evented-gearman-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/HOWTO +146 -0
- data/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +41 -0
- data/TODO +8 -0
- data/VERSION.yml +4 -0
- data/evented-gearman-ruby.gemspec +110 -0
- data/examples/calculus_client.rb +41 -0
- data/examples/calculus_worker.rb +42 -0
- data/examples/client.rb +19 -0
- data/examples/client_background.rb +14 -0
- data/examples/client_data.rb +16 -0
- data/examples/client_exception.rb +17 -0
- data/examples/client_prefix.rb +15 -0
- data/examples/evented_client.rb +23 -0
- data/examples/evented_worker.rb +26 -0
- data/examples/gearman_environment.sh +25 -0
- data/examples/scale_image.rb +30 -0
- data/examples/scale_image_worker.rb +34 -0
- data/examples/server.rb +15 -0
- data/examples/worker.rb +23 -0
- data/examples/worker_data.rb +16 -0
- data/examples/worker_exception.rb +14 -0
- data/examples/worker_prefix.rb +25 -0
- data/lib/gearman.rb +29 -0
- data/lib/gearman/client.rb +80 -0
- data/lib/gearman/evented/client.rb +99 -0
- data/lib/gearman/evented/reactor.rb +86 -0
- data/lib/gearman/evented/worker.rb +118 -0
- data/lib/gearman/job.rb +38 -0
- data/lib/gearman/protocol.rb +110 -0
- data/lib/gearman/server.rb +94 -0
- data/lib/gearman/task.rb +99 -0
- data/lib/gearman/taskset.rb +11 -0
- data/lib/gearman/util.rb +52 -0
- data/lib/gearman/worker.rb +39 -0
- data/test/basic_integration_test.rb +121 -0
- data/test/crash_test.rb +69 -0
- data/test/job_test.rb +30 -0
- data/test/protocol_test.rb +132 -0
- data/test/test_helper.rb +31 -0
- data/test/util_test.rb +12 -0
- data/test/worker_test.rb +45 -0
- metadata +149 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
|
2
|
+
require 'gearman'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
def start_gearmand(port = 4730, debug = false)
|
7
|
+
log = debug ? "-l /tmp/gearmand.log -vvv" : ""
|
8
|
+
system "gearmand -d -p #{port} --pid-file=#{gearmand_pidfile(port)} #{log}"
|
9
|
+
gearmand_pid(port)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stop_gearmand(port = 4730)
|
13
|
+
Process.kill "KILL", gearmand_pid(port)
|
14
|
+
File.unlink gearmand_pidfile(port)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown_gearmands
|
18
|
+
glob = "/tmp/gearmand_*_#{$$}.pid"
|
19
|
+
Dir[glob].each do |pidfile|
|
20
|
+
Process.kill "KILL", `cat #{pidfile}`.to_i
|
21
|
+
File.unlink pidfile
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def gearmand_pid(port = 4730)
|
26
|
+
`cat #{gearmand_pidfile(port)}`.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def gearmand_pidfile(port)
|
30
|
+
"/tmp/gearmand_#{port}_#{$$}.pid"
|
31
|
+
end
|
data/test/util_test.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class UtilTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_ability_prefix_name_builder
|
6
|
+
assert_equal(Gearman::Util.ability_name_with_prefix("test","a"),"test\ta")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_ability_name_for_perl
|
10
|
+
assert_equal(Gearman::Util.ability_name_for_perl("test","a"),"test\ta")
|
11
|
+
end
|
12
|
+
end
|
data/test/worker_test.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class WorkerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_accepts_multiple_job_servers
|
6
|
+
Gearman::Evented::WorkerReactor.expects(:connect).times(2)
|
7
|
+
|
8
|
+
EM.run do
|
9
|
+
EM.add_timer(0.1) { EM.stop_event_loop }
|
10
|
+
Gearman::Worker.new(["localhost:4730", "localhost:4731"]).work
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_accepts_exactly_one_job_server
|
15
|
+
Gearman::Evented::WorkerReactor.expects(:connect).with("localhost", "4730", {:abilities => {}}).times(1)
|
16
|
+
|
17
|
+
EM.run do
|
18
|
+
EM.add_timer(0.1) { EM.stop_event_loop }
|
19
|
+
Gearman::Worker.new("localhost:4730").work
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_passes_abilities_to_reactor
|
24
|
+
worker = Gearman::Worker.new("localhost:4730")
|
25
|
+
worker.add_ability("foo") {|data, job| "noop!"}
|
26
|
+
worker.add_ability("bar") {|data, job| "nothing to see here!" }
|
27
|
+
worker.remove_ability("bar")
|
28
|
+
|
29
|
+
assert_equal true, worker.has_ability?("foo")
|
30
|
+
assert_equal false, worker.has_ability?("bar")
|
31
|
+
|
32
|
+
Gearman::Evented::WorkerReactor.expects(:connect).with do |host, port, opts|
|
33
|
+
assert_equal "localhost", host
|
34
|
+
assert_equal 4730, port.to_i
|
35
|
+
assert_equal 1, opts[:abilities].size
|
36
|
+
assert_equal true, opts[:abilities]['foo'][:callback].is_a?(Proc)
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
EM.run do
|
41
|
+
EM.add_timer(0.1) { EM.stop_event_loop }
|
42
|
+
worker.work
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evented-gearman-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kim Altintop
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-19 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: eventmachine
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 63
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 12
|
33
|
+
- 8
|
34
|
+
version: 0.12.8
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Library for the Gearman distributed job system
|
38
|
+
email: kim.altintop@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README
|
46
|
+
- TODO
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- HOWTO
|
50
|
+
- LICENSE
|
51
|
+
- README
|
52
|
+
- Rakefile
|
53
|
+
- TODO
|
54
|
+
- VERSION.yml
|
55
|
+
- evented-gearman-ruby.gemspec
|
56
|
+
- examples/calculus_client.rb
|
57
|
+
- examples/calculus_worker.rb
|
58
|
+
- examples/client.rb
|
59
|
+
- examples/client_background.rb
|
60
|
+
- examples/client_data.rb
|
61
|
+
- examples/client_exception.rb
|
62
|
+
- examples/client_prefix.rb
|
63
|
+
- examples/evented_client.rb
|
64
|
+
- examples/evented_worker.rb
|
65
|
+
- examples/gearman_environment.sh
|
66
|
+
- examples/scale_image.rb
|
67
|
+
- examples/scale_image_worker.rb
|
68
|
+
- examples/server.rb
|
69
|
+
- examples/worker.rb
|
70
|
+
- examples/worker_data.rb
|
71
|
+
- examples/worker_exception.rb
|
72
|
+
- examples/worker_prefix.rb
|
73
|
+
- lib/gearman.rb
|
74
|
+
- lib/gearman/client.rb
|
75
|
+
- lib/gearman/evented/client.rb
|
76
|
+
- lib/gearman/evented/reactor.rb
|
77
|
+
- lib/gearman/evented/worker.rb
|
78
|
+
- lib/gearman/job.rb
|
79
|
+
- lib/gearman/protocol.rb
|
80
|
+
- lib/gearman/server.rb
|
81
|
+
- lib/gearman/task.rb
|
82
|
+
- lib/gearman/taskset.rb
|
83
|
+
- lib/gearman/util.rb
|
84
|
+
- lib/gearman/worker.rb
|
85
|
+
- test/basic_integration_test.rb
|
86
|
+
- test/crash_test.rb
|
87
|
+
- test/job_test.rb
|
88
|
+
- test/protocol_test.rb
|
89
|
+
- test/test_helper.rb
|
90
|
+
- test/util_test.rb
|
91
|
+
- test/worker_test.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/kim/evented-gearman-ruby
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- --charset=UTF-8
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.3.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: eventmachine-based library for the Gearman distributed job system
|
126
|
+
test_files:
|
127
|
+
- test/basic_integration_test.rb
|
128
|
+
- test/crash_test.rb
|
129
|
+
- test/job_test.rb
|
130
|
+
- test/protocol_test.rb
|
131
|
+
- test/test_helper.rb
|
132
|
+
- test/util_test.rb
|
133
|
+
- test/worker_test.rb
|
134
|
+
- examples/calculus_client.rb
|
135
|
+
- examples/calculus_worker.rb
|
136
|
+
- examples/client.rb
|
137
|
+
- examples/client_background.rb
|
138
|
+
- examples/client_data.rb
|
139
|
+
- examples/client_exception.rb
|
140
|
+
- examples/client_prefix.rb
|
141
|
+
- examples/evented_client.rb
|
142
|
+
- examples/evented_worker.rb
|
143
|
+
- examples/scale_image.rb
|
144
|
+
- examples/scale_image_worker.rb
|
145
|
+
- examples/server.rb
|
146
|
+
- examples/worker.rb
|
147
|
+
- examples/worker_data.rb
|
148
|
+
- examples/worker_exception.rb
|
149
|
+
- examples/worker_prefix.rb
|