fraggle 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/fraggle.rb +11 -2
- data/lib/fraggle/client.rb +17 -11
- data/lib/fraggle/emitter.rb +3 -0
- data/lib/fraggle/snap.rb +4 -0
- data/test/fraggle_client_test.rb +6 -12
- metadata +11 -4
data/README.md
CHANGED
data/lib/fraggle.rb
CHANGED
@@ -6,10 +6,19 @@ require 'uri'
|
|
6
6
|
module Fraggle
|
7
7
|
extend Logger
|
8
8
|
|
9
|
-
|
9
|
+
DefaultUri = "doozer:?"+
|
10
|
+
# Default host/port
|
11
|
+
"ca=127.0.0.1:8046&"+
|
12
|
+
|
13
|
+
# Default host + test-cluster ports
|
14
|
+
"ca=127.0.0.1:8041&"+
|
15
|
+
"ca=127.0.0.1:8042&"+
|
16
|
+
"ca=127.0.0.1:8043"
|
17
|
+
|
18
|
+
def self.connect(uri=ENV["DOOZER_URI"] || DefaultUri)
|
10
19
|
addrs = addrs_for(uri)
|
11
20
|
host, port = addrs.first.split(":")
|
12
|
-
c = EM.connect(host, port, Client, addrs
|
21
|
+
c = EM.connect(host, port, Client, addrs)
|
13
22
|
Snap.new(0, c)
|
14
23
|
end
|
15
24
|
|
data/lib/fraggle/client.rb
CHANGED
@@ -191,16 +191,18 @@ module Fraggle
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def send(req, &blk)
|
194
|
-
|
194
|
+
if ! req.tag
|
195
|
+
tag = MinTag
|
195
196
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
197
|
+
while @cbx.has_key?(tag)
|
198
|
+
tag += 1
|
199
|
+
if tag > MaxTag
|
200
|
+
tag = MinTag
|
201
|
+
end
|
200
202
|
end
|
201
|
-
end
|
202
203
|
|
203
|
-
|
204
|
+
req.tag = tag
|
205
|
+
end
|
204
206
|
|
205
207
|
if blk
|
206
208
|
req.valid(&blk)
|
@@ -208,7 +210,7 @@ module Fraggle
|
|
208
210
|
|
209
211
|
# Setup a default error handler that gives useful information
|
210
212
|
req.error do |e|
|
211
|
-
|
213
|
+
warn("'error (%d) (%s)' for: %s" % [
|
212
214
|
e.err_code,
|
213
215
|
e.err_detail.inspect,
|
214
216
|
req.inspect
|
@@ -246,13 +248,17 @@ module Fraggle
|
|
246
248
|
|
247
249
|
@last_received = Time.now
|
248
250
|
|
251
|
+
# We've been connected to a new server. Notify all requests.
|
252
|
+
@cbx.values.each do |req|
|
253
|
+
req.emit(:again, req)
|
254
|
+
end
|
255
|
+
|
249
256
|
EM.add_periodic_timer(2) do
|
250
257
|
if (n = Time.now - last_received) >= 3
|
251
258
|
error("timeout talking to #{@addr}")
|
252
259
|
close_connection
|
253
260
|
else
|
254
|
-
|
255
|
-
get(0, "/ping") { debug("pong") }
|
261
|
+
get(0, "/ping")
|
256
262
|
end
|
257
263
|
end
|
258
264
|
|
@@ -294,7 +300,7 @@ module Fraggle
|
|
294
300
|
|
295
301
|
# What happens when a connection is closed for any reason.
|
296
302
|
def unbind
|
297
|
-
|
303
|
+
warn "disconnected from #{@addr}"
|
298
304
|
|
299
305
|
# Shun the address we were currently attempting/connected to.
|
300
306
|
@shun[@addr] = Time.now
|
data/lib/fraggle/emitter.rb
CHANGED
@@ -13,12 +13,15 @@ module Fraggle
|
|
13
13
|
def valid(&blk) ; must_callback!(:valid, blk) ; end
|
14
14
|
def done(&blk) ; must_callback!(:done, blk) ; end
|
15
15
|
def error(&blk) ; must_callback!(:error, blk) ; end
|
16
|
+
def again(&blk) ; must_callback!(:again, blk) ; end
|
16
17
|
|
17
18
|
def must_callback!(name, blk)
|
18
19
|
if ! blk
|
19
20
|
raise ArgumentError, "no block given to `#{name}`"
|
20
21
|
end
|
21
22
|
callbacks[name] = blk
|
23
|
+
|
24
|
+
self
|
22
25
|
end
|
23
26
|
|
24
27
|
def aggr(coll=[], &blk)
|
data/lib/fraggle/snap.rb
CHANGED
data/test/fraggle_client_test.rb
CHANGED
@@ -46,18 +46,6 @@ class FraggleClientTest < Test::Unit::TestCase
|
|
46
46
|
assert_equal 1, blk.length
|
47
47
|
end
|
48
48
|
|
49
|
-
def test_default_error
|
50
|
-
req = c.send(Fraggle::Request.new)
|
51
|
-
|
52
|
-
assert_raises Fraggle::Client::Error do
|
53
|
-
reply(req.tag, :err_code => E::OTHER, :err_detail => "boom!")
|
54
|
-
end
|
55
|
-
|
56
|
-
assert_nothing_raised do
|
57
|
-
reply(req.tag, :err_code => E::OTHER, :err_detail => "boom!")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
49
|
def test_error
|
62
50
|
req = c.send(Fraggle::Request.new)
|
63
51
|
req.error(&blk)
|
@@ -78,6 +66,12 @@ class FraggleClientTest < Test::Unit::TestCase
|
|
78
66
|
assert_equal t+4, c.noop.tag
|
79
67
|
end
|
80
68
|
|
69
|
+
def test_no_tag_if_tag
|
70
|
+
req = Fraggle::Request.new :tag => 99
|
71
|
+
c.send(req)
|
72
|
+
assert_sent 99
|
73
|
+
end
|
74
|
+
|
81
75
|
# CHECKIN cas, path => cas
|
82
76
|
def test_checkin
|
83
77
|
req = c.checkin("abc123", 123, &blk)
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fraggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 5
|
10
|
+
version: 0.3.5
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Blake Mizerany
|
@@ -21,9 +22,11 @@ dependencies:
|
|
21
22
|
name: beefcake
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 1
|
@@ -74,23 +77,27 @@ rdoc_options:
|
|
74
77
|
require_paths:
|
75
78
|
- lib
|
76
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
77
81
|
requirements:
|
78
82
|
- - ">="
|
79
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
80
85
|
segments:
|
81
86
|
- 0
|
82
87
|
version: "0"
|
83
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
84
90
|
requirements:
|
85
91
|
- - ">="
|
86
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
87
94
|
segments:
|
88
95
|
- 0
|
89
96
|
version: "0"
|
90
97
|
requirements: []
|
91
98
|
|
92
99
|
rubyforge_project: fraggle
|
93
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.5.2
|
94
101
|
signing_key:
|
95
102
|
specification_version: 2
|
96
103
|
summary: A Ruby/EventMachine Client for Doozer
|