infopark-politics 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -174,6 +174,16 @@ module Politics
174
174
  true
175
175
  end
176
176
 
177
+ def leader
178
+ 2.times do
179
+ break if leader_uri
180
+ log.debug "could not determine leader - relaxing until next iteration"
181
+ relax until_next_iteration
182
+ end
183
+ raise "cannot determine leader" unless leader_uri
184
+ DRbObject.new(nil, leader_uri)
185
+ end
186
+
177
187
  private
178
188
 
179
189
  def bucket_process(bucket, sleep_time)
@@ -205,14 +215,6 @@ module Politics
205
215
  def update_buckets
206
216
  end
207
217
 
208
- def replicas
209
- @replicas ||= []
210
- end
211
-
212
- def leader
213
- DRbObject.new(nil, leader_uri)
214
- end
215
-
216
218
  def loop?
217
219
  true
218
220
  end
@@ -270,7 +272,6 @@ module Politics
270
272
  Time.now - a
271
273
  end
272
274
 
273
-
274
275
  def register_with_bonjour
275
276
  server = DRb.start_service(nil, self)
276
277
  @uri = DRb.uri
@@ -22,6 +22,10 @@ class Worker
22
22
  def client_for(servers)
23
23
  @@memcache_client
24
24
  end
25
+
26
+ def local_ip
27
+ IPAddr.new("127.0.0.1")
28
+ end
25
29
  end
26
30
 
27
31
  describe Worker do
@@ -252,4 +256,39 @@ describe Worker do
252
256
  @worker.sleep_until_next_bucket_time.should == 5
253
257
  end
254
258
  end
259
+
260
+ describe "when providing leader object" do
261
+ before do
262
+ @worker.stub!(:until_next_iteration).and_return 0
263
+ end
264
+
265
+ it "should return a drb object with the leader uri" do
266
+ @worker.stub!(:leader_uri).and_return("leader's uri")
267
+ DRbObject.should_receive(:new).with(nil, "leader's uri").and_return "leader"
268
+ @worker.leader.should == "leader"
269
+ end
270
+
271
+ it "should try three times to get the leader on anarchy (no leader)" do
272
+ @worker.should_receive(:leader_uri).at_least(3).times.and_return nil
273
+ begin
274
+ @worker.leader
275
+ rescue
276
+ end
277
+ end
278
+
279
+ it "should raise an error when leader cannot be determined during anarchy" do
280
+ @worker.stub!(:leader_uri).and_return nil
281
+ lambda {@worker.leader}.should raise_error(/cannot determine leader/)
282
+ end
283
+
284
+ it "should sleep until next iteration before retrying to get leader" do
285
+ @worker.stub!(:leader_uri).and_return nil
286
+ @worker.stub!(:until_next_iteration).and_return 666
287
+ @worker.should_receive(:relax).with(666).exactly(2).times
288
+ begin
289
+ @worker.leader
290
+ rescue
291
+ end
292
+ end
293
+ end
255
294
  end
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.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-07-01 00:00:00 -07:00
13
+ date: 2009-07-13 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency