klomp 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.rspec +2 -0
- data/.simplecov +8 -0
- data/ChangeLog.md +11 -1
- data/Gemfile +18 -12
- data/Gemfile.lock +36 -16
- data/Manifest.txt +31 -0
- data/README.md +134 -116
- data/Rakefile +18 -5
- data/klomp.gemspec +52 -17
- data/lib/klomp.rb +44 -3
- data/lib/klomp/connection.rb +163 -0
- data/lib/klomp/frames.rb +108 -0
- data/lib/klomp/sentinel.rb +21 -0
- data/spec/acceptance/acceptance_spec.rb +152 -0
- data/spec/frames/auth_error.txt +0 -0
- data/spec/frames/connect.txt +0 -0
- data/spec/frames/connect_vhost.txt +0 -0
- data/spec/frames/connected.txt +0 -0
- data/spec/frames/disconnect.txt +0 -0
- data/spec/frames/error.txt +0 -0
- data/spec/frames/greeting.txt +0 -0
- data/spec/frames/message.txt +0 -0
- data/spec/frames/receipt.txt +0 -0
- data/spec/frames/subscribe.txt +0 -0
- data/spec/frames/unsubscribe.txt +0 -0
- data/spec/klomp/connection_spec.rb +329 -0
- data/spec/klomp/frames_spec.rb +23 -0
- data/spec/klomp/sentinel_spec.rb +57 -0
- data/spec/klomp_spec.rb +167 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/have_received.rb +101 -0
- metadata +163 -35
- data/.gitignore +0 -1
- data/.rvmrc +0 -1
- data/Procfile +0 -2
- data/lib/klomp/client.rb +0 -163
- data/tasks/test_failover.rake +0 -35
- data/test/test_client.rb +0 -245
- data/test/test_helper.rb +0 -14
data/tasks/test_failover.rake
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
desc "Start an infinite publish/subscribe loop to test STOMP client failover"
|
2
|
-
task :test_failover do
|
3
|
-
require 'klomp'
|
4
|
-
|
5
|
-
# Set the delay between publish events. If this is too small, the consumer
|
6
|
-
# will never be able to catch up to the producer, giving the false impression
|
7
|
-
# of lost messages.
|
8
|
-
publish_interval = 0.01
|
9
|
-
|
10
|
-
client = Klomp::Client.new([
|
11
|
-
'stomp://admin:password@localhost:61613',
|
12
|
-
'stomp://admin:password@127.0.0.1:62613'
|
13
|
-
]).connect
|
14
|
-
|
15
|
-
last_i = nil
|
16
|
-
client.subscribe("/queue/test") do |msg|
|
17
|
-
print "-"
|
18
|
-
last_i = msg.body.to_i
|
19
|
-
end
|
20
|
-
|
21
|
-
begin
|
22
|
-
i = 0
|
23
|
-
loop do
|
24
|
-
i += 1
|
25
|
-
client.send("/queue/test", i.to_s) do |r|
|
26
|
-
print "+"
|
27
|
-
end
|
28
|
-
sleep publish_interval
|
29
|
-
end
|
30
|
-
rescue SignalException
|
31
|
-
client.disconnect
|
32
|
-
puts
|
33
|
-
puts "Sent #{i}; Received #{last_i}; Lost #{i - last_i}"
|
34
|
-
end
|
35
|
-
end
|
data/test/test_client.rb
DELETED
@@ -1,245 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'minitest/pride'
|
3
|
-
|
4
|
-
require 'klomp'
|
5
|
-
require File.expand_path('../test_helper', __FILE__)
|
6
|
-
|
7
|
-
describe Klomp::Client do
|
8
|
-
|
9
|
-
include KlompTestHelpers
|
10
|
-
|
11
|
-
before do
|
12
|
-
@uris = [
|
13
|
-
'stomp://admin:password@localhost:61613',
|
14
|
-
'stomp://admin:password@127.0.0.1:62613'
|
15
|
-
]
|
16
|
-
@destination = '/queue/test_component.test_event'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'accepts a single uri and establishes separate failover connections for writes and reads' do
|
20
|
-
client = Klomp::Client.new(@uris.first).connect
|
21
|
-
|
22
|
-
assert_equal [client.write_conn], client.read_conn
|
23
|
-
assert client.write_conn.connected?
|
24
|
-
|
25
|
-
client.disconnect
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'accepts an array of uris and establishes separate failover connections for writes and reads' do
|
29
|
-
client = Klomp::Client.new(@uris).connect
|
30
|
-
|
31
|
-
assert client.write_conn.connected?
|
32
|
-
refute_empty client.read_conn
|
33
|
-
client.read_conn.each do |obj|
|
34
|
-
assert obj.connected?
|
35
|
-
end
|
36
|
-
|
37
|
-
client.disconnect
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'allows the virtual host to be set' do
|
41
|
-
vhost = "klomp-test"
|
42
|
-
|
43
|
-
client = Klomp::Client.new(@uris, :vhost => vhost)
|
44
|
-
assert_equal vhost, client.vhost
|
45
|
-
|
46
|
-
client.all_conn.each do |failover_client|
|
47
|
-
failover_client.client_pool.each do |conn|
|
48
|
-
assert_equal vhost, conn.host
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'raises an error if authentication fails' do
|
54
|
-
assert_raises OnStomp::ConnectFailedError do
|
55
|
-
Klomp::Client.new(@uris.first.sub('password', 'psswrd')).connect
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'disconnnects' do
|
60
|
-
client = Klomp::Client.new(@uris.first).connect
|
61
|
-
assert client.write_conn.connected?
|
62
|
-
client.disconnect
|
63
|
-
refute client.write_conn.connected?
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'has a logger' do
|
67
|
-
logger = Logger.new(STDOUT)
|
68
|
-
client = Klomp::Client.new(@uris, :logger=>logger)
|
69
|
-
assert_equal client.log, logger
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'sends heartbeat' do
|
73
|
-
client = Klomp::Client.new(@uris).connect
|
74
|
-
client.beat
|
75
|
-
client.disconnect
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'sends requests and gets responses' do
|
79
|
-
client = Klomp::Client.new(@uris).connect
|
80
|
-
body = { 'body' => rand(36**128).to_s(36) }
|
81
|
-
|
82
|
-
client.send(@destination, body, :ack=>'client')
|
83
|
-
|
84
|
-
got_message = false
|
85
|
-
client.subscribe(@destination) do |msg|
|
86
|
-
got_message = true if msg.body == body
|
87
|
-
client.ack(msg)
|
88
|
-
end
|
89
|
-
let_background_processor_run
|
90
|
-
assert got_message
|
91
|
-
|
92
|
-
client.disconnect
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'automatically publishes responses to the reply-to destination' do
|
96
|
-
client = Klomp::Client.new(@uris).connect
|
97
|
-
reply_to_body = { 'reply_to_body' => rand(36**128).to_s(36) }
|
98
|
-
|
99
|
-
client.send(@destination, nil, { 'reply-to' => @destination })
|
100
|
-
|
101
|
-
got_message = false
|
102
|
-
client.subscribe(@destination) do |msg|
|
103
|
-
got_message = true if msg.body == reply_to_body
|
104
|
-
reply_to_body
|
105
|
-
end
|
106
|
-
let_background_processor_run
|
107
|
-
assert got_message
|
108
|
-
|
109
|
-
client.disconnect
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'unsubscribes' do
|
113
|
-
client = Klomp::Client.new(@uris).connect
|
114
|
-
|
115
|
-
subscribe_frames = client.subscribe(@destination) { |msg| }
|
116
|
-
unsub_frames = client.unsubscribe(subscribe_frames)
|
117
|
-
assert_equal subscribe_frames.length, unsub_frames.length
|
118
|
-
let_background_processor_run
|
119
|
-
|
120
|
-
assert client.subscriptions.flatten.empty?, "expected connection to have no subscriptions"
|
121
|
-
|
122
|
-
client.disconnect
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'sends all unknown options through to OnStomp' do
|
126
|
-
client = Klomp::Client.new(@uris.first, :haz_cheezburgers => true, :retry_attempts => 42).connect
|
127
|
-
assert client.write_conn.connected?
|
128
|
-
assert_equal 42, client.write_conn.retry_attempts
|
129
|
-
client.disconnect
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'uses a fibonacci back-off approach to reconnect' do
|
133
|
-
good_client = Object.new
|
134
|
-
def good_client.connect; true; end
|
135
|
-
def good_client.connected?; true; end
|
136
|
-
def good_client.connection; true; end
|
137
|
-
|
138
|
-
bad_client = Object.new
|
139
|
-
def bad_client.connect; raise "could not connect"; end
|
140
|
-
def bad_client.connected?; false; end
|
141
|
-
|
142
|
-
test_context = self
|
143
|
-
attempts = 0
|
144
|
-
conn = nil
|
145
|
-
fib = lambda {|n| (1..n).inject([0, 1]) {|fib,_| [fib[1], fib[0]+fib[1]]}.first}
|
146
|
-
|
147
|
-
pool_class = Class.new do
|
148
|
-
def initialize(*) end
|
149
|
-
def each(&blk) end
|
150
|
-
define_method :next_client do
|
151
|
-
attempts += 1
|
152
|
-
test_context.assert_equal fib[attempts], conn.retry_delay
|
153
|
-
if attempts == 6
|
154
|
-
good_client
|
155
|
-
else
|
156
|
-
bad_client
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
client = Klomp::Client.new(@uris.first, :pool => pool_class)
|
162
|
-
conn = client.write_conn
|
163
|
-
def conn.sleep_for_retry(*) end # skip sleep between retries for test
|
164
|
-
|
165
|
-
client.reconnect
|
166
|
-
assert_equal 6, attempts
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'sends messages with uuids in the :id header' do
|
170
|
-
client = Klomp::Client.new(@uris, :translate_json => false).connect
|
171
|
-
client.send(@destination, '')
|
172
|
-
|
173
|
-
received_message = false
|
174
|
-
client.subscribe(@destination) do |msg|
|
175
|
-
received_message = msg
|
176
|
-
end
|
177
|
-
let_background_processor_run
|
178
|
-
assert received_message
|
179
|
-
assert received_message[:id], "message did not have an id"
|
180
|
-
assert received_message[:id] =~ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
181
|
-
"message id did not look like a uuid"
|
182
|
-
|
183
|
-
client.disconnect
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'allows customization of the uuid generator' do
|
187
|
-
generator = Object.new
|
188
|
-
def generator.generate; "42"; end
|
189
|
-
|
190
|
-
client = Klomp::Client.new(@uris, :translate_json => false, :uuid => generator).connect
|
191
|
-
client.send(@destination, '')
|
192
|
-
|
193
|
-
received_message = false
|
194
|
-
client.subscribe(@destination) do |msg|
|
195
|
-
received_message = msg
|
196
|
-
end
|
197
|
-
let_background_processor_run
|
198
|
-
assert received_message
|
199
|
-
assert received_message[:id], "message did not have an id"
|
200
|
-
assert_equal "42", received_message[:id]
|
201
|
-
|
202
|
-
client.disconnect
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'allows disabling generated message ids' do
|
206
|
-
client = Klomp::Client.new(@uris, :translate_json => false, :uuid => false).connect
|
207
|
-
client.send(@destination, '')
|
208
|
-
|
209
|
-
received_message = false
|
210
|
-
client.subscribe(@destination) do |msg|
|
211
|
-
received_message = msg
|
212
|
-
end
|
213
|
-
let_background_processor_run
|
214
|
-
assert received_message
|
215
|
-
refute received_message[:id], "message had an id"
|
216
|
-
|
217
|
-
client.disconnect
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'logs message ids' do
|
221
|
-
logger = Object.new
|
222
|
-
def logger.msgs; @msgs; end
|
223
|
-
def logger.debug(msg) (@msgs ||= []) << msg end
|
224
|
-
|
225
|
-
client = Klomp::Client.new(@uris, :translate_json => false, :logger => logger).connect
|
226
|
-
client.send(@destination, '')
|
227
|
-
|
228
|
-
received_message = false
|
229
|
-
client.subscribe(@destination) do |msg|
|
230
|
-
received_message = msg
|
231
|
-
end
|
232
|
-
let_background_processor_run
|
233
|
-
assert received_message
|
234
|
-
assert received_message[:id], "message did not have an id"
|
235
|
-
|
236
|
-
assert_equal 2, logger.msgs.length
|
237
|
-
assert logger.msgs[0] =~ /\[Sending\] ID=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
|
238
|
-
sent_id = $1
|
239
|
-
assert logger.msgs[1] =~ /\[Received\] ID=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
|
240
|
-
received_id = $1
|
241
|
-
assert_equal sent_id, received_id
|
242
|
-
|
243
|
-
client.disconnect
|
244
|
-
end
|
245
|
-
end
|
data/test/test_helper.rb
DELETED