infopark-politics 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjRmYzE1MmU4OGM0YmE4YTZhZTA2N2NjYjc3NjI4MjJiM2VlYTJjMQ==
4
+ YzI2YjBlZjljZTNiODUyNDhkOWVjNmQ1ZTdhN2Y0M2MzN2I1N2I2Zg==
5
5
  data.tar.gz: !binary |-
6
- ZTliMGY5NzcyNDk3ZjliZjBmZjY1NGM5MGE3MzkzZmM3NDg5ZDljZQ==
6
+ OTY5ZDEzMWU0ZTdmNDhkZTUwZGRhMjBkMmRkNGEwYTk2MDgzYTBkMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzYzMjdmYzgxZTgyNjgxODhiYzg0NWVmZmI4YmY5N2JkZmMxZTZjN2Q4OGRh
10
- MDIxYzg1NTc0MTk5MDA2ZTI3N2VmMjkzODQ4YzMxYzM3MTZiNWViZDRhM2I1
11
- Yzc0ZDM3MWU2N2FlNzlhMDFmODMwYjZkMWMzMWIxYzRhNGY4ZjQ=
9
+ MjQwOTlhYzYwMjVmNWFmNTY1ZWFjYjU2NjQxNGEzZmQ3MWU5N2RlYTRmN2I5
10
+ MzUzYmE5NjZkOTQ5MjEyODEyMDYzMzk5NmY2ZjhiMWI2YjYwZDA0ODcwNmM4
11
+ MjhlZmQ0NzYzNDg4NjQyMTZjODMyNzczZjQyN2QwNjIxZWEwMzU=
12
12
  data.tar.gz: !binary |-
13
- MjkxNGRkMzFkNTlhYTY3Yzk4MDBhMzE4OGRkMzA3YzM2ZTZlZjc2MDczNzIz
14
- N2JjMWFjYmRmNzM2ODE1NGUxOWI2MDE5NmQ2MTA0NmRkYmY1ODM5ODY4ODI2
15
- Yzc1Yzk3MzZiOTdkN2NlYzIzZGRkYzdmODNiNDU2Yzk0MGY0M2I=
13
+ NDhmMTBjYTM4YzM0MmZmZTBkZTYzOWI3NTY1MTk4M2UxNTJhYmNkNWEyZWI2
14
+ N2M1ZTQxOGI3MmM3YTM2YTJiMTU1MTcwNmJlNWVkMDAwNjQ0NzE3MDZkNjFi
15
+ MDIzMmQ2OTk2OGMyOGRmMjgxNGJkYWYxOThmZjFjOTk2MzA0N2U=
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  Gem::Specification.new do |gem|
8
8
  gem.name = "infopark-politics"
9
- gem.version = "0.4.0"
9
+ gem.version = "0.5.0"
10
10
  gem.summary = "Algorithms and Tools for Distributed Computing in Ruby."
11
11
  gem.description = ""
12
12
  gem.authors = ["Mike Perham", "Tilo Prütz"]
@@ -65,7 +65,7 @@ module Politics
65
65
  # Get a bucket from the leader and process it
66
66
  begin
67
67
  log.debug "getting bucket request from leader (#{leader_uri}) and processing it"
68
- bucket_process(*leader.bucket_request(uri), &block)
68
+ bucket_process(*leader.bucket_request(uri, bucket_request_context), &block)
69
69
  rescue DRb::DRbError => dre
70
70
  log.error { "Error talking to leader: #{dre.message}" }
71
71
  relax until_next_iteration
@@ -124,10 +124,10 @@ module Politics
124
124
  @followers_to_stop.select {|u| DRbObject.new(nil, u).alive? rescue DRb::DRbConnError && false}
125
125
  end
126
126
 
127
- def bucket_request(requestor_uri)
127
+ def bucket_request(requestor_uri, context)
128
128
  if leader?
129
129
  log.debug "delivering bucket request"
130
- bucket_spec = next_bucket(requestor_uri)
130
+ bucket_spec = next_bucket(requestor_uri, context)
131
131
  if !bucket_spec[0] && @followers_to_stop.include?(requestor_uri)
132
132
  bucket_spec = [:stop, 0]
133
133
  @followers_to_stop.delete(requestor_uri)
@@ -139,7 +139,7 @@ module Politics
139
139
  end
140
140
  end
141
141
 
142
- def next_bucket(requestor_uri)
142
+ def next_bucket(requestor_uri, context)
143
143
  [@buckets.pop, sleep_until_next_bucket_time]
144
144
  end
145
145
 
@@ -271,6 +271,9 @@ module Politics
271
271
  Time.now - a
272
272
  end
273
273
 
274
+ def bucket_request_context
275
+ end
276
+
274
277
  def hostname
275
278
  end
276
279
 
@@ -56,6 +56,10 @@ describe UninitializedWorker do
56
56
  worker.send(:hostname).should be_nil
57
57
  end
58
58
 
59
+ it "should not have a bucket_request_context" do
60
+ worker.send(:bucket_request_context).should be_nil
61
+ end
62
+
59
63
  context "when it has a hostname" do
60
64
  before do
61
65
  worker.stub(:hostname).and_return '127.0.0.1'
@@ -156,11 +160,18 @@ describe Worker do
156
160
 
157
161
  it "should get the bucket to process from the leader at every iteration" do
158
162
  worker.should_receive(:leader).exactly(4).times.and_return @leader
159
- @leader.should_receive(:bucket_request).with(worker.uri).exactly(4).times.
163
+ @leader.should_receive(:bucket_request).with(worker.uri, nil).exactly(4).times.
160
164
  and_return([1, 2])
161
165
  worker.start
162
166
  end
163
167
 
168
+ it "should send the bucket_request_context with the bucket request" do
169
+ worker.stub(:loop?).and_return false
170
+ worker.stub(:bucket_request_context).and_return "the context"
171
+ @leader.should_receive(:bucket_request).with(worker.uri, "the context")
172
+ worker.start
173
+ end
174
+
164
175
  it "should exit on :stop bucket" do
165
176
  @leader.should_receive(:bucket_request).ordered.once.and_return([:stop, 0])
166
177
  worker.should_receive(:exit).with(0).ordered.and_return do
@@ -179,8 +190,8 @@ describe Worker do
179
190
  end
180
191
 
181
192
  it "should deliver the bucket" do
182
- worker.should_receive(:next_bucket).with("requestor").and_return "the bucket"
183
- worker.bucket_request("requestor").should == "the bucket"
193
+ worker.should_receive(:next_bucket).with("requestor", "context").and_return "the bucket"
194
+ worker.bucket_request("requestor", "context").should == "the bucket"
184
195
  end
185
196
 
186
197
  describe "when no buckets are left" do
@@ -191,15 +202,15 @@ describe Worker do
191
202
  end
192
203
 
193
204
  it "should deliver the :stop bucket if requestor is in followers_to_stop list" do
194
- worker.bucket_request("1").should == [:stop, 0]
205
+ worker.bucket_request("1", nil).should == [:stop, 0]
195
206
  end
196
207
 
197
208
  it "should not deliver the :stop bucket if requestor is not in followers_to_stop list" do
198
- worker.bucket_request("requestor")[0].should be_nil
209
+ worker.bucket_request("requestor", nil)[0].should be_nil
199
210
  end
200
211
 
201
212
  it "should remove the requestor from the followers_to_stop list" do
202
- worker.bucket_request("2")
213
+ worker.bucket_request("2", nil)
203
214
  worker.followers_to_stop.should =~ %w(1 3)
204
215
  end
205
216
  end
@@ -211,7 +222,7 @@ describe Worker do
211
222
  end
212
223
 
213
224
  it "should deliver the :not_leader bucket" do
214
- worker.bucket_request("requestor")[0].should == :not_leader
225
+ worker.bucket_request("requestor", nil)[0].should == :not_leader
215
226
  end
216
227
  end
217
228
  end
@@ -386,7 +397,7 @@ describe Worker do
386
397
  describe "when creating next bucket" do
387
398
  it "should set the sleep time to sleep_until_next_bucket_time" do
388
399
  worker.should_receive(:sleep_until_next_bucket_time).and_return 'the sleep time'
389
- worker.next_bucket('')[1].should == 'the sleep time'
400
+ worker.next_bucket('', nil)[1].should == 'the sleep time'
390
401
  end
391
402
  end
392
403
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark-politics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-11 00:00:00.000000000 Z
12
+ date: 2013-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec