stomp 1.1.10 → 1.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/test/test_client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  $:.unshift(File.dirname(__FILE__))
2
4
 
3
5
  require 'test_helper'
@@ -6,14 +8,14 @@ class TestClient < Test::Unit::TestCase
6
8
  include TestBase
7
9
 
8
10
  def setup
9
- @client = Stomp::Client.new(user, passcode, host, port)
11
+ @client = get_client()
10
12
  # Multi_thread test data
11
13
  @max_threads = 20
12
14
  @max_msgs = 50
13
15
  end
14
16
 
15
17
  def teardown
16
- @client.close if @client # allow tests to close
18
+ @client.close if @client.open? # allow tests to close
17
19
  end
18
20
 
19
21
  def test_ack_api_works
@@ -23,9 +25,12 @@ class TestClient < Test::Unit::TestCase
23
25
  @client.subscribe(make_destination, {:ack => 'client'}) {|msg| received = msg}
24
26
  sleep 0.01 until received
25
27
  assert_equal message_text, received.body
26
-
27
28
  receipt = nil
28
- @client.acknowledge(received) {|r| receipt = r}
29
+ ack_headers = {}
30
+ if @client.protocol > Stomp::SPL_10
31
+ ack_headers["subscription"] = received.headers["subscription"]
32
+ end
33
+ @client.acknowledge(received, ack_headers) {|r| receipt = r}
29
34
  sleep 0.01 until receipt
30
35
  assert_not_nil receipt.headers['receipt-id']
31
36
  end unless ENV['STOMP_RABBIT']
@@ -50,7 +55,7 @@ class TestClient < Test::Unit::TestCase
50
55
 
51
56
  # was never acked so should be resent to next client
52
57
 
53
- @client = Stomp::Client.new(user, passcode, host, port)
58
+ @client = get_client()
54
59
  received2 = nil
55
60
  @client.subscribe(make_destination) {|msg| received2 = msg}
56
61
  sleep 0.01 until received2
@@ -78,7 +83,6 @@ class TestClient < Test::Unit::TestCase
78
83
  assert_equal(@client.disconnect_receipt.headers['receipt-id'],
79
84
  "xyz789", "receipt sent and received should match")
80
85
  }
81
- @client = nil
82
86
  end
83
87
 
84
88
  def test_publish_then_sub
@@ -128,27 +132,51 @@ class TestClient < Test::Unit::TestCase
128
132
 
129
133
  @client.begin 'tx1'
130
134
  message = nil
131
- @client.subscribe(make_destination, :ack => 'client') {|m| message = m}
135
+ sid = nil
136
+ if @client.protocol() == Stomp::SPL_10
137
+ @client.subscribe(make_destination, :ack => 'client') {|m| message = m}
138
+ else
139
+ sid = @client.uuid()
140
+ @client.subscribe(make_destination, :ack => 'client', :id => sid) {|m| message = m}
141
+ end
132
142
  sleep 0.01 until message
133
143
  assert_equal message_text, message.body
134
- @client.acknowledge message, :transaction => 'tx1'
135
- message = nil
136
- @client.abort 'tx1'
144
+ assert_nothing_raised {
145
+ if @client.protocol() == Stomp::SPL_10
146
+ @client.acknowledge message, :transaction => 'tx1'
147
+ else
148
+ @client.acknowledge message, :transaction => 'tx1', :subscription => sid
149
+ end
150
+ message = nil
151
+ @client.abort 'tx1'
152
+ }
137
153
 
138
154
  # lets recreate the connection
139
155
  teardown
140
156
  setup
141
- @client.subscribe(make_destination, :ack => 'client') {|m| message = m}
142
-
157
+ sid = nil
158
+ assert_nothing_raised {
159
+ if @client.protocol() == Stomp::SPL_10
160
+ @client.subscribe(make_destination, :ack => 'client') {|m| message = m}
161
+ else
162
+ sid = @client.uuid()
163
+ @client.subscribe(make_destination, :ack => 'client', :id => sid) {|m| message = m}
164
+ end
165
+ }
143
166
  Timeout::timeout(4) do
144
167
  sleep 0.01 until message
145
168
  end
146
169
  assert_not_nil message
147
170
  assert_equal message_text, message.body
148
-
171
+ assert_nothing_raised {
149
172
  @client.begin 'tx2'
150
- @client.acknowledge message, :transaction => 'tx2'
151
- @client.commit 'tx2'
173
+ if @client.protocol() == Stomp::SPL_10
174
+ @client.acknowledge message, :transaction => 'tx2'
175
+ else
176
+ @client.acknowledge message, :transaction => 'tx2', :subscription => sid
177
+ end
178
+ @client.commit 'tx2'
179
+ }
152
180
  end
153
181
 
154
182
  def test_raise_on_multiple_subscriptions_to_same_make_destination
@@ -243,12 +271,22 @@ class TestClient < Test::Unit::TestCase
243
271
 
244
272
  @client.begin 'tx1'
245
273
  message = nil
246
- @client.subscribe(make_destination, :ack => 'client') { |m| message = m }
274
+ sid = nil
275
+ if @client.protocol() == Stomp::SPL_10
276
+ @client.subscribe(make_destination, :ack => 'client') { |m| message = m }
277
+ else
278
+ sid = @client.uuid()
279
+ @client.subscribe(make_destination, :ack => 'client', :id => sid) { |m| message = m }
280
+ end
247
281
 
248
282
  sleep 0.1 while message.nil?
249
283
 
250
284
  assert_equal message_text, message.body
251
- @client.acknowledge message, :transaction => 'tx1'
285
+ if @client.protocol() == Stomp::SPL_10
286
+ @client.acknowledge message, :transaction => 'tx1'
287
+ else
288
+ @client.acknowledge message, :transaction => 'tx1', :subscription => sid
289
+ end
252
290
  message = nil
253
291
  @client.abort 'tx1'
254
292
 
@@ -258,7 +296,11 @@ class TestClient < Test::Unit::TestCase
258
296
  assert_equal message_text, message.body
259
297
 
260
298
  @client.begin 'tx2'
261
- @client.acknowledge message, :transaction => 'tx2'
299
+ if @client.protocol() == Stomp::SPL_10
300
+ @client.acknowledge message, :transaction => 'tx2'
301
+ else
302
+ @client.acknowledge message, :transaction => 'tx2', :subscription => sid
303
+ end
262
304
  @client.commit 'tx2'
263
305
  end
264
306
 
@@ -270,28 +312,37 @@ class TestClient < Test::Unit::TestCase
270
312
  message = nil
271
313
  dest = make_destination
272
314
  to_send = message_text
273
- client = Stomp::Client.new(user, passcode, host, port, true)
274
- assert_nothing_raised {
315
+ client = get_client()
316
+ sid = nil
317
+ if @client.protocol() == Stomp::SPL_10
275
318
  client.subscribe(dest, :ack => 'client') { |m| message = m }
276
- @client.publish dest, to_send
277
- Timeout::timeout(4) do
278
- sleep 0.01 until message
279
- end
280
- }
319
+ else
320
+ sid = client.uuid()
321
+ client.subscribe(dest, :ack => 'client', :id => sid) { |m| message = m }
322
+ end
323
+ @client.publish dest, to_send
324
+ Timeout::timeout(4) do
325
+ sleep 0.01 until message
326
+ end
281
327
  assert_equal to_send, message.body, "first body check"
282
- assert_nothing_raised {
283
- client.unsubscribe dest # was throwing exception on unsub at one point
284
- client.close
285
- }
328
+ if @client.protocol() == Stomp::SPL_10
329
+ client.unsubscribe dest
330
+ else
331
+ client.unsubscribe dest, :subscription => sid
332
+ end
333
+ client.close
286
334
  # Same message should remain on the queue. Receive it again with ack=>auto.
287
335
  message_copy = nil
288
- client = Stomp::Client.new(user, passcode, host, port, true)
289
- assert_nothing_raised {
336
+ client = get_client()
337
+ if @client.protocol() == Stomp::SPL_10
290
338
  client.subscribe(dest, :ack => 'auto') { |m| message_copy = m }
291
- Timeout::timeout(4) do
292
- sleep 0.01 until message_copy
293
- end
294
- }
339
+ else
340
+ sid = client.uuid()
341
+ client.subscribe(dest, :ack => 'auto', :id => sid) { |m| message_copy = m }
342
+ end
343
+ Timeout::timeout(4) do
344
+ sleep 0.01 until message_copy
345
+ end
295
346
  assert_equal to_send, message_copy.body, "second body check"
296
347
  assert_equal message.headers['message-id'], message_copy.headers['message-id'], "header check" unless ENV['STOMP_RABBIT']
297
348
  end
@@ -301,7 +352,11 @@ class TestClient < Test::Unit::TestCase
301
352
  dest = make_destination
302
353
  Thread.new(@client) do |acli|
303
354
  assert_nothing_raised {
304
- acli.subscribe(dest) { |m| msg = m }
355
+ if acli.protocol() == Stomp::SPL_10
356
+ acli.subscribe(dest) { |m| msg = m }
357
+ else
358
+ acli.subscribe(dest, :id => acli.uuid()) { |m| msg = m }
359
+ end
305
360
  Timeout::timeout(4) do
306
361
  sleep 0.01 until msg
307
362
  end
@@ -322,14 +377,26 @@ class TestClient < Test::Unit::TestCase
322
377
  # Threads within threads .....
323
378
  Thread.new(@client) do |acli|
324
379
  assert_nothing_raised {
325
- acli.subscribe(dest) { |m|
326
- msg = m
327
- lock.synchronize do
328
- msg_ctr += 1
329
- end
330
- # Simulate message processing
331
- sleep 0.05
332
- }
380
+ # this is ugly .....
381
+ if acli.protocol() == Stomp::SPL_10
382
+ acli.subscribe(dest) { |m|
383
+ msg = m
384
+ lock.synchronize do
385
+ msg_ctr += 1
386
+ end
387
+ # Simulate message processing
388
+ sleep 0.05
389
+ }
390
+ else
391
+ acli.subscribe(dest, :id => acli.uuid()) { |m|
392
+ msg = m
393
+ lock.synchronize do
394
+ msg_ctr += 1
395
+ end
396
+ # Simulate message processing
397
+ sleep 0.05
398
+ }
399
+ end
333
400
  }
334
401
  end
335
402
  end
@@ -351,6 +418,47 @@ class TestClient < Test::Unit::TestCase
351
418
  assert_equal @max_msgs, msg_ctr
352
419
  end
353
420
 
421
+ def test_closed_checks_client
422
+ @client.close
423
+ #
424
+ assert_raise Stomp::Error::NoCurrentConnection do
425
+ m = Stomp::Message.new("")
426
+ @client.acknowledge(m) {|r| receipt = r}
427
+ end
428
+ #
429
+ assert_raise Stomp::Error::NoCurrentConnection do
430
+ @client.begin("dummy_data")
431
+ end
432
+ #
433
+ assert_raise Stomp::Error::NoCurrentConnection do
434
+ @client.commit("dummy_data")
435
+ end
436
+ #
437
+ assert_raise Stomp::Error::NoCurrentConnection do
438
+ @client.abort("dummy_data")
439
+ end
440
+ #
441
+ assert_raise Stomp::Error::NoCurrentConnection do
442
+ @client.subscribe("dummy_data", {:ack => 'auto'}) {|msg| received = msg}
443
+ end
444
+ #
445
+ assert_raise Stomp::Error::NoCurrentConnection do
446
+ @client.unsubscribe("dummy_data")
447
+ end
448
+ #
449
+ assert_raise Stomp::Error::NoCurrentConnection do
450
+ @client.publish("dummy_data","dummy_data")
451
+ end
452
+ #
453
+ assert_raise Stomp::Error::NoCurrentConnection do
454
+ @client.unreceive("dummy_data")
455
+ end
456
+ #
457
+ assert_raise Stomp::Error::NoCurrentConnection do
458
+ @client.close("dummy_data")
459
+ end
460
+ end
461
+
354
462
  private
355
463
  def message_text
356
464
  name = caller_method_name unless name
@@ -0,0 +1,83 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.unshift(File.dirname(__FILE__))
4
+
5
+ require 'test_helper'
6
+
7
+ class TestCodec < Test::Unit::TestCase
8
+ include TestBase
9
+
10
+ def setup
11
+ @conn = get_connection()
12
+ # Data for multi_thread tests
13
+ @max_threads = 20
14
+ @max_msgs = 100
15
+ end
16
+
17
+ def teardown
18
+ @conn.disconnect if @conn.open? # allow tests to disconnect
19
+ end
20
+
21
+ def test_1000_check_notneeded
22
+ test_data = [
23
+ "a",
24
+ "abcdefghijklmnopqrstuvwxyz",
25
+ "ªºÀÁ",
26
+ "AÇBØCꞇDẼ",
27
+ "ªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ" +
28
+ "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġDŽDždžLJLjǼǽǾǿȀȁȂȃȌȍȒɰɵɲɮᴘᴤᴭᴥᵻᶅ" +
29
+ "ᶑṆṌṕṽẄẂỚỘⅱⅲꜨꝐꞂ",
30
+ ]
31
+ #
32
+ test_data.each do |s|
33
+ #
34
+ s_decoded = Stomp::HeaderCodec::decode(s)
35
+ assert_equal s, s_decoded, "Sanity check decode: #{s} | #{s_decoded}"
36
+ s_reencoded = Stomp::HeaderCodec::encode(s_decoded)
37
+ assert_equal s_decoded, s_reencoded, "Sanity check reencode: #{s_decoded} | #{s_reencoded}"
38
+ #
39
+ end
40
+ end
41
+
42
+ #
43
+ def test_1010_basic_encode_decode
44
+ test_data = [
45
+ [ "\\\\", "\\" ],
46
+ ["\\n", "\n"],
47
+ ["\\c", ":"],
48
+ ["\\\\\\n\\c", "\\\n:"],
49
+ ["\\c\\n\\\\", ":\n\\"],
50
+ ["\\\\\\c", "\\:"],
51
+ ["c\\cc", "c:c"],
52
+ ["n\\nn", "n\nn"],
53
+ ]
54
+ #
55
+ test_data.each do |s|
56
+ #
57
+ s_decoded = Stomp::HeaderCodec::encode(s[0])
58
+ assert_equal s[1], s_decoded, "Sanity check encode: #{s[1]} | #{s_decoded}"
59
+ #
60
+ s_encoded = Stomp::HeaderCodec::decode(s[1])
61
+ assert_equal s[0], s_encoded, "Sanity check decode: #{s[0]} | #{s_encoded}"
62
+ end
63
+ end
64
+
65
+ #
66
+ def test_1020_fancier
67
+ test_data = [
68
+ [ "a\\\\b", "a\\b" ],
69
+ [ "\\\\\\n\\c", "\\\n:" ],
70
+ ]
71
+ #
72
+ test_data.each do |s|
73
+ #
74
+ s_decoded = Stomp::HeaderCodec::encode(s[0])
75
+ assert_equal s[1], s_decoded, "Sanity check encode: #{s[1]} | #{s_decoded}"
76
+ #
77
+ s_encoded = Stomp::HeaderCodec::decode(s[1])
78
+ assert_equal s[0], s_encoded, "Sanity check decode: #{s[0]} | #{s_encoded}"
79
+ end
80
+ end
81
+
82
+ end # of class
83
+
@@ -1,19 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  $:.unshift(File.dirname(__FILE__))
2
4
 
3
5
  require 'test_helper'
4
6
 
5
- class TestStomp < Test::Unit::TestCase
7
+ class TestConnection < Test::Unit::TestCase
6
8
  include TestBase
7
9
 
8
10
  def setup
9
- @conn = Stomp::Connection.open(user, passcode, host, port)
11
+ @conn = get_connection()
10
12
  # Data for multi_thread tests
11
13
  @max_threads = 20
12
14
  @max_msgs = 100
13
15
  end
14
16
 
15
17
  def teardown
16
- @conn.disconnect if @conn # allow tests to disconnect
18
+ @conn.disconnect if @conn.open? # allow tests to disconnect
17
19
  end
18
20
 
19
21
  def test_connection_exists
@@ -21,7 +23,7 @@ class TestStomp < Test::Unit::TestCase
21
23
  end
22
24
 
23
25
  def test_no_length
24
- @conn.subscribe make_destination
26
+ conn_subscribe make_destination
25
27
  #
26
28
  @conn.publish make_destination, "test_stomp#test_no_length",
27
29
  { :suppress_content_length => true }
@@ -31,18 +33,22 @@ class TestStomp < Test::Unit::TestCase
31
33
  @conn.publish make_destination, "test_stomp#test_\000_length",
32
34
  { :suppress_content_length => true }
33
35
  msg2 = @conn.receive
34
- assert_equal "test_stomp#test_", msg2.body
36
+ if @conn.protocol == Stomp::SPL_10
37
+ assert_equal "test_stomp#test_", msg2.body
38
+ else
39
+ assert_equal "test_stomp#test_\000_length", msg2.body
40
+ end
35
41
  end unless ENV['STOMP_RABBIT']
36
42
 
37
43
  def test_explicit_receive
38
- @conn.subscribe make_destination
44
+ conn_subscribe make_destination
39
45
  @conn.publish make_destination, "test_stomp#test_explicit_receive"
40
46
  msg = @conn.receive
41
47
  assert_equal "test_stomp#test_explicit_receive", msg.body
42
48
  end
43
49
 
44
50
  def test_receipt
45
- @conn.subscribe make_destination, :receipt => "abc"
51
+ conn_subscribe make_destination, :receipt => "abc"
46
52
  msg = @conn.receive
47
53
  assert_equal "abc", msg.headers['receipt-id']
48
54
  end
@@ -54,18 +60,28 @@ class TestStomp < Test::Unit::TestCase
54
60
  assert_equal(@conn.disconnect_receipt.headers['receipt-id'],
55
61
  "abc123", "receipt sent and received should match")
56
62
  }
57
- @conn = nil
58
63
  end
59
64
 
60
65
  def test_client_ack_with_symbol
61
- @conn.subscribe make_destination, :ack => :client
66
+ if @conn.protocol == Stomp::SPL_10
67
+ @conn.subscribe make_destination, :ack => :client
68
+ else
69
+ sid = @conn.uuid()
70
+ @conn.subscribe make_destination, :ack => :client, :id => sid
71
+ end
62
72
  @conn.publish make_destination, "test_stomp#test_client_ack_with_symbol"
63
73
  msg = @conn.receive
64
- @conn.ack msg.headers['message-id']
74
+ assert_nothing_raised {
75
+ if @conn.protocol == Stomp::SPL_10
76
+ @conn.ack msg.headers['message-id']
77
+ else
78
+ @conn.ack msg.headers['message-id'], :subscription => sid
79
+ end
80
+ }
65
81
  end
66
82
 
67
83
  def test_embedded_null
68
- @conn.subscribe make_destination
84
+ conn_subscribe make_destination
69
85
  @conn.publish make_destination, "a\0"
70
86
  msg = @conn.receive
71
87
  assert_equal "a\0" , msg.body
@@ -83,15 +99,63 @@ class TestStomp < Test::Unit::TestCase
83
99
  assert_equal true, @conn.closed?
84
100
  end
85
101
 
102
+ def test_closed_checks_conn
103
+ @conn.disconnect
104
+ #
105
+ assert_raise Stomp::Error::NoCurrentConnection do
106
+ @conn.ack("dummy_data")
107
+ end
108
+ #
109
+ assert_raise Stomp::Error::NoCurrentConnection do
110
+ @conn.begin("dummy_data")
111
+ end
112
+ #
113
+ assert_raise Stomp::Error::NoCurrentConnection do
114
+ @conn.commit("dummy_data")
115
+ end
116
+ #
117
+ assert_raise Stomp::Error::NoCurrentConnection do
118
+ @conn.abort("dummy_data")
119
+ end
120
+ #
121
+ assert_raise Stomp::Error::NoCurrentConnection do
122
+ conn_subscribe("dummy_data")
123
+ end
124
+ #
125
+ assert_raise Stomp::Error::NoCurrentConnection do
126
+ @conn.unsubscribe("dummy_data")
127
+ end
128
+ #
129
+ assert_raise Stomp::Error::NoCurrentConnection do
130
+ @conn.publish("dummy_data","dummy_data")
131
+ end
132
+ #
133
+ assert_raise Stomp::Error::NoCurrentConnection do
134
+ @conn.unreceive("dummy_data")
135
+ end
136
+ #
137
+ assert_raise Stomp::Error::NoCurrentConnection do
138
+ @conn.disconnect("dummy_data")
139
+ end
140
+ #
141
+ assert_raise Stomp::Error::NoCurrentConnection do
142
+ m = @conn.receive
143
+ end
144
+ #
145
+ assert_raise Stomp::Error::NoCurrentConnection do
146
+ m = @conn.poll
147
+ end
148
+ end
149
+
86
150
  def test_response_is_instance_of_message_class
