rightscale-nanite 0.4.1.4 → 0.4.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +3 -1
- data/lib/nanite/agent.rb +24 -8
- data/lib/nanite/amqp.rb +5 -1
- data/lib/nanite/cluster.rb +74 -54
- data/lib/nanite/daemonize.rb +4 -4
- data/lib/nanite/local_state.rb +5 -1
- data/lib/nanite/log.rb +1 -1
- data/lib/nanite/mapper.rb +17 -11
- data/lib/nanite/mapper_proxy.rb +9 -1
- data/lib/nanite/{dispatcher.rb → nanite_dispatcher.rb} +0 -0
- data/lib/nanite/packets.rb +55 -19
- data/lib/nanite/reaper.rb +15 -14
- data/lib/nanite/redis_tag_store.rb +141 -0
- data/lib/nanite/state.rb +87 -116
- data/lib/nanite/util.rb +21 -1
- data/lib/nanite.rb +2 -2
- metadata +34 -58
- data/spec/actor_registry_spec.rb +0 -60
- data/spec/actor_spec.rb +0 -77
- data/spec/agent_spec.rb +0 -240
- data/spec/cached_certificate_store_proxy_spec.rb +0 -34
- data/spec/certificate_cache_spec.rb +0 -49
- data/spec/certificate_spec.rb +0 -27
- data/spec/cluster_spec.rb +0 -485
- data/spec/dispatcher_spec.rb +0 -136
- data/spec/distinguished_name_spec.rb +0 -24
- data/spec/encrypted_document_spec.rb +0 -21
- data/spec/job_spec.rb +0 -251
- data/spec/local_state_spec.rb +0 -112
- data/spec/log_spec.rb +0 -49
- data/spec/mapper_proxy_spec.rb +0 -72
- data/spec/mapper_spec.rb +0 -70
- data/spec/nanite_spec.rb +0 -36
- data/spec/packet_spec.rb +0 -220
- data/spec/rsa_key_pair_spec.rb +0 -33
- data/spec/secure_serializer_spec.rb +0 -41
- data/spec/serializer_spec.rb +0 -107
- data/spec/signature_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -30
- data/spec/static_certificate_store_spec.rb +0 -30
- data/spec/util_spec.rb +0 -63
data/spec/job_spec.rb
DELETED
@@ -1,251 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Nanite::JobWarden do
|
4
|
-
|
5
|
-
describe "Creating a new Job" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@serializer = mock("Serializer")
|
9
|
-
@warden = Nanite::JobWarden.new(@serializer)
|
10
|
-
|
11
|
-
@request = mock("Request")
|
12
|
-
@targets = mock("Targets")
|
13
|
-
@job = mock("Job", :token => "3faba24fcc")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should instantiate a new Job" do
|
17
|
-
Nanite::Job.should_receive(:new).with(@request, @targets, nil, nil).and_return(@job)
|
18
|
-
@warden.new_job(@request, @targets)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should add the job to the job list" do
|
22
|
-
Nanite::Job.should_receive(:new).with(@request, @targets, nil, nil).and_return(@job)
|
23
|
-
@warden.jobs.size.should == 0
|
24
|
-
@warden.new_job(@request, @targets)
|
25
|
-
@warden.jobs.size.should == 1
|
26
|
-
@warden.jobs["3faba24fcc"].should == @job
|
27
|
-
end
|
28
|
-
|
29
|
-
it "return the newly crated job" do
|
30
|
-
Nanite::Job.should_receive(:new).with(@request, @targets, nil, nil).and_return(@job)
|
31
|
-
@warden.new_job(@request, @targets).should == @job
|
32
|
-
end
|
33
|
-
|
34
|
-
end # Creating a new Job
|
35
|
-
|
36
|
-
describe "Processing an intermediate message" do
|
37
|
-
before(:each) do
|
38
|
-
@intm_handler = lambda {|arg1, arg2, arg3| puts 'ehlo'}
|
39
|
-
@message = mock("Message", :token => "3faba24fcc", :from => 'nanite-agent')
|
40
|
-
@serializer = mock("Serializer", :load => @message)
|
41
|
-
@warden = Nanite::JobWarden.new(@serializer)
|
42
|
-
@job = Nanite::Job.new(stub("request", :token => "3faba24fcc"), [], @intm_handler)
|
43
|
-
@job.instance_variable_set(:@pending_keys, ["defaultkey"])
|
44
|
-
@job.instance_variable_set(:@intermediate_state, {"nanite-agent" => {"defaultkey" => [1]}})
|
45
|
-
@warden.jobs[@job.token] = @job
|
46
|
-
Nanite::Log.stub!(:debug)
|
47
|
-
Nanite::Log.stub!(:error)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should call the intermediate handler with three parameters" do
|
51
|
-
@intm_handler.should_receive(:call).with("defaultkey", "nanite-agent", 1)
|
52
|
-
@warden.process(@message)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should call the intermediate handler with four parameters" do
|
56
|
-
@intm_handler.stub!(:arity).and_return(4)
|
57
|
-
@intm_handler.should_receive(:call).with("defaultkey", "nanite-agent", 1, @job)
|
58
|
-
@warden.process(@message)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should not call the intermediate handler when it can't be found for the specified key" do
|
62
|
-
@intm_handler.should_not_receive(:call)
|
63
|
-
@job.instance_variable_set(:@intermediate_handler, nil)
|
64
|
-
@warden.process(@message)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should call the intermediate handler with one parameter which needs to be the result" do
|
68
|
-
@intm_handler.should_receive(:call).with(1, @job)
|
69
|
-
@intm_handler.stub!(:arity).and_return(2)
|
70
|
-
@warden.process(@message)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "Processing a Message" do
|
75
|
-
|
76
|
-
before(:each) do
|
77
|
-
@message = mock("Message", :token => "3faba24fcc")
|
78
|
-
@warden = Nanite::JobWarden.new(@serializer)
|
79
|
-
@job = mock("Job", :token => "3faba24fcc", :process => true, :completed? => false, :results => 42, :pending_keys => [], :intermediate_handler => true)
|
80
|
-
|
81
|
-
Nanite::Log.stub!(:debug)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should hand over processing to job" do
|
85
|
-
Nanite::Job.stub!(:new).and_return(@job)
|
86
|
-
@job.should_receive(:process).with(@message)
|
87
|
-
|
88
|
-
@warden.new_job("request", "targets")
|
89
|
-
@warden.process(@message)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should delete job from jobs after completion" do
|
93
|
-
Nanite::Job.stub!(:new).and_return(@job)
|
94
|
-
@job.should_receive(:process).with(@message)
|
95
|
-
@job.should_receive(:completed?).and_return(true)
|
96
|
-
@job.should_receive(:completed).and_return(nil)
|
97
|
-
|
98
|
-
@warden.jobs["3faba24fcc"].should be_nil
|
99
|
-
@warden.new_job("request", "targets")
|
100
|
-
@warden.jobs["3faba24fcc"].should == @job
|
101
|
-
@warden.process(@message)
|
102
|
-
@warden.jobs["3faba24fcc"].should be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should call completed block after completion" do
|
106
|
-
completed_block = mock("Completed", :arity => 1, :call => true)
|
107
|
-
|
108
|
-
Nanite::Job.stub!(:new).and_return(@job)
|
109
|
-
@job.should_receive(:process).with(@message)
|
110
|
-
@job.should_receive(:completed?).and_return(true)
|
111
|
-
@job.should_receive(:completed).exactly(3).times.and_return(completed_block)
|
112
|
-
|
113
|
-
@warden.new_job("request", "targets")
|
114
|
-
@warden.process(@message)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should pass in job result if arity of completed block is one" do
|
118
|
-
completed_block = mock("Completed")
|
119
|
-
|
120
|
-
Nanite::Job.stub!(:new).and_return(@job)
|
121
|
-
@job.should_receive(:process).with(@message)
|
122
|
-
@job.should_receive(:completed?).and_return(true)
|
123
|
-
@job.should_receive(:completed).exactly(3).times.and_return(completed_block)
|
124
|
-
@job.should_receive(:results).and_return("the job result")
|
125
|
-
completed_block.should_receive(:arity).and_return(1)
|
126
|
-
completed_block.should_receive(:call).with("the job result")
|
127
|
-
|
128
|
-
@warden.new_job("request", "targets")
|
129
|
-
@warden.process(@message)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should pass in job result and job if arity of completed block is two" do
|
133
|
-
completed_block = mock("Completed")
|
134
|
-
|
135
|
-
Nanite::Job.stub!(:new).and_return(@job)
|
136
|
-
@job.should_receive(:process).with(@message)
|
137
|
-
@job.should_receive(:completed?).and_return(true)
|
138
|
-
@job.should_receive(:completed).exactly(3).times.and_return(completed_block)
|
139
|
-
@job.should_receive(:results).and_return("the job result")
|
140
|
-
completed_block.should_receive(:arity).and_return(2)
|
141
|
-
completed_block.should_receive(:call).with("the job result", @job)
|
142
|
-
|
143
|
-
@warden.new_job("request", "targets")
|
144
|
-
@warden.process(@message)
|
145
|
-
end
|
146
|
-
|
147
|
-
end # Processing a Message
|
148
|
-
|
149
|
-
end # Nanite::JobWarden
|
150
|
-
|
151
|
-
|
152
|
-
describe Nanite::Job do
|
153
|
-
|
154
|
-
describe "Creating a Job" do
|
155
|
-
|
156
|
-
before(:each) do
|
157
|
-
@request = mock("Request", :token => "af534ceaaacdcd")
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should initialize the request" do
|
161
|
-
job = Nanite::Job.new(@request, nil, nil)
|
162
|
-
job.request.should == @request
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should initialize the targets" do
|
166
|
-
job = Nanite::Job.new(@request, "targets", nil)
|
167
|
-
job.targets.should == "targets"
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should initialize the job token to the request token" do
|
171
|
-
job = Nanite::Job.new(@request, nil, nil)
|
172
|
-
job.token.should == "af534ceaaacdcd"
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should initialize the results to an empty hash" do
|
176
|
-
job = Nanite::Job.new(@request, nil, nil)
|
177
|
-
job.results.should == {}
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should initialize the intermediate state to an empty hash" do
|
181
|
-
job = Nanite::Job.new(@request, nil, nil)
|
182
|
-
job.intermediate_state.should == {}
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should initialize the job block" do
|
186
|
-
job = Nanite::Job.new(@request, nil, nil, "my block")
|
187
|
-
job.completed.should == "my block"
|
188
|
-
end
|
189
|
-
|
190
|
-
end # Creating a new Job
|
191
|
-
|
192
|
-
|
193
|
-
describe "Processing a Message" do
|
194
|
-
|
195
|
-
before(:each) do
|
196
|
-
@request = mock("Request", :token => "feeefe132")
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should set the job result (for sender) to the message result for 'final' status messages" do
|
200
|
-
job = Nanite::Job.new(@request, [], nil)
|
201
|
-
message = Nanite::Result.new('token', 'to', 'results', 'from')
|
202
|
-
job.results.should == {}
|
203
|
-
job.process(message)
|
204
|
-
job.results.should == { 'from' => 'results' }
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should delete the message sender from the targets for 'final' status messages" do
|
208
|
-
job = Nanite::Job.new(@request, ['from'], nil)
|
209
|
-
message = Nanite::Result.new('token', 'to', 'results', 'from')
|
210
|
-
job.targets.should == ['from']
|
211
|
-
job.process(message)
|
212
|
-
job.targets.should == []
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should set the job result (for sender) to the message result for 'intermediate' status messages" do
|
216
|
-
job = Nanite::Job.new(@request, ['from'], nil)
|
217
|
-
message = Nanite::IntermediateMessage.new('token', 'to', 'from', 'messagekey', 'message')
|
218
|
-
job.process(message)
|
219
|
-
job.intermediate_state.should == { 'from' => { 'messagekey' => ['message'] } }
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should not delete the message sender from the targets for 'intermediate' status messages" do
|
223
|
-
job = Nanite::Job.new(@request, ['from'], nil)
|
224
|
-
message = Nanite::IntermediateMessage.new('token', 'to', 'from', 'messagekey', 'message')
|
225
|
-
job.targets.should == ['from']
|
226
|
-
job.process(message)
|
227
|
-
job.targets.should == ['from']
|
228
|
-
end
|
229
|
-
|
230
|
-
end # Processing a Message
|
231
|
-
|
232
|
-
|
233
|
-
describe "Completion" do
|
234
|
-
|
235
|
-
before(:each) do
|
236
|
-
@request = mock("Request", :token => "af534ceaaacdcd")
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should be true is targets are empty" do
|
240
|
-
job = Nanite::Job.new(@request, {}, nil)
|
241
|
-
job.completed?.should == true
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should be false is targets are not empty" do
|
245
|
-
job = Nanite::Job.new(@request, { :a => 1 }, nil)
|
246
|
-
job.completed?.should == false
|
247
|
-
end
|
248
|
-
|
249
|
-
end # Completion
|
250
|
-
|
251
|
-
end # Nanite::Job
|
data/spec/local_state_spec.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
require 'nanite/local_state'
|
3
|
-
|
4
|
-
describe "Nanite::LocalState: " do
|
5
|
-
|
6
|
-
describe "Class" do
|
7
|
-
|
8
|
-
it "should a Hash" do
|
9
|
-
Nanite::LocalState.new({}).should be_kind_of(Hash)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should create empty hash if no hash passed in" do
|
13
|
-
Nanite::LocalState.new.should == {}
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should initialize hash with value passed in" do
|
17
|
-
state = Nanite::LocalState.new({:a => 1, :b => 2, :c => 3})
|
18
|
-
state.should == {:a => 1, :b => 2, :c => 3}
|
19
|
-
end
|
20
|
-
|
21
|
-
end # Class
|
22
|
-
|
23
|
-
|
24
|
-
describe "All services" do
|
25
|
-
|
26
|
-
it "should return empty array if no services are defined" do
|
27
|
-
state = Nanite::LocalState.new({:f => { :foo => 1 }, :b => { :bar => 2 }})
|
28
|
-
state.all_services.should == []
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return all :services values" do
|
32
|
-
state = Nanite::LocalState.new({:f => { :foo => 1 }, :b => { :services => "b's services" }, :c => { :services => "c's services" }})
|
33
|
-
state.all_services.should include("b's services")
|
34
|
-
state.all_services.should include("c's services")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should only return one entry for each service" do
|
38
|
-
state = Nanite::LocalState.new({:f => { :services => "services" }, :b => { :services => "services" }})
|
39
|
-
state.all_services.size == 1
|
40
|
-
state.all_services.should == ["services"]
|
41
|
-
end
|
42
|
-
|
43
|
-
end # All services
|
44
|
-
|
45
|
-
|
46
|
-
describe "All tags" do
|
47
|
-
|
48
|
-
it "should return empty array if no tags are defined" do
|
49
|
-
state = Nanite::LocalState.new({:f => { :foo => 1 }, :b => { :bar => 2 }})
|
50
|
-
state.all_tags.should == []
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should return all :tags values" do
|
54
|
-
state = Nanite::LocalState.new({:f => { :foo => 1 }, :b => { :tags => ["a", "b"] }, :c => { :tags => ["c", "d"] }})
|
55
|
-
state.all_tags.should include("a")
|
56
|
-
state.all_tags.should include("b")
|
57
|
-
state.all_tags.should include("c")
|
58
|
-
state.all_tags.should include("d")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should only return one entry for each tag" do
|
62
|
-
state = Nanite::LocalState.new({:f => { :foo => 1 }, :b => { :tags => ["a", "b"] }, :c => { :tags => ["a", "c"] }})
|
63
|
-
state.all_tags.size == 3
|
64
|
-
state.all_tags.should include("a")
|
65
|
-
state.all_tags.should include("b")
|
66
|
-
state.all_tags.should include("c")
|
67
|
-
end
|
68
|
-
|
69
|
-
end # All tags
|
70
|
-
|
71
|
-
|
72
|
-
describe "Nanites lookup" do
|
73
|
-
|
74
|
-
it "should find services matching the service criteria if no tags criteria is specified" do
|
75
|
-
state = Nanite::LocalState.new({:a => { :services => "a's services" }, :b => { :services => "b's services" }})
|
76
|
-
state.nanites_for("b's services").should == [[:b, {:services => "b's services"}]]
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should find all services matching the service criteria if no tags criteria is specified" do
|
80
|
-
state = Nanite::LocalState.new({:a => { :services => "services" }, :b => { :services => "services" }, :c => { :services => "other services" }})
|
81
|
-
state.nanites_for("services").should include([:a, {:services => "services"}])
|
82
|
-
state.nanites_for("services").should include([:b, {:services => "services"}])
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should only services matching the service criteria that also match the tags criteria" do
|
86
|
-
state = Nanite::LocalState.new({:a => { :services => "a's services", :tags => ["a_1", "a_2"] }, :b => { :services => "b's services", :tags => ["b_1", "b_2"] }})
|
87
|
-
state.nanites_for("b's services").should == [[:b, {:tags=>["b_1", "b_2"], :services=>"b's services"}]]
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should also return all tags for services matching the service criteria that also match a single tags criterium" do
|
91
|
-
state = Nanite::LocalState.new({:a => { :services => "services", :tags => ["t_1", "t_2"] }})
|
92
|
-
state.nanites_for("services", ["t_1"]).should == [[:a, {:tags=>["t_1", "t_2"], :services=>"services"}]]
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should return services matching the service criteria and also match the tags criterium" do
|
96
|
-
state = Nanite::LocalState.new({:a => { :services => "a's services", :tags => ["a_1", "a_2"] }, :b => { :services => "b's services", :tags => ["b_1", "b_2"] }})
|
97
|
-
state.nanites_for("b's services", ["b_1"]).should == [[:b, {:tags=>["b_1", "b_2"], :services=>"b's services"}]]
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should ignore services matching the service criteria and but not the tags criteria" do
|
101
|
-
state = Nanite::LocalState.new({:a => { :services => "services", :tags => ["t_1", "t_2"] }, :b => { :services => "services", :tags => ["t_3", "t_4"] }})
|
102
|
-
state.nanites_for("services", ["t_1"]).should == [[:a, {:services => "services", :tags => ["t_1", "t_2"]}]]
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should lookup services matching the service criteria and and any of the tags criteria" do
|
106
|
-
state = Nanite::LocalState.new({'a' => { :services => "services", :tags => ["t_1", "t_2"] }, 'b' => { :services => "services", :tags => ["t_2", "t_3"] }})
|
107
|
-
state.nanites_for("services", ["t_1", "t_3"]).sort.should == [['a', {:services => "services", :tags => ["t_1", "t_2"]}], ['b', {:services => "services", :tags => ["t_2", "t_3"]}]]
|
108
|
-
end
|
109
|
-
|
110
|
-
end # Nanites lookup
|
111
|
-
|
112
|
-
end # Nanite::LocalState
|
data/spec/log_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Nanite::Log do
|
4
|
-
describe "Using log without initializing it first" do
|
5
|
-
before(:each) do
|
6
|
-
Nanite::Log.instance_variable_set(:@logger, nil)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should use standard out for logging" do
|
10
|
-
Nanite::Log.init
|
11
|
-
STDOUT.should_receive(:write) do |arg|
|
12
|
-
arg.include?("For your consideration").should == true
|
13
|
-
end
|
14
|
-
Nanite::Log.info("For your consideration")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "Initializing the log level" do
|
19
|
-
it "should default to :info" do
|
20
|
-
Nanite::Log.init
|
21
|
-
Nanite::Log.level.should == :info
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should raise an error if level is incorrect" do
|
25
|
-
lambda { Nanite::Log.level = "fool" }.should raise_error
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should succeed when using symbols" do
|
29
|
-
[ :debug, :info, :warn, :error, :fatal ].each do |level|
|
30
|
-
Nanite::Log.level = level
|
31
|
-
Nanite::Log.level.should == level
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
it "should succeed when using log levels" do
|
37
|
-
lvls = { Logger::DEBUG => :debug,
|
38
|
-
Logger::INFO => :info,
|
39
|
-
Logger::WARN => :warn,
|
40
|
-
Logger::ERROR => :error,
|
41
|
-
Logger::FATAL => :fatal }
|
42
|
-
lvls.keys.each do |level|
|
43
|
-
Nanite::Log.level = level
|
44
|
-
Nanite::Log.level.should == lvls[level]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
data/spec/mapper_proxy_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Nanite::MapperProxy do
|
4
|
-
describe "when fetching the instance" do
|
5
|
-
before(:each) do
|
6
|
-
if Nanite::MapperProxy.class_variables.include?('@@instance')
|
7
|
-
Nanite::MapperProxy.__send__(:remove_class_variable, :@@instance)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return nil when the instance is undefined" do
|
12
|
-
Nanite::MapperProxy.instance.should == nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return the instance if defined" do
|
16
|
-
instance = mock
|
17
|
-
Nanite::MapperProxy.class_eval do
|
18
|
-
@@instance = "instance"
|
19
|
-
end
|
20
|
-
|
21
|
-
Nanite::MapperProxy.instance.should_not == nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "when pushing a message" do
|
26
|
-
before do
|
27
|
-
AMQP.stub!(:connect)
|
28
|
-
MQ.stub!(:new)
|
29
|
-
Nanite::MapperProxy.new('mapperproxy', {})
|
30
|
-
@instance = Nanite::MapperProxy.instance
|
31
|
-
@fanout = stub(:fanout, :publish => true)
|
32
|
-
@instance.amqp.stub!(:fanout).and_return(@fanout)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should raise an error if mapper proxy is not initialized" do
|
36
|
-
lambda {
|
37
|
-
@instance.stub!(:identity).and_return nil
|
38
|
-
@instance.push('/welcome/aboard', 'iZac')
|
39
|
-
}.should raise_error("Mapper proxy not initialized")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should set correct attributes on the push message" do
|
43
|
-
@fanout.should_receive(:publish).with do |push|
|
44
|
-
push = @instance.serializer.load(push)
|
45
|
-
push.token.should_not == nil
|
46
|
-
push.persistent.should_not == true
|
47
|
-
push.from.should == 'mapperproxy'
|
48
|
-
end
|
49
|
-
|
50
|
-
@instance.push('/welcome/aboard', 'iZac')
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should mark the message as persistent when the option is specified on the parameter" do
|
54
|
-
@fanout.should_receive(:publish).with do |push|
|
55
|
-
push = @instance.serializer.load(push)
|
56
|
-
push.persistent.should == true
|
57
|
-
end
|
58
|
-
|
59
|
-
@instance.push('/welcome/aboard', 'iZac', :persistent => true)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should mark the message as persistent when the option is set globally" do
|
63
|
-
@instance.options[:persistent] = true
|
64
|
-
@fanout.should_receive(:publish).with do |push|
|
65
|
-
push = @instance.serializer.load(push)
|
66
|
-
push.persistent.should == true
|
67
|
-
end
|
68
|
-
|
69
|
-
@instance.push('/welcome/aboard', 'iZac')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/spec/mapper_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Nanite::Mapper do
|
4
|
-
include SpecHelpers
|
5
|
-
|
6
|
-
describe "Initializing" do
|
7
|
-
before(:each) do
|
8
|
-
@mapper = Nanite::Mapper.new({})
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should set the identity" do
|
12
|
-
@mapper.identity.should_not == nil
|
13
|
-
@mapper.identity.should =~ /mapper-.*/
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should set the identity to a custom identity" do
|
17
|
-
@mapper = Nanite::Mapper.new({:identity => "bob"})
|
18
|
-
@mapper.identity.should == "mapper-bob"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should set the file root" do
|
22
|
-
@mapper.options[:file_root].should == File.expand_path("#{File.dirname(__FILE__)}/../files")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "Starting" do
|
27
|
-
before(:each) do
|
28
|
-
@mapper = Nanite::Mapper.new({:log_level => :debug})
|
29
|
-
@mapper.stub!(:setup_queues)
|
30
|
-
@mapper.stub!(:start_amqp)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should initialize the logger" do
|
34
|
-
@mapper.stub!(:setup_cluster)
|
35
|
-
run_in_em do
|
36
|
-
@mapper.run
|
37
|
-
Nanite::Log.logger.level.should == Logger::DEBUG
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should set up the cluster" do
|
42
|
-
Nanite::Cluster.should_receive(:new).with(nil, 15, instance_of(String), instance_of(Nanite::Serializer), @mapper, nil, {})
|
43
|
-
run_in_em do
|
44
|
-
@mapper.run
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should set the prefetch value" do
|
49
|
-
amqp = mock("AMQP")
|
50
|
-
|
51
|
-
mapper = Nanite::Mapper.new(:prefetch => 11)
|
52
|
-
mapper.stub!(:setup_offline_queue)
|
53
|
-
mapper.stub!(:setup_message_queue)
|
54
|
-
mapper.stub!(:start_amqp)
|
55
|
-
mapper.stub!(:setup_cluster)
|
56
|
-
|
57
|
-
mapper.stub!(:start_amqp).and_return(amqp)
|
58
|
-
amqp.should_receive(:prefetch).with(11)
|
59
|
-
mapper.run
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should hand over callback options to the cluster" do
|
63
|
-
@mapper = Nanite::Mapper.new({:callbacks => {:register => lambda {|*args|}}})
|
64
|
-
@mapper.stub!(:setup_queues)
|
65
|
-
@mapper.stub!(:start_amqp)
|
66
|
-
Nanite::Cluster.should_receive(:new)
|
67
|
-
run_in_em {@mapper.run}
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/spec/nanite_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Nanite do
|
4
|
-
describe "when ensuring a mapper exists" do
|
5
|
-
describe "with a configured mapper proxy" do
|
6
|
-
before(:each) do
|
7
|
-
Nanite.instance_variable_set(:@mapper, nil)
|
8
|
-
Nanite::MapperProxy.stub!(:instance).and_return(mock(:mapper_proxy))
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should not raise an error" do
|
12
|
-
lambda {
|
13
|
-
Nanite.ensure_mapper
|
14
|
-
}.should_not raise_error
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should set the mapper instance variable to the mapper proxy instance" do
|
18
|
-
Nanite.ensure_mapper
|
19
|
-
Nanite.mapper.should == Nanite::MapperProxy.instance
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "when the mapper wasn't started yet" do
|
24
|
-
before do
|
25
|
-
Nanite.instance_variable_set(:@mapper, nil)
|
26
|
-
Nanite::MapperProxy.stub!(:instance).and_return(nil)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should raise an error" do
|
30
|
-
lambda {
|
31
|
-
Nanite.ensure_mapper
|
32
|
-
}.should raise_error(Nanite::MapperNotRunning)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|