onstomp 1.0.6 → 1.0.7
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/.gitignore +1 -1
- data/CHANGELOG.md +14 -0
- data/lib/onstomp/connections/base.rb +59 -19
- data/lib/onstomp/failover/client.rb +3 -0
- data/lib/onstomp/interfaces/event_manager.rb +7 -1
- data/lib/onstomp/version.rb +1 -1
- data/lib/onstomp.rb +3 -0
- data/spec/onstomp/connections/base_spec.rb +57 -11
- data/spec/onstomp/full_stacks/onstomp_spec.rb +53 -0
- data/spec/onstomp/full_stacks/{onstomp_ssh_spec.rb → onstomp_ssl_spec.rb} +2 -2
- data/spec/onstomp/full_stacks/test_broker.rb +56 -0
- data/spec/onstomp/interfaces/event_manager_spec.rb +11 -0
- metadata +33 -13
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 1.0.7
|
4
|
+
* rescue any exceptions in event callbacks, uses Kernel#warn to notify the
|
5
|
+
user of the exception
|
6
|
+
* force OnStomp::Failover::Client to wait until the re-connect thread is up
|
7
|
+
and running before initialize returns
|
8
|
+
* force OnStomp::Connections::Base to raise exceptions that occur while trying
|
9
|
+
to read the initial CONNECTED frame from the broker. prior to this, the
|
10
|
+
call to Base#connect would hang indefinitely if the connection to the broker
|
11
|
+
was lost before the CONNECTED frame was received (or if the broker simply did
|
12
|
+
not respond with any frame at all.)
|
13
|
+
|
14
|
+
## 1.0.6
|
15
|
+
* fix a typo on the `connection` attribute in the ReceiptScope
|
16
|
+
|
3
17
|
## 1.0.5
|
4
18
|
* fixed a race condition that would occur if a user (or the failover extension)
|
5
19
|
tried to re-connect an OnStomp::Client instance within an `on_connection_closed`
|
@@ -5,7 +5,7 @@ class OnStomp::Connections::Base
|
|
5
5
|
include OnStomp::Interfaces::ConnectionEvents
|
6
6
|
attr_reader :version, :socket, :client
|
7
7
|
attr_reader :last_transmitted_at, :last_received_at
|
8
|
-
|
8
|
+
attr_reader :write_timeout, :read_timeout
|
9
9
|
|
10
10
|
# The approximate maximum number of bytes to write per call to
|
11
11
|
# {#io_process_write}.
|
@@ -27,10 +27,36 @@ class OnStomp::Connections::Base
|
|
27
27
|
@read_buffer = []
|
28
28
|
@client = client
|
29
29
|
@connection_up = false
|
30
|
-
|
31
|
-
|
30
|
+
self.read_timeout = 120
|
31
|
+
self.write_timeout = nil
|
32
32
|
setup_non_blocking_methods
|
33
33
|
end
|
34
|
+
|
35
|
+
# Sets the read timeout when connecting to the specified number of seconds.
|
36
|
+
# If set to nil, no read timeout checking will be performed.
|
37
|
+
# @param [Number] secs
|
38
|
+
def read_timeout= secs
|
39
|
+
if secs
|
40
|
+
@read_timeout = secs
|
41
|
+
@read_timeout_ms = secs * 1000
|
42
|
+
else
|
43
|
+
@read_timeout = @read_timeout_ms = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sets the maximum number of seconds to wait between IO writes before
|
48
|
+
# declaring the connection blocked. This timeout is ignored if there is no
|
49
|
+
# data waiting to be written. If set to `nil`, connection write timeout
|
50
|
+
# checking will be performed.
|
51
|
+
# @param [Number, nil] secs
|
52
|
+
def write_timeout= secs
|
53
|
+
if secs
|
54
|
+
@write_timeout = secs
|
55
|
+
@write_timeout_ms = secs * 1000
|
56
|
+
else
|
57
|
+
@write_timeout = @write_timeout_ms = nil
|
58
|
+
end
|
59
|
+
end
|
34
60
|
|
35
61
|
# Performs any necessary configuration of the connection from the CONNECTED
|
36
62
|
# frame sent by the broker and a `Hash` of pending callbacks. This method
|
@@ -70,12 +96,14 @@ class OnStomp::Connections::Base
|
|
70
96
|
# @param [OnStomp::Client] client
|
71
97
|
# @param [Array<Hash>] headers
|
72
98
|
def connect client, *headers
|
99
|
+
# I really don't care for this. A core part of the CONNECT/CONNECTED
|
100
|
+
# exchange can only be accomplished through subclasses.
|
73
101
|
write_frame_nonblock connect_frame(*headers)
|
74
102
|
client_con = nil
|
75
103
|
until client_con
|
76
104
|
io_process_write { |f| client_con ||= f }
|
77
105
|
end
|
78
|
-
|
106
|
+
update_last_received
|
79
107
|
broker_con = nil
|
80
108
|
until broker_con
|
81
109
|
io_process_read(true) { |f| broker_con ||= f }
|
@@ -102,14 +130,14 @@ class OnStomp::Connections::Base
|
|
102
130
|
# `nil` if no data has been transmitted when the method is called.
|
103
131
|
# @return [Fixnum, nil]
|
104
132
|
def duration_since_transmitted
|
105
|
-
last_transmitted_at && ((Time.now - last_transmitted_at)*1000)
|
133
|
+
last_transmitted_at && ((Time.now.to_f - last_transmitted_at) * 1000)
|
106
134
|
end
|
107
135
|
|
108
136
|
# Number of milliseconds since data was last received from the broker or
|
109
137
|
# `nil` if no data has been received when the method is called.
|
110
138
|
# @return [Fixnum, nil]
|
111
139
|
def duration_since_received
|
112
|
-
last_received_at && ((Time.now - last_received_at)*1000)
|
140
|
+
last_received_at && ((Time.now.to_f - last_received_at) * 1000)
|
113
141
|
end
|
114
142
|
|
115
143
|
# Flushes the write buffer by invoking {#io_process_write} until the
|
@@ -141,7 +169,7 @@ class OnStomp::Connections::Base
|
|
141
169
|
# @param [OnStomp::Components::Frame]
|
142
170
|
def push_write_buffer data, frame
|
143
171
|
@write_mutex.synchronize {
|
144
|
-
|
172
|
+
update_last_write_activity if @write_buffer.empty?
|
145
173
|
@write_buffer << [data, frame] unless @closing
|
146
174
|
}
|
147
175
|
end
|
@@ -184,7 +212,8 @@ class OnStomp::Connections::Base
|
|
184
212
|
raise
|
185
213
|
end
|
186
214
|
written += w
|
187
|
-
|
215
|
+
update_last_write_activity
|
216
|
+
update_last_transmitted
|
188
217
|
if w < data.length
|
189
218
|
unshift_write_buffer data[w..-1], frame
|
190
219
|
else
|
@@ -204,12 +233,12 @@ class OnStomp::Connections::Base
|
|
204
233
|
# and the socket is ready for reading. The received data will be pushed
|
205
234
|
# to the end of a read buffer, which is then sent to the connection's
|
206
235
|
# {OnStomp::Connections::Serializers serializer} for processing.
|
207
|
-
def io_process_read(
|
236
|
+
def io_process_read(connecting=false)
|
208
237
|
if ready_for_read?
|
209
238
|
begin
|
210
239
|
if data = read_nonblock
|
211
240
|
@read_buffer << data
|
212
|
-
|
241
|
+
update_last_received
|
213
242
|
serializer.bytes_to_frame(@read_buffer) do |frame|
|
214
243
|
yield frame if block_given?
|
215
244
|
client.dispatch_received frame
|
@@ -219,6 +248,7 @@ class OnStomp::Connections::Base
|
|
219
248
|
# do not
|
220
249
|
rescue EOFError
|
221
250
|
triggered_close $!.message
|
251
|
+
raise if connecting
|
222
252
|
rescue Exception
|
223
253
|
# TODO: Fix this potential race condition the right way.
|
224
254
|
# This is the problematic area! If the user (or failover library)
|
@@ -230,14 +260,28 @@ class OnStomp::Connections::Base
|
|
230
260
|
triggered_close $!.message, :terminated
|
231
261
|
raise
|
232
262
|
end
|
233
|
-
|
263
|
+
end
|
264
|
+
if connecting && read_timeout_exceeded?
|
234
265
|
triggered_close 'read blocked', :blocked
|
266
|
+
raise OnStomp::ConnectionTimeoutError
|
235
267
|
end
|
236
268
|
end
|
237
269
|
|
238
270
|
private
|
271
|
+
def update_last_received
|
272
|
+
@last_received_at = Time.now.to_f
|
273
|
+
end
|
274
|
+
|
275
|
+
def update_last_write_activity
|
276
|
+
@last_write_activity = Time.now.to_f
|
277
|
+
end
|
278
|
+
|
279
|
+
def update_last_transmitted
|
280
|
+
@last_transmitted_at = Time.now.to_f
|
281
|
+
end
|
282
|
+
|
239
283
|
def duration_since_write_activity
|
240
|
-
Time.now - @last_write_activity
|
284
|
+
(Time.now.to_f - @last_write_activity) * 1000
|
241
285
|
end
|
242
286
|
|
243
287
|
# Returns true if the connection has buffered data to write and the
|
@@ -270,8 +314,8 @@ class OnStomp::Connections::Base
|
|
270
314
|
# data to write, and `duration_since_transmitted` is greater than
|
271
315
|
# `write_timeout`
|
272
316
|
def write_timeout_exceeded?
|
273
|
-
@
|
274
|
-
duration_since_write_activity > @
|
317
|
+
@write_timeout_ms && @write_buffer.length > 0 &&
|
318
|
+
duration_since_write_activity > @write_timeout_ms
|
275
319
|
end
|
276
320
|
|
277
321
|
# Returns true if a `read_timeout` has been set and
|
@@ -279,16 +323,12 @@ class OnStomp::Connections::Base
|
|
279
323
|
# This is only used when establishing the connection through the CONNECT/
|
280
324
|
# CONNECTED handshake. After that, it is up to heart-beating.
|
281
325
|
def read_timeout_exceeded?
|
282
|
-
@
|
326
|
+
@read_timeout_ms && duration_since_received > @read_timeout_ms
|
283
327
|
end
|
284
328
|
|
285
329
|
def triggered_close msg, *evs
|
286
330
|
@connection_up = false
|
287
331
|
@closing = false
|
288
|
-
# unless socket.closed?
|
289
|
-
# socket.to_io.shutdown(2) rescue nil
|
290
|
-
#
|
291
|
-
# end
|
292
332
|
socket.close rescue nil
|
293
333
|
evs.each { |ev| trigger_connection_event ev, msg }
|
294
334
|
trigger_connection_event :closed, msg
|
@@ -50,14 +50,17 @@ class OnStomp::Failover::Client
|
|
50
50
|
@connection = nil
|
51
51
|
@frame_buffer = buffer.new self
|
52
52
|
@disconnecting = false
|
53
|
+
retry_ready = false
|
53
54
|
@retry_thread = Thread.new do
|
54
55
|
until @disconnecting
|
56
|
+
retry_ready = true
|
55
57
|
Thread.stop
|
56
58
|
@client_mutex.synchronize {
|
57
59
|
reconnect unless @disconnecting
|
58
60
|
}
|
59
61
|
end
|
60
62
|
end
|
63
|
+
Thread.pass until retry_ready && @retry_thread.stop?
|
61
64
|
end
|
62
65
|
|
63
66
|
# Returns true if there is an {#active_client} and it is
|
@@ -27,7 +27,13 @@ module OnStomp::Interfaces::EventManager
|
|
27
27
|
# @param [Symbol] event_name event to trigger
|
28
28
|
# @param [Object, Object, ...] args
|
29
29
|
def trigger_event(event_name, *args)
|
30
|
-
event_callbacks[event_name].each
|
30
|
+
event_callbacks[event_name].each do |cb|
|
31
|
+
begin
|
32
|
+
cb.call(*args)
|
33
|
+
rescue Exception => ex
|
34
|
+
warn "[OnStomp/Event] triggering #{event_name} raised an error: #{ex}"
|
35
|
+
end
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
# Mixin to allow includers to define custom event methods
|
data/lib/onstomp/version.rb
CHANGED
data/lib/onstomp.rb
CHANGED
@@ -74,6 +74,9 @@ module OnStomp
|
|
74
74
|
# Raised when an attempt to connect to the broker results in an unexpected
|
75
75
|
# exchange.
|
76
76
|
class ConnectFailedError < FatalConnectionError; end
|
77
|
+
|
78
|
+
# Raised when the connection between client and broker times out.
|
79
|
+
class ConnectionTimeoutError < FatalConnectionError; end
|
77
80
|
|
78
81
|
# Raised if the command issued is not supported by the protocol version
|
79
82
|
# negotiated between the client and broker.
|
@@ -19,6 +19,16 @@ module OnStomp::Connections
|
|
19
19
|
let(:frame) {
|
20
20
|
mock('frame')
|
21
21
|
}
|
22
|
+
|
23
|
+
describe "timeouts" do
|
24
|
+
it "defaults write timeout to nil" do
|
25
|
+
connection.write_timeout.should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "defaults read timeout to 120 seconds" do
|
29
|
+
connection.read_timeout.should == 120
|
30
|
+
end
|
31
|
+
end
|
22
32
|
|
23
33
|
describe ".method_missing" do
|
24
34
|
it "should raise an unsupported command error if the method ends in _frame" do
|
@@ -47,7 +57,8 @@ module OnStomp::Connections
|
|
47
57
|
it "should be the difference between now and the last_transmitted_at in milliseconds" do
|
48
58
|
Time.stub(:now => 10)
|
49
59
|
connection.stub(:last_transmitted_at => 8.5)
|
50
|
-
|
60
|
+
# Be careful, floating point will give you problems
|
61
|
+
connection.duration_since_transmitted.should == 1500.0
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
@@ -59,7 +70,7 @@ module OnStomp::Connections
|
|
59
70
|
it "should be the difference between now and the last_received_at in milliseconds" do
|
60
71
|
Time.stub(:now => 10)
|
61
72
|
connection.stub(:last_received_at => 6)
|
62
|
-
connection.duration_since_received.should == 4000
|
73
|
+
connection.duration_since_received.should == 4000.0
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
@@ -280,7 +291,14 @@ module OnStomp::Connections
|
|
280
291
|
io.should_receive(:read_nonblock).with(Base::MAX_BYTES_PER_READ).and_raise(Errno::EWOULDBLOCK)
|
281
292
|
lambda { connection.io_process_read }.should_not raise_error
|
282
293
|
end
|
283
|
-
it "
|
294
|
+
it "closes the connection and re-raises EOFError when connecting" do
|
295
|
+
connection.stub(:connected? => true)
|
296
|
+
IO.stub(:select => true)
|
297
|
+
io.should_receive(:read_nonblock).with(Base::MAX_BYTES_PER_READ).and_raise(EOFError)
|
298
|
+
io.should_receive(:close)
|
299
|
+
lambda { connection.io_process_read(true) }.should raise_error(EOFError)
|
300
|
+
end
|
301
|
+
it "closes the connection without re-raising EOFError when not connecting" do
|
284
302
|
connection.stub(:connected? => true)
|
285
303
|
IO.stub(:select => true)
|
286
304
|
io.should_receive(:read_nonblock).with(Base::MAX_BYTES_PER_READ).and_raise(EOFError)
|
@@ -311,13 +329,17 @@ module OnStomp::Connections
|
|
311
329
|
lambda { connection.io_process_read }.should raise_error(Exception)
|
312
330
|
triggered.should be_true
|
313
331
|
end
|
314
|
-
it "
|
332
|
+
it "triggers a blocked close and raises ConnectionTimeoutError when connecting" do
|
315
333
|
triggered = false
|
316
334
|
connection.on_blocked { triggered = true }
|
335
|
+
connection.read_timeout = 0.5
|
317
336
|
IO.stub(:select => false)
|
318
|
-
connection.stub(:
|
337
|
+
connection.stub(:connected? => true)
|
319
338
|
io.should_receive(:close)
|
320
|
-
connection.
|
339
|
+
connection.__send__(:update_last_received)
|
340
|
+
lambda do
|
341
|
+
connection.io_process_read(true) while true
|
342
|
+
end.should raise_error(OnStomp::ConnectionTimeoutError)
|
321
343
|
triggered.should be_true
|
322
344
|
end
|
323
345
|
end
|
@@ -354,17 +376,17 @@ module OnStomp::Connections
|
|
354
376
|
end
|
355
377
|
it "should not exceed the timeout if duration is less than timeout" do
|
356
378
|
connection.read_timeout = 10
|
357
|
-
connection.stub(:duration_since_received => 9000)
|
379
|
+
connection.stub(:duration_since_received => 9000.0)
|
358
380
|
connection.__send__(:read_timeout_exceeded?).should be_false
|
359
381
|
end
|
360
382
|
it "should not exceed the timeout if duration is equal to timeout" do
|
361
383
|
connection.read_timeout = 10
|
362
|
-
connection.stub(:duration_since_received => 10000)
|
384
|
+
connection.stub(:duration_since_received => 10000.0)
|
363
385
|
connection.__send__(:read_timeout_exceeded?).should be_false
|
364
386
|
end
|
365
387
|
it "should exceed the timeout if duration is greater than timeout" do
|
366
388
|
connection.read_timeout = 10
|
367
|
-
connection.stub(:duration_since_received =>
|
389
|
+
connection.stub(:duration_since_received => 10000.1)
|
368
390
|
connection.__send__(:read_timeout_exceeded?).should be_true
|
369
391
|
end
|
370
392
|
end
|
@@ -413,9 +435,9 @@ module OnStomp::Connections
|
|
413
435
|
Time.stub(:now => 69)
|
414
436
|
connection.__send__(:write_timeout_exceeded?).should be_false
|
415
437
|
end
|
416
|
-
it "should not exceed the timeout if the
|
438
|
+
it "should not exceed the timeout if the duration is greater but there's no buffered data" do
|
417
439
|
connection.write_timeout = 1
|
418
|
-
connection.stub(:duration_since_transmitted => 5000)
|
440
|
+
connection.stub(:duration_since_transmitted => 5000.0)
|
419
441
|
connection.__send__(:write_timeout_exceeded?).should be_false
|
420
442
|
end
|
421
443
|
it "should exceed the timeout if buffered and duration is greater than timeout" do
|
@@ -488,6 +510,30 @@ module OnStomp::Connections
|
|
488
510
|
connection.io_process
|
489
511
|
triggered.should == 1
|
490
512
|
end
|
513
|
+
|
514
|
+
it "re-raises an error raised while writing during connect" do
|
515
|
+
io.stub(:closed? => false)
|
516
|
+
connection.stub(:connect_frame => connect_frame)
|
517
|
+
connection.stub(:serializer => OnStomp::Connections::Serializers::Stomp_1_0.new)
|
518
|
+
connection.stub(:ready_for_write? => true)
|
519
|
+
connection.stub(:write_nonblock) { raise EOFError }
|
520
|
+
connection.stub(:io_process_read).with(true).and_yield(connected_frame)
|
521
|
+
lambda do
|
522
|
+
connection.connect(client)
|
523
|
+
end.should raise_error(EOFError)
|
524
|
+
end
|
525
|
+
|
526
|
+
it "re-raises an EOFError raised while reading during connect" do
|
527
|
+
io.stub(:closed? => false)
|
528
|
+
connection.stub(:connect_frame => connect_frame)
|
529
|
+
connection.stub(:serializer => OnStomp::Connections::Serializers::Stomp_1_0.new)
|
530
|
+
connection.stub(:ready_for_read? => true)
|
531
|
+
connection.stub(:read_nonblock) { raise EOFError }
|
532
|
+
connection.stub(:io_process_write).and_yield(connect_frame)
|
533
|
+
lambda do
|
534
|
+
connection.connect(client)
|
535
|
+
end.should raise_error(EOFError)
|
536
|
+
end
|
491
537
|
end
|
492
538
|
|
493
539
|
describe ".configure" do
|
@@ -10,6 +10,59 @@ describe OnStomp::Client, "full stack test (stomp+ssl:)", :fullstack => true do
|
|
10
10
|
body
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
describe "Failing on connect" do
|
15
|
+
let(:broker) {
|
16
|
+
TestBroker.new 10101
|
17
|
+
}
|
18
|
+
before :each do
|
19
|
+
broker.start
|
20
|
+
end
|
21
|
+
after :each do
|
22
|
+
broker.stop
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises an error when the TCP/IP connection is refused" do
|
26
|
+
broker.stop
|
27
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
28
|
+
lambda do
|
29
|
+
client.connect
|
30
|
+
end.should raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises an error if the connection is closed while writing the CONNECT frame" do
|
34
|
+
broker.session_class = TestBroker::SessionCloseBeforeConnect
|
35
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
36
|
+
lambda do
|
37
|
+
client.connect
|
38
|
+
end.should raise_error
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an error if the connection is closed while waiting for the CONNECTED frame" do
|
42
|
+
broker.session_class = TestBroker::SessionCloseAfterConnect
|
43
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
44
|
+
lambda do
|
45
|
+
client.connect
|
46
|
+
end.should raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "raises an error if the connection times out before receiving a CONNECTED frame" do
|
50
|
+
broker.session_class = TestBroker::SessionTimeoutAfterConnect
|
51
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
52
|
+
client.read_timeout = 1
|
53
|
+
lambda do
|
54
|
+
client.connect
|
55
|
+
end.should raise_error(OnStomp::ConnectionTimeoutError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises an error if the broker does not respond with CONNECTED" do
|
59
|
+
broker.session_class = TestBroker::SessionBadFrameAfterConnect
|
60
|
+
client = OnStomp::Client.new('stomp://localhost:10101')
|
61
|
+
lambda do
|
62
|
+
client.connect
|
63
|
+
end.should raise_error(OnStomp::ConnectFailedError)
|
64
|
+
end
|
65
|
+
end
|
13
66
|
|
14
67
|
describe "STOMP 1.0" do
|
15
68
|
let(:broker) {
|
@@ -44,7 +44,7 @@ describe OnStomp::Client, "full stack test (stomp+ssl:)", :fullstack => true do
|
|
44
44
|
})
|
45
45
|
lambda {
|
46
46
|
client.connect
|
47
|
-
}.should raise_error('hostname was not match with the server certificate')
|
47
|
+
}.should raise_error #('hostname was not match with the server certificate')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -83,7 +83,7 @@ describe OnStomp::Client, "full stack test (stomp+ssl:)", :fullstack => true do
|
|
83
83
|
})
|
84
84
|
lambda {
|
85
85
|
client.connect
|
86
|
-
}.should raise_error('hostname was not match with the server certificate')
|
86
|
+
}.should raise_error #('hostname was not match with the server certificate')
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -243,6 +243,62 @@ class TestBroker
|
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
246
|
+
class SessionCloseBeforeConnect
|
247
|
+
def initialize server, sock
|
248
|
+
sock.close rescue nil
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class SessionCloseAfterConnect < Session10
|
253
|
+
def initialize server, sock
|
254
|
+
@server = server
|
255
|
+
@socket = sock
|
256
|
+
init_events
|
257
|
+
init_connection
|
258
|
+
connect_frame = nil
|
259
|
+
@connection.io_process_read do |f|
|
260
|
+
connect_frame ||= f
|
261
|
+
end until connect_frame
|
262
|
+
@socket.close
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
class SessionTimeoutAfterConnect < Session10
|
267
|
+
def initialize server, sock
|
268
|
+
@server = server
|
269
|
+
@socket = sock
|
270
|
+
init_events
|
271
|
+
init_connection
|
272
|
+
connect_frame = nil
|
273
|
+
@connection.io_process_read do |f|
|
274
|
+
connect_frame ||= f
|
275
|
+
end until connect_frame
|
276
|
+
# Do not send a frame, do not close the connection, let it timeout
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
class SessionBadFrameAfterConnect < Session10
|
281
|
+
def initialize server, sock
|
282
|
+
@server = server
|
283
|
+
@socket = sock
|
284
|
+
init_events
|
285
|
+
init_connection
|
286
|
+
connect_frame = nil
|
287
|
+
@connection.io_process_read do |f|
|
288
|
+
connect_frame ||= f
|
289
|
+
end until connect_frame
|
290
|
+
reply_to_connect_with_crap
|
291
|
+
end
|
292
|
+
|
293
|
+
def reply_to_connect_with_crap
|
294
|
+
connected_frame = nil
|
295
|
+
transmit OnStomp::Components::Frame.new('CRAPPY_FRAME')
|
296
|
+
@connection.io_process_write do |f|
|
297
|
+
connected_frame ||= f
|
298
|
+
end until connected_frame
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
246
302
|
class StompErrorOnConnectSession < Session10
|
247
303
|
end
|
248
304
|
end
|
@@ -17,6 +17,17 @@ module OnStomp::Interfaces
|
|
17
17
|
triggered.should == [3, 'test']
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
describe "callbacks with exceptions" do
|
22
|
+
it "does not allow exceptions to break the callback chain" do
|
23
|
+
triggered = [false, false]
|
24
|
+
eventable.bind_event(:an_event, lambda { |*_| raise "failed" })
|
25
|
+
eventable.bind_event(:an_event, lambda { |x,y| triggered[0] = y; raise "failed again" })
|
26
|
+
eventable.bind_event(:an_event, lambda { |x,y| triggered[1] = x })
|
27
|
+
eventable.trigger_event :an_event, 4, 10
|
28
|
+
triggered.should == [10, 4]
|
29
|
+
end
|
30
|
+
end
|
20
31
|
|
21
32
|
describe ".event_callbacks" do
|
22
33
|
it "should provide an empty array for an unbound event" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onstomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.4.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.4.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: simplecov
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 0.3.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: yard
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 0.6.0
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.0
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rake
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
description: Client library for message passing with brokers that support the Stomp
|
59
79
|
protocol.
|
60
80
|
email:
|
@@ -157,7 +177,7 @@ files:
|
|
157
177
|
- spec/onstomp/failover/uri_spec.rb
|
158
178
|
- spec/onstomp/full_stacks/failover_spec.rb
|
159
179
|
- spec/onstomp/full_stacks/onstomp_spec.rb
|
160
|
-
- spec/onstomp/full_stacks/
|
180
|
+
- spec/onstomp/full_stacks/onstomp_ssl_spec.rb
|
161
181
|
- spec/onstomp/full_stacks/open-uri_spec.rb
|
162
182
|
- spec/onstomp/full_stacks/ssl/README
|
163
183
|
- spec/onstomp/full_stacks/ssl/broker_cert.csr
|
@@ -212,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
232
|
version: '0'
|
213
233
|
requirements: []
|
214
234
|
rubyforge_project: onstomp-core
|
215
|
-
rubygems_version: 1.8.
|
235
|
+
rubygems_version: 1.8.21
|
216
236
|
signing_key:
|
217
237
|
specification_version: 3
|
218
238
|
summary: Client for message queues implementing the Stomp protocol interface.
|
@@ -246,7 +266,7 @@ test_files:
|
|
246
266
|
- spec/onstomp/failover/uri_spec.rb
|
247
267
|
- spec/onstomp/full_stacks/failover_spec.rb
|
248
268
|
- spec/onstomp/full_stacks/onstomp_spec.rb
|
249
|
-
- spec/onstomp/full_stacks/
|
269
|
+
- spec/onstomp/full_stacks/onstomp_ssl_spec.rb
|
250
270
|
- spec/onstomp/full_stacks/open-uri_spec.rb
|
251
271
|
- spec/onstomp/full_stacks/ssl/README
|
252
272
|
- spec/onstomp/full_stacks/ssl/broker_cert.csr
|