87
- @conn.subscribe make_destination
151
+ conn_subscribe make_destination
88
152
  @conn.publish make_destination, "a\0"
89
153
  msg = @conn.receive
90
154
  assert_instance_of Stomp::Message , msg
91
155
  end
92
156
 
93
157
  def test_message_to_s
94
- @conn.subscribe make_destination
158
+ conn_subscribe make_destination
95
159
  @conn.publish make_destination, "a\0"
96
160
  msg = @conn.receive
97
161
  assert_match /^<Stomp::Message headers=/ , msg.to_s
@@ -102,7 +166,7 @@ class TestStomp < Test::Unit::TestCase
102
166
  end
103
167
 
104
168
  def test_messages_with_multipleLine_ends
105
- @conn.subscribe make_destination
169
+ conn_subscribe make_destination
106
170
  @conn.publish make_destination, "a\n\n"
107
171
  @conn.publish make_destination, "b\n\na\n\n"
108
172
 
@@ -114,7 +178,7 @@ class TestStomp < Test::Unit::TestCase
114
178
  end
115
179
 
116
180
  def test_publish_two_messages
117
- @conn.subscribe make_destination
181
+ conn_subscribe make_destination
118
182
  @conn.publish make_destination, "a\0"
119
183
  @conn.publish make_destination, "b\0"
120
184
  msg_a = @conn.receive
@@ -132,7 +196,7 @@ class TestStomp < Test::Unit::TestCase
132
196
  end
133
197
  end
134
198
  #
135
- @conn.subscribe( make_destination )
199
+ conn_subscribe( make_destination )
136
200
  message = Time.now.to_s
137
201
  @conn.publish(make_destination, message)
138
202
  sleep 1
@@ -142,7 +206,7 @@ class TestStomp < Test::Unit::TestCase
142
206
 
143
207
  def test_thread_poll_one
144
208
  received = nil
145
- max_sleep = (RUBY_VERSION =~ /1\.8\.6/) ? 5 : 1
209
+ max_sleep = (RUBY_VERSION =~ /1\.8/) ? 10 : 1
146
210
  Thread.new(@conn) do |amq|
147
211
  while true
148
212
  received = amq.poll
@@ -152,7 +216,7 @@ class TestStomp < Test::Unit::TestCase
152
216
  end
153
217
  end
154
218
  #
155
- @conn.subscribe( make_destination )
219
+ conn_subscribe( make_destination )
156
220
  message = Time.now.to_s
157
221
  @conn.publish(make_destination, message)
158
222
  sleep max_sleep+1
@@ -178,13 +242,14 @@ class TestStomp < Test::Unit::TestCase
178
242
  end
179
243
  end
180
244
  #
181
- @conn.subscribe( dest )
245
+ conn_subscribe( dest )
182
246
  1.upto(@max_msgs) do |mnum|
183
247
  msg = Time.now.to_s + " #{mnum}"
184
248
  @conn.publish(dest, msg)
185
249
  end
186
250
  #
187
- max_sleep = (RUBY_VERSION =~ /1\.8\.6/) ? 30 : 5
251
+ max_sleep = (RUBY_VERSION =~ /1\.8/) ? 30 : 5
252
+ max_sleep = 30 if RUBY_ENGINE =~ /mingw/
188
253
  sleep_incr = 0.10
