features/support/test_stomp_server.rb in stomper-2.0.3 vs features/support/test_stomp_server.rb in stomper-2.0.4
- old
+ new
@@ -7,10 +7,11 @@
def initialize(version=nil)
@port = 61613
begin
@socket = TCPServer.new(@port)
rescue Exception => ex
+ retry
end
@session = nil
@version = version
@session_class = StompSession
end
@@ -57,11 +58,11 @@
headers = {}
version && headers[:version] = version
connect_to_client(headers)
@serializer.extend_for_protocol('1.1') if version == '1.1'
@receive_thread = Thread.new do
- while true
+ loop do
begin
read_frame
rescue Exception => ex
break
end
@@ -86,35 +87,37 @@
@receive_thread.join
end
def read_frame
@serializer.read_frame.tap do |f|
- @received_frames << f
- unless f[:receipt].nil? || f[:receipt].empty?
- send_frame 'RECEIPT', { :'receipt-id' => f[:receipt] }
- end
- case f.command
- when 'DISCONNECT'
- @running = false
- @client_socket.close
- when 'SEND'
- if @subscribed[f[:destination]]
- @subscribed[f[:destination]].each_with_index do |sub_id, idx|
- msg = f.dup
- msg[:subscription] = sub_id
- msg[:'message-id'] = "m-#{(Time.now.to_f * 1000).to_i}-#{idx}"
- msg.command = 'MESSAGE'
- send_frame msg
+ if f
+ @received_frames << f
+ unless f[:receipt].nil? || f[:receipt].empty?
+ send_frame 'RECEIPT', { :'receipt-id' => f[:receipt] }
+ end
+ case f.command
+ when 'DISCONNECT'
+ @running = false
+ @client_socket.close
+ when 'SEND'
+ if @subscribed[f[:destination]]
+ @subscribed[f[:destination]].each_with_index do |sub_id, idx|
+ msg = f.dup
+ msg[:subscription] = sub_id
+ msg[:'message-id'] = "m-#{(Time.now.to_f * 1000).to_i}-#{idx}"
+ msg.command = 'MESSAGE'
+ send_frame msg
+ end
end
+ when 'SUBSCRIBE'
+ @subscribed[f[:destination]] ||= []
+ @subscribed[f[:destination]] << f[:id]
+ when 'UNSUBSCRIBE'
+ if @subscribed[f[:destination]]
+ @subscribed[f[:destination]].delete f[:id]
+ end
end
- when 'SUBSCRIBE'
- @subscribed[f[:destination]] ||= []
- @subscribed[f[:destination]] << f[:id]
- when 'UNSUBSCRIBE'
- if @subscribed[f[:destination]]
- @subscribed[f[:destination]].delete f[:id]
- end
end
end
end
def send_frame cmd, headers={}, body=nil
@@ -128,9 +131,10 @@
end
end
class StompErrorOnConnectSession < StompSession
def connect_to_client(headers)
+ rf = read_frame
send_frame 'ERROR'
end
end
end