stomp 1.0.6 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module Stomp
2
+
3
+ # Container class for frames, misnamed technically
4
+ class Message
5
+ attr_accessor :headers, :body, :command
6
+
7
+ def initialize
8
+ yield(self) if block_given?
9
+ end
10
+
11
+ def to_s
12
+ "<Stomp::Message headers=#{headers.inspect} body='#{body}' command='#{command}' >"
13
+ end
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,182 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @client = Stomp::Client.new("test", "user", "localhost", 61613)
7
+ end
8
+
9
+ def teardown
10
+ @client.close
11
+ end
12
+
13
+ def message_text
14
+ "test_client#" + name()
15
+ end
16
+
17
+ def destination
18
+ "/queue/test/ruby/client/" + name()
19
+ end
20
+
21
+ def test_subscribe_requires_block
22
+ assert_raise(RuntimeError) do
23
+ @client.subscribe destination
24
+ end
25
+ end
26
+
27
+ def test_asynch_subscribe
28
+ received = false
29
+ @client.subscribe(destination) {|msg| received = msg}
30
+ @client.send destination, message_text
31
+ sleep 0.01 until received
32
+
33
+ assert_equal message_text, received.body
34
+ end
35
+
36
+ def test_ack_api_works
37
+ @client.send destination, message_text
38
+
39
+ received = nil
40
+ @client.subscribe(destination, :ack => 'client') {|msg| received = msg}
41
+ sleep 0.01 until received
42
+ assert_equal message_text, received.body
43
+
44
+ receipt = nil
45
+ @client.acknowledge(received) {|r| receipt = r}
46
+ sleep 0.01 until receipt
47
+ assert_not_nil receipt.headers['receipt-id']
48
+ end
49
+
50
+ # BROKEN
51
+ def test_noack
52
+ @client.send destination, message_text
53
+
54
+ received = nil
55
+ @client.subscribe(destination, :ack => :client) {|msg| received = msg}
56
+ sleep 0.01 until received
57
+ assert_equal message_text, received.body
58
+ @client.close
59
+
60
+ # was never acked so should be resent to next client
61
+
62
+ @client = Stomp::Client.new("test", "user", "localhost", 61613)
63
+ received = nil
64
+ @client.subscribe(destination) {|msg| received = msg}
65
+ sleep 0.01 until received
66
+
67
+ assert_equal message_text, received.body
68
+ end
69
+
70
+ def test_receipts
71
+ receipt = false
72
+ @client.send(destination, message_text) {|r| receipt = r}
73
+ sleep 0.1 until receipt
74
+
75
+ message = nil
76
+ @client.subscribe(destination) {|m| message = m}
77
+ sleep 0.1 until message
78
+ assert_equal message_text, message.body
79
+ end
80
+
81
+ def test_send_then_sub
82
+ @client.send destination, message_text
83
+ message = nil
84
+ @client.subscribe(destination) {|m| message = m}
85
+ sleep 0.01 until message
86
+
87
+ assert_equal message_text, message.body
88
+ end
89
+
90
+ def test_transactional_send
91
+ @client.begin 'tx1'
92
+ @client.send destination, message_text, :transaction => 'tx1'
93
+ @client.commit 'tx1'
94
+
95
+ message = nil
96
+ @client.subscribe(destination) {|m| message = m}
97
+ sleep 0.01 until message
98
+
99
+ assert_equal message_text, message.body
100
+ end
101
+
102
+ def test_transaction_send_then_rollback
103
+ @client.begin 'tx1'
104
+ @client.send destination, "first_message", :transaction => 'tx1'
105
+ @client.abort 'tx1'
106
+
107
+ @client.begin 'tx1'
108
+ @client.send destination, "second_message", :transaction => 'tx1'
109
+ @client.commit 'tx1'
110
+
111
+ message = nil
112
+ @client.subscribe(destination) {|m| message = m}
113
+ sleep 0.01 until message
114
+ assert_equal "second_message", message.body
115
+ end
116
+
117
+ def test_transaction_ack_rollback_with_new_client
118
+ @client.send destination, message_text
119
+
120
+ @client.begin 'tx1'
121
+ message = nil
122
+ @client.subscribe(destination, :ack => 'client') {|m| message = m}
123
+ sleep 0.01 until message
124
+ assert_equal message_text, message.body
125
+ @client.acknowledge message, :transaction => 'tx1'
126
+ message = nil
127
+ @client.abort 'tx1'
128
+
129
+ # lets recreate the connection
130
+ teardown
131
+ setup
132
+ @client.subscribe(destination, :ack => 'client') {|m| message = m}
133
+
134
+ Timeout::timeout(4) do
135
+ sleep 0.01 until message
136
+ end
137
+ assert_not_nil message
138
+ assert_equal message_text, message.body
139
+
140
+ @client.begin 'tx2'
141
+ @client.acknowledge message, :transaction => 'tx2'
142
+ @client.commit 'tx2'
143
+ end
144
+
145
+ def test_unsubscribe
146
+ message = nil
147
+ client = Stomp::Client.new("test", "user", "localhost", 61613, true)
148
+ client.subscribe(destination, :ack => 'client') { |m| message = m }
149
+ @client.send destination, message_text
150
+ Timeout::timeout(4) do
151
+ sleep 0.01 until message
152
+ end
153
+ client.unsubscribe destination # was throwing exception on unsub at one point
154
+
155
+ end
156
+
157
+ def test_transaction_with_client_side_redelivery
158
+ @client.send destination, message_text
159
+
160
+ @client.begin 'tx1'
161
+ message = nil
162
+ @client.subscribe(destination, :ack => 'client') { |m| message = m }
163
+
164
+ sleep 0.1 while message.nil?
165
+
166
+ assert_equal message_text, message.body
167
+ @client.acknowledge message, :transaction => 'tx1'
168
+ message = nil
169
+ @client.abort 'tx1'
170
+
171
+ sleep 0.1 while message.nil?
172
+
173
+ assert_not_nil message
174
+ assert_equal message_text, message.body
175
+
176
+ @client.begin 'tx2'
177
+ @client.acknowledge message, :transaction => 'tx2'
178
+ @client.commit 'tx2'
179
+ end
180
+
181
+
182
+ end
@@ -0,0 +1,95 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+
3
+ class TestStomp < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @conn = Stomp::Connection.open("test", "user", "localhost", 61613)
7
+ end
8
+
9
+ def teardown
10
+ @conn.disconnect
11
+ end
12
+
13
+ def make_destination
14
+ "/queue/test/ruby/stomp/" + name()
15
+ end
16
+
17
+ def _test_transaction
18
+ @conn.subscribe make_destination
19
+
20
+ # Drain the destination.
21
+ sleep 0.01 while
22
+ sleep 0.01 while @conn.poll!=nil
23
+
24
+ @conn.begin "tx1"
25
+ @conn.send make_destination, "txn message", 'transaction' => "tx1"
26
+
27
+ @conn.send make_destination, "first message"
28
+
29
+ sleep 0.01
30
+ msg = @conn.receive
31
+ assert_equal "first message", msg.body
32
+
33
+ @conn.commit "tx1"
34
+ msg = @conn.receive
35
+ assert_equal "txn message", msg.body
36
+ end
37
+
38
+ def test_connection_exists
39
+ assert_not_nil @conn
40
+ end
41
+
42
+ def test_explicit_receive
43
+ @conn.subscribe make_destination
44
+ @conn.send make_destination, "test_stomp#test_explicit_receive"
45
+ msg = @conn.receive
46
+ assert_equal "test_stomp#test_explicit_receive", msg.body
47
+ end
48
+
49
+ def test_receipt
50
+ @conn.subscribe make_destination, :receipt => "abc"
51
+ msg = @conn.receive
52
+ assert_equal "abc", msg.headers['receipt-id']
53
+ end
54
+
55
+ def test_client_ack_with_symbol
56
+ @conn.subscribe make_destination, :ack => :client
57
+ @conn.send make_destination, "test_stomp#test_client_ack_with_symbol"
58
+ msg = @conn.receive
59
+ @conn.ack msg.headers['message-id']
60
+ end
61
+
62
+ def test_embedded_null
63
+ @conn.subscribe make_destination
64
+ @conn.send make_destination, "a\0"
65
+ msg = @conn.receive
66
+ assert_equal "a\0" , msg.body
67
+ end
68
+
69
+ def test_connection_open?
70
+ assert_equal true , @conn.open?
71
+ @conn.disconnect
72
+ assert_equal false, @conn.open?
73
+ end
74
+
75
+ def test_connection_closed?
76
+ assert_equal false, @conn.closed?
77
+ @conn.disconnect
78
+ assert_equal true, @conn.closed?
79
+ end
80
+
81
+ def test_response_is_instance_of_message_class
82
+ @conn.subscribe make_destination
83
+ @conn.send make_destination, "a\0"
84
+ msg = @conn.receive
85
+ assert_instance_of Stomp::Message , msg
86
+ end
87
+
88
+ def test_message_to_s
89
+ @conn.subscribe make_destination
90
+ @conn.send make_destination, "a\0"
91
+ msg = @conn.receive
92
+ assert_match /^<Stomp::Message headers=/ , msg.to_s
93
+ end
94
+
95
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ require 'timeout'
3
+ require 'stomp'
4
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
5
+
metadata CHANGED
@@ -1,33 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stomp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
- - Someone, possibly Andrew Kuklewicz
7
+ - Brian McCallister
8
+ - Marius Mathiesen
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-11-10 00:00:00 -08:00
13
+ date: 2009-02-27 00:00:00 +01:00
13
14
  default_executable:
14
15
  dependencies: []
15
16
 
16
- description:
17
- email: dev@stomp.codehaus.org
18
- executables: []
19
-
17
+ description: Ruby client for the Stomp messaging protocol
18
+ email:
19
+ - brianm@apache.org
20
+ - marius@stones.com
21
+ executables:
22
+ - catstomp
23
+ - stompcat
20
24
  extensions: []
21
25
 
22
- extra_rdoc_files: []
23
-
26
+ extra_rdoc_files:
27
+ - README.rdoc
28
+ - CHANGELOG
29
+ - LICENSE
24
30
  files:
31
+ - README.rdoc
32
+ - LICENSE
33
+ - CHANGELOG
34
+ - Rakefile
25
35
  - lib/stomp.rb
26
- has_rdoc: false
36
+ - lib/stomp/client.rb
37
+ - lib/stomp/connection.rb
38
+ - lib/stomp/message.rb
39
+ - test/test_client.rb
40
+ - test/test_connection.rb
41
+ - test/test_helper.rb
42
+ has_rdoc: true
27
43
  homepage: http://stomp.codehaus.org/
28
44
  post_install_message:
29
- rdoc_options: []
30
-
45
+ rdoc_options:
46
+ - --quiet
47
+ - --title
48
+ - stomp documentation
49
+ - --opname
50
+ - index.html
51
+ - --line-numbers
52
+ - --main
53
+ - README.rdoc
54
+ - --inline-source
31
55
  require_paths:
32
56
  - lib
33
57
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -45,9 +69,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
69
  requirements: []
46
70
 
47
71
  rubyforge_project:
48
- rubygems_version: 1.3.0
72
+ rubygems_version: 1.3.1
49
73
  signing_key:
50
74
  specification_version: 2
51
75
  summary: Ruby client for the Stomp messaging protocol
52
- test_files: []
53
-
76
+ test_files:
77
+ - test/test_client.rb
78
+ - test/test_connection.rb
79
+ - test/test_helper.rb