fraggle 0.1.1 → 0.2.0
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/README.md +32 -16
- data/lib/fraggle.rb +6 -316
- data/lib/fraggle/client.rb +325 -0
- data/lib/fraggle/emitter.rb +26 -0
- data/lib/fraggle/logger.rb +26 -0
- data/lib/fraggle/meta.rb +9 -0
- data/lib/fraggle/{proto.rb → msg.rb} +10 -2
- data/lib/fraggle/protocol.rb +47 -0
- data/lib/fraggle/request.rb +15 -0
- data/lib/fraggle/response.rb +33 -0
- data/lib/fraggle/snap.rb +43 -0
- data/lib/fraggle/test.rb +72 -0
- data/test/fraggle_client_test.rb +261 -0
- data/test/fraggle_protocol_test.rb +100 -0
- data/test/fraggle_snap_test.rb +67 -0
- metadata +20 -11
- data/test/core_test.rb +0 -215
- data/test/live_test.rb +0 -197
- data/test/reconnect_test.rb +0 -175
data/test/reconnect_test.rb
DELETED
@@ -1,175 +0,0 @@
|
|
1
|
-
require 'fraggle'
|
2
|
-
|
3
|
-
class RecConn
|
4
|
-
include Fraggle
|
5
|
-
|
6
|
-
attr_reader :store, :recs
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
super("1:1", :assemble => true)
|
10
|
-
post_init
|
11
|
-
@store = {}
|
12
|
-
@recs = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def get(path, sid=0, &blk)
|
16
|
-
res = store.fetch(path) { fail("testing: no slot for #{path}") }
|
17
|
-
blk.call(res)
|
18
|
-
end
|
19
|
-
|
20
|
-
def reconnect(host, port)
|
21
|
-
@recs << [host, port]
|
22
|
-
end
|
23
|
-
|
24
|
-
def send_data(data)
|
25
|
-
# do nothing
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class ReconnectTest < Test::Unit::TestCase
|
30
|
-
|
31
|
-
Walk = 0
|
32
|
-
Watch = 1
|
33
|
-
|
34
|
-
attr_reader :c
|
35
|
-
|
36
|
-
def setup
|
37
|
-
@c = RecConn.new
|
38
|
-
end
|
39
|
-
|
40
|
-
def reply(to, path, value)
|
41
|
-
res = Fraggle::Response.new
|
42
|
-
res.tag = to
|
43
|
-
res.flags = Fraggle::Response::Flag::VALID
|
44
|
-
res.path = path
|
45
|
-
res.value = value
|
46
|
-
res.validate!
|
47
|
-
|
48
|
-
c.receive_response(res)
|
49
|
-
end
|
50
|
-
|
51
|
-
def set(path, value)
|
52
|
-
res = Fraggle::Response.new
|
53
|
-
res.tag = 123
|
54
|
-
res.flags = Fraggle::Response::Flag::VALID
|
55
|
-
res.value = value
|
56
|
-
res.validate!
|
57
|
-
|
58
|
-
c.store[path] = res
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_ignore_current
|
62
|
-
assert_equal Hash.new, c.doozers
|
63
|
-
|
64
|
-
set "/doozer/info/ABC/public-addr", "1:1"
|
65
|
-
reply(Walk, "/doozer/slot/1", "ABC")
|
66
|
-
|
67
|
-
assert_equal Hash.new, c.doozers
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_add_other_slots_at_start
|
71
|
-
set "/doozer/info/DEF/public-addr", "2:2"
|
72
|
-
set "/doozer/info/GHI/public-addr", "3:3"
|
73
|
-
reply(Walk, "/doozer/slot/2", "DEF")
|
74
|
-
reply(Walk, "/doozer/slot/3", "GHI")
|
75
|
-
|
76
|
-
exp = {
|
77
|
-
"/doozer/slot/2" => "2:2",
|
78
|
-
"/doozer/slot/3" => "3:3"
|
79
|
-
}
|
80
|
-
|
81
|
-
assert_equal exp, c.doozers
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_add_new_slots_as_they_come
|
85
|
-
set "/doozer/info/DEF/public-addr", "2:2"
|
86
|
-
set "/doozer/info/GHI/public-addr", "3:3"
|
87
|
-
reply(Watch, "/doozer/slot/2", "DEF")
|
88
|
-
reply(Watch, "/doozer/slot/3", "GHI")
|
89
|
-
|
90
|
-
exp = {
|
91
|
-
"/doozer/slot/2" => "2:2",
|
92
|
-
"/doozer/slot/3" => "3:3"
|
93
|
-
}
|
94
|
-
|
95
|
-
assert_equal exp, c.doozers
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_del_slots_if_they_emptied
|
99
|
-
set "/doozer/info/DEF/public-addr", "2:2"
|
100
|
-
set "/doozer/info/GHI/public-addr", "3:3"
|
101
|
-
reply(Walk, "/doozer/slot/2", "DEF")
|
102
|
-
reply(Walk, "/doozer/slot/3", "GHI")
|
103
|
-
|
104
|
-
# Del
|
105
|
-
reply(Watch, "/doozer/slot/3", "")
|
106
|
-
|
107
|
-
exp = {
|
108
|
-
"/doozer/slot/2" => "2:2"
|
109
|
-
}
|
110
|
-
|
111
|
-
assert_equal exp, c.doozers
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_raise_error_if_given_by_server
|
115
|
-
res = Fraggle::Response.new
|
116
|
-
res.tag = Walk
|
117
|
-
res.flags = Fraggle::Response::Flag::VALID
|
118
|
-
res.err_code = Fraggle::Response::Err::OTHER
|
119
|
-
res.err_detail = "invalid glob"
|
120
|
-
|
121
|
-
assert_raises Fraggle::AssemblyError do
|
122
|
-
c.receive_response(res)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_out_of_doozers
|
127
|
-
assert_raises Fraggle::AssemblyError do
|
128
|
-
c.unbind
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_first_reconnect_success
|
133
|
-
set "/doozer/info/DEF/public-addr", "2:2"
|
134
|
-
set "/doozer/info/GHI/public-addr", "3:3"
|
135
|
-
reply(Walk, "/doozer/slot/2", "DEF")
|
136
|
-
reply(Walk, "/doozer/slot/3", "GHI")
|
137
|
-
|
138
|
-
c.unbind
|
139
|
-
assert_equal 1, c.recs.length
|
140
|
-
|
141
|
-
# The order in which the client try is non-detrministic because we're
|
142
|
-
# shifting off a Hash.
|
143
|
-
assert ["2:2", "3:3"].include?(c.addr)
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_second_reconnect_success
|
147
|
-
set "/doozer/info/DEF/public-addr", "2:2"
|
148
|
-
set "/doozer/info/GHI/public-addr", "3:3"
|
149
|
-
reply(Walk, "/doozer/slot/2", "DEF")
|
150
|
-
reply(Walk, "/doozer/slot/3", "GHI")
|
151
|
-
|
152
|
-
c.unbind
|
153
|
-
c.unbind
|
154
|
-
assert_equal 2, c.recs.length
|
155
|
-
|
156
|
-
# The order in which the client try is non-detrministic because we're
|
157
|
-
# shifting off a Hash.
|
158
|
-
assert ["2:2", "3:3"].include?(c.addr)
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_all_recconcts_fail
|
162
|
-
set "/doozer/info/DEF/public-addr", "2:2"
|
163
|
-
set "/doozer/info/GHI/public-addr", "3:3"
|
164
|
-
reply(Walk, "/doozer/slot/2", "DEF")
|
165
|
-
reply(Walk, "/doozer/slot/3", "GHI")
|
166
|
-
|
167
|
-
c.unbind
|
168
|
-
c.unbind
|
169
|
-
|
170
|
-
assert_raises Fraggle::AssemblyError do
|
171
|
-
c.unbind
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
end
|