189
254
  total_slept = 0
190
255
  while true
@@ -194,7 +259,7 @@ class TestStomp < Test::Unit::TestCase
194
259
  sleep sleep_incr
195
260
  end
196
261
  assert_equal @max_msgs, msg_ctr
197
- end
262
+ end unless RUBY_ENGINE =~ /jruby/
198
263
 
199
264
  def test_multi_thread_poll
200
265
  #
@@ -220,13 +285,14 @@ class TestStomp < Test::Unit::TestCase
220
285
  end
221
286
  end
222
287
  #
223
- @conn.subscribe( dest )
288
+ conn_subscribe( dest )
224
289
  1.upto(@max_msgs) do |mnum|
225
290
  msg = Time.now.to_s + " #{mnum}"
226
291
  @conn.publish(dest, msg)
227
292
  end
228
293
  #
229
294
  max_sleep = (RUBY_VERSION =~ /1\.8\.6/) ? 30 : 5
295
+ max_sleep = 30 if RUBY_ENGINE =~ /mingw/
230
296
  sleep_incr = 0.10
231
297
  total_slept = 0
232
298
  while true
@@ -236,20 +302,20 @@ class TestStomp < Test::Unit::TestCase
236
302
  sleep sleep_incr
237
303
  end
238
304
  assert_equal @max_msgs, msg_ctr
239
- end
305
+ end unless RUBY_ENGINE =~ /jruby/
240
306
 
241
307
  def test_nil_body
242
308
  dest = make_destination
243
309
  assert_nothing_raised {
244
310
  @conn.publish dest, nil
245
311
  }
246
- @conn.subscribe dest
312
+ conn_subscribe dest
247
313
  msg = @conn.receive
248
314
  assert_equal "", msg.body
249
315
  end
250
316
 
251
317
  def test_transaction
252
- @conn.subscribe make_destination
318
+ conn_subscribe make_destination
253
319
 
254
320
  @conn.begin "txA"
255
321
  @conn.publish make_destination, "txn message", 'transaction' => "txA"
@@ -264,5 +330,52 @@ class TestStomp < Test::Unit::TestCase
264
330
  assert_equal "txn message", msg.body
265
331
  end
266
332
 
333
+ def test_duplicate_subscription
334
+ @conn.disconnect # not reliable
335
+ @conn = Stomp::Connection.open(user, passcode, host, port, true) # reliable
336
+ dest = make_destination
337
+ conn_subscribe dest
338
+ #
339
+ assert_raise Stomp::Error::DuplicateSubscription do
340
+ conn_subscribe dest
341
+ end
342
+ end
343
+
344
+ def test_nil_connparms
345
+ @conn.disconnect
346
+ #
347
+ assert_nothing_raised do
348
+ @conn = Stomp::Connection.open(user, passcode, host, port, false, 5, nil)
349
+ end
350
+ end
351
+
352
+ def test_nack11p_0010
353
+ if @conn.protocol == Stomp::SPL_10
354
+ assert_raise Stomp::Error::UnsupportedProtocolError do
355
+ @conn.nack "dummy msg-id"
356
+ end
357
+ else
358
+ sid = @conn.uuid()
359
+ dest = make_destination
360
+ @conn.subscribe dest, :ack => :client, :id => sid
361
+ smsg = "test_stomp#test_nack01: #{Time.now.to_f}"
362
+ @conn.publish make_destination, smsg
363
+ msg = @conn.receive
364
+ assert_equal smsg, msg.body
365
+ assert_nothing_raised {
366
+ @conn.nack msg.headers["message-id"], :subscription => sid
367
+ sleep 0.05 # Give racy brokers a chance to handle the last nack before unsubscribe
368
+ @conn.unsubscribe dest, :id => sid
369
+ }
370
+ # phase 2
371
+ teardown()
372
+ setup()
373
+ sid = @conn.uuid()
374
+ @conn.subscribe dest, :ack => :auto, :id => sid
375
+ msg2 = @conn.receive
376
+ assert_equal smsg, msg2.body
377
+ end
378
+ end
379
+
267
380
  end
268
381