bunny 1.7.0 → 2.17.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.
Files changed (141) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +18 -0
  3. data/.gitignore +6 -1
  4. data/.rspec +1 -3
  5. data/.travis.yml +21 -14
  6. data/CONTRIBUTING.md +132 -0
  7. data/ChangeLog.md +745 -1
  8. data/Gemfile +13 -13
  9. data/LICENSE +1 -1
  10. data/README.md +41 -75
  11. data/Rakefile +54 -0
  12. data/bunny.gemspec +4 -10
  13. data/docker-compose.yml +28 -0
  14. data/docker/Dockerfile +24 -0
  15. data/docker/apt/preferences.d/erlang +3 -0
  16. data/docker/apt/sources.list.d/bintray.rabbitmq.list +2 -0
  17. data/docker/docker-entrypoint.sh +26 -0
  18. data/docker/rabbitmq.conf +29 -0
  19. data/examples/connection/automatic_recovery_with_basic_get.rb +1 -1
  20. data/examples/connection/automatic_recovery_with_client_named_queues.rb +1 -1
  21. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +1 -1
  22. data/examples/connection/automatic_recovery_with_republishing.rb +1 -1
  23. data/examples/connection/automatic_recovery_with_server_named_queues.rb +1 -1
  24. data/examples/connection/channel_level_exception.rb +1 -9
  25. data/examples/connection/disabled_automatic_recovery.rb +1 -1
  26. data/examples/connection/heartbeat.rb +1 -1
  27. data/examples/consumers/high_and_low_priority.rb +1 -1
  28. data/examples/guides/extensions/alternate_exchange.rb +2 -0
  29. data/examples/guides/getting_started/hello_world.rb +2 -0
  30. data/examples/guides/getting_started/weathr.rb +2 -0
  31. data/examples/guides/queues/one_off_consumer.rb +2 -0
  32. data/examples/guides/queues/redeliveries.rb +2 -0
  33. data/lib/bunny.rb +6 -2
  34. data/lib/bunny/channel.rb +192 -109
  35. data/lib/bunny/channel_id_allocator.rb +6 -4
  36. data/lib/bunny/concurrent/continuation_queue.rb +34 -13
  37. data/lib/bunny/consumer_work_pool.rb +34 -6
  38. data/lib/bunny/cruby/socket.rb +29 -16
  39. data/lib/bunny/cruby/ssl_socket.rb +20 -7
  40. data/lib/bunny/exceptions.rb +7 -1
  41. data/lib/bunny/exchange.rb +11 -7
  42. data/lib/bunny/get_response.rb +1 -1
  43. data/lib/bunny/heartbeat_sender.rb +3 -2
  44. data/lib/bunny/jruby/socket.rb +23 -6
  45. data/lib/bunny/jruby/ssl_socket.rb +5 -0
  46. data/lib/bunny/queue.rb +12 -10
  47. data/lib/bunny/reader_loop.rb +31 -18
  48. data/lib/bunny/session.rb +389 -134
  49. data/lib/bunny/test_kit.rb +14 -0
  50. data/lib/bunny/timeout.rb +1 -12
  51. data/lib/bunny/transport.rb +114 -67
  52. data/lib/bunny/version.rb +1 -1
  53. data/repl +1 -1
  54. data/spec/config/rabbitmq.conf +13 -0
  55. data/spec/higher_level_api/integration/basic_ack_spec.rb +154 -22
  56. data/spec/higher_level_api/integration/basic_cancel_spec.rb +77 -11
  57. data/spec/higher_level_api/integration/basic_consume_spec.rb +60 -55
  58. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +6 -6
  59. data/spec/higher_level_api/integration/basic_get_spec.rb +31 -7
  60. data/spec/higher_level_api/integration/basic_nack_spec.rb +22 -19
  61. data/spec/higher_level_api/integration/basic_publish_spec.rb +11 -100
  62. data/spec/higher_level_api/integration/basic_qos_spec.rb +32 -4
  63. data/spec/higher_level_api/integration/basic_reject_spec.rb +94 -16
  64. data/spec/higher_level_api/integration/basic_return_spec.rb +4 -4
  65. data/spec/higher_level_api/integration/channel_close_spec.rb +51 -10
  66. data/spec/higher_level_api/integration/channel_open_spec.rb +12 -12
  67. data/spec/higher_level_api/integration/connection_recovery_spec.rb +412 -286
  68. data/spec/higher_level_api/integration/connection_spec.rb +284 -134
  69. data/spec/higher_level_api/integration/connection_stop_spec.rb +31 -19
  70. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +17 -17
  71. data/spec/higher_level_api/integration/dead_lettering_spec.rb +14 -14
  72. data/spec/higher_level_api/integration/exchange_bind_spec.rb +5 -5
  73. data/spec/higher_level_api/integration/exchange_declare_spec.rb +32 -31
  74. data/spec/higher_level_api/integration/exchange_delete_spec.rb +12 -12
  75. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +5 -5
  76. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +5 -5
  77. data/spec/higher_level_api/integration/heartbeat_spec.rb +4 -4
  78. data/spec/higher_level_api/integration/message_properties_access_spec.rb +49 -49
  79. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +2 -2
  80. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +92 -27
  81. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +19 -19
  82. data/spec/higher_level_api/integration/queue_bind_spec.rb +23 -23
  83. data/spec/higher_level_api/integration/queue_declare_spec.rb +129 -34
  84. data/spec/higher_level_api/integration/queue_delete_spec.rb +2 -2
  85. data/spec/higher_level_api/integration/queue_purge_spec.rb +5 -5
  86. data/spec/higher_level_api/integration/queue_unbind_spec.rb +6 -6
  87. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +9 -9
  88. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +10 -10
  89. data/spec/higher_level_api/integration/tls_connection_spec.rb +218 -112
  90. data/spec/higher_level_api/integration/toxiproxy_spec.rb +76 -0
  91. data/spec/higher_level_api/integration/tx_commit_spec.rb +1 -1
  92. data/spec/higher_level_api/integration/tx_rollback_spec.rb +1 -1
  93. data/spec/higher_level_api/integration/with_channel_spec.rb +2 -2
  94. data/spec/issues/issue100_spec.rb +11 -12
  95. data/spec/issues/issue141_spec.rb +13 -14
  96. data/spec/issues/issue202_spec.rb +1 -1
  97. data/spec/issues/issue224_spec.rb +5 -5
  98. data/spec/issues/issue465_spec.rb +32 -0
  99. data/spec/issues/issue549_spec.rb +30 -0
  100. data/spec/issues/issue78_spec.rb +21 -24
  101. data/spec/issues/issue83_spec.rb +5 -6
  102. data/spec/issues/issue97_spec.rb +44 -45
  103. data/spec/lower_level_api/integration/basic_cancel_spec.rb +15 -16
  104. data/spec/lower_level_api/integration/basic_consume_spec.rb +20 -21
  105. data/spec/spec_helper.rb +2 -19
  106. data/spec/stress/channel_close_stress_spec.rb +3 -3
  107. data/spec/stress/channel_open_stress_spec.rb +4 -4
  108. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +7 -7
  109. data/spec/stress/concurrent_consumers_stress_spec.rb +18 -16
  110. data/spec/stress/concurrent_publishers_stress_spec.rb +16 -19
  111. data/spec/stress/connection_open_close_spec.rb +9 -9
  112. data/spec/stress/merry_go_round_spec.rb +105 -0
  113. data/spec/tls/ca_certificate.pem +27 -16
  114. data/spec/tls/ca_key.pem +52 -27
  115. data/spec/tls/client_certificate.pem +27 -16
  116. data/spec/tls/client_key.pem +49 -25
  117. data/spec/tls/generate-server-cert.sh +8 -0
  118. data/spec/tls/server-openssl.cnf +10 -0
  119. data/spec/tls/server.csr +16 -0
  120. data/spec/tls/server_certificate.pem +27 -16
  121. data/spec/tls/server_key.pem +49 -25
  122. data/spec/toxiproxy_helper.rb +28 -0
  123. data/spec/unit/bunny_spec.rb +5 -5
  124. data/spec/unit/concurrent/atomic_fixnum_spec.rb +6 -6
  125. data/spec/unit/concurrent/condition_spec.rb +8 -8
  126. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +2 -2
  127. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +16 -16
  128. data/spec/unit/exchange_recovery_spec.rb +39 -0
  129. data/spec/unit/version_delivery_tag_spec.rb +3 -3
  130. metadata +42 -35
  131. data/lib/bunny/system_timer.rb +0 -20
  132. data/spec/config/rabbitmq.config +0 -18
  133. data/spec/higher_level_api/integration/basic_recover_spec.rb +0 -18
  134. data/spec/higher_level_api/integration/confirm_select_spec.rb +0 -19
  135. data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +0 -50
  136. data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
  137. data/spec/stress/long_running_consumer_spec.rb +0 -83
  138. data/spec/tls/cacert.pem +0 -18
  139. data/spec/tls/client_cert.pem +0 -18
  140. data/spec/tls/server_cert.pem +0 -18
  141. data/spec/unit/system_timer_spec.rb +0 -10
@@ -4,10 +4,10 @@ require "spec_helper"
4
4
  unless ENV["CI"]
5
5
  describe "Message framing implementation" do
6
6
  let(:connection) do
7
- c = Bunny.new(:user => "bunny_gem",
8
- :password => "bunny_password",
9
- :vhost => "bunny_testbed",
10
- :port => ENV.fetch("RABBITMQ_PORT", 5672))
7
+ c = Bunny.new(username: "bunny_gem",
8
+ password: "bunny_password",
9
+ vhost: "bunny_testbed",
10
+ port: ENV.fetch("RABBITMQ_PORT", 5672))
11
11
  c.start
12
12
  c
13
13
  end
@@ -21,17 +21,17 @@ unless ENV["CI"]
21
21
  it "successfully frames the message" do
22
22
  ch = connection.create_channel
23
23
 
24
- q = ch.queue("", :exclusive => true)
24
+ q = ch.queue("", exclusive: true)
25
25
  x = ch.default_exchange
26
26
 
27
27
  as = ("a" * (1024 * 1024 * 4 + 28237777))
28
- x.publish(as, :routing_key => q.name, :persistent => true)
28
+ x.publish(as, routing_key: q.name, persistent: true)
29
29
 
30
30
  sleep(1)
31
- q.message_count.should == 1
31
+ expect(q.message_count).to eq 1
32
32
 
33
33
  _, _, payload = q.pop
34
- payload.bytesize.should == as.bytesize
34
+ expect(payload.bytesize).to eq as.bytesize
35
35
 
36
36
  ch.close
37
37
  end
@@ -42,17 +42,17 @@ unless ENV["CI"]
42
42
  it "successfully frames the message" do
43
43
  ch = connection.create_channel
44
44
 
45
- q = ch.queue("", :exclusive => true)
45
+ q = ch.queue("", exclusive: true)
46
46
  x = ch.default_exchange
47
47
 
48
48
  as = "кириллца, йо" * (1024 * 1024)
49
- x.publish(as, :routing_key => q.name, :persistent => true)
49
+ x.publish(as, routing_key: q.name, persistent: true)
50
50
 
51
51
  sleep(1)
52
- q.message_count.should == 1
52
+ expect(q.message_count).to eq 1
53
53
 
54
54
  _, _, payload = q.pop
55
- payload.bytesize.should == as.bytesize
55
+ expect(payload.bytesize).to eq as.bytesize
56
56
 
57
57
  ch.close
58
58
  end
@@ -64,21 +64,21 @@ unless ENV["CI"]
64
64
  it "successfully publishes the message" do
65
65
  ch = connection.create_channel
66
66
 
67
- q = ch.queue("", :exclusive => true)
67
+ q = ch.queue("", exclusive: true)
68
68
  x = ch.default_exchange
69
69
 
70
- x.publish("", :routing_key => q.name, :persistent => false, :mandatory => true)
70
+ x.publish("", routing_key: q.name, persistent: false, mandatory: true)
71
71
 
72
72
  sleep(0.5)
73
- q.message_count.should == 1
73
+ expect(q.message_count).to eq 1
74
74
 
75
75
  envelope, headers, payload = q.pop
76
76
 
77
- payload.should == ""
77
+ expect(payload).to eq ""
78
78
 
79
- headers[:content_type].should == "application/octet-stream"
80
- headers[:delivery_mode].should == 1
81
- headers[:priority].should == 0
79
+ expect(headers[:content_type]).to eq "application/octet-stream"
80
+ expect(headers[:delivery_mode]).to eq 1
81
+ expect(headers[:priority]).to eq 0
82
82
 
83
83
  ch.close
84
84
  end
@@ -2,38 +2,38 @@ require "spec_helper"
2
2
 
3
3
  describe "A client-named", Bunny::Queue do
4
4
  let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
5
+ c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
6
  c.start
7
7
  c
8
8
  end
9
9
 
10
10
  it "can be bound to a pre-declared exchange" do
11
11
  ch = connection.create_channel
12
- q = ch.queue("bunny.tests.queues.client-named#{rand}", :exclusive => true)
13
- q.should_not be_server_named
12
+ q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
13
+ expect(q).not_to be_server_named
14
14
 
15
- q.bind("amq.fanout").should == q
15
+ expect(q.bind("amq.fanout")).to eq q
16
16
 
17
17
  ch.close
18
18
  end
19
19
 
20
20
  it "can be unbound from a pre-declared exchange" do
21
21
  ch = connection.create_channel
22
- q = ch.queue("bunny.tests.queues.client-named#{rand}", :exclusive => true)
23
- q.should_not be_server_named
22
+ q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
23
+ expect(q).not_to be_server_named
24
24
 
25
25
  q.bind("amq.fanout")
26
- q.unbind("amq.fanout").should == q
26
+ expect(q.unbind("amq.fanout")).to eq q
27
27
 
28
28
  ch.close
29
29
  end
30
30
 
31
31
  it "can be bound to a custom exchange" do
32
32
  ch = connection.create_channel
33
- q = ch.queue("bunny.tests.queues.client-named#{rand}", :exclusive => true)
33
+ q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
34
34
 
35
35
  x = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
36
- q.bind(x).should == q
36
+ expect(q.bind(x)).to eq q
37
37
 
38
38
  x.delete
39
39
  ch.close
@@ -41,13 +41,13 @@ describe "A client-named", Bunny::Queue do
41
41
 
42
42
  it "can be unbound from a custom exchange" do
43
43
  ch = connection.create_channel
44
- q = ch.queue("bunny.tests.queues.client-named#{rand}", :exclusive => true)
45
- q.should_not be_server_named
44
+ q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
45
+ expect(q).not_to be_server_named
46
46
 
47
- x = ch.fanout("bunny.tests.fanout", :auto_delete => true, :durable => false)
47
+ x = ch.fanout("bunny.tests.fanout", auto_delete: true, durable: false)
48
48
 
49
49
  q.bind(x)
50
- q.unbind(x).should == q
50
+ expect(q.unbind(x)).to eq q
51
51
 
52
52
  ch.close
53
53
  end
@@ -64,31 +64,31 @@ describe "A server-named", Bunny::Queue do
64
64
 
65
65
  it "can be bound to a pre-declared exchange" do
66
66
  ch = connection.create_channel
67
- q = ch.queue("", :exclusive => true)
68
- q.should be_server_named
67
+ q = ch.queue("", exclusive: true)
68
+ expect(q).to be_server_named
69
69
 
70
- q.bind("amq.fanout").should == q
70
+ expect(q.bind("amq.fanout")).to eq q
71
71
 
72
72
  ch.close
73
73
  end
74
74
 
75
75
  it "can be unbound from a pre-declared exchange" do
76
76
  ch = connection.create_channel
77
- q = ch.queue("", :exclusive => true)
78
- q.should be_server_named
77
+ q = ch.queue("", exclusive: true)
78
+ expect(q).to be_server_named
79
79
 
80
80
  q.bind("amq.fanout")
81
- q.unbind("amq.fanout").should == q
81
+ expect(q.unbind("amq.fanout")).to eq q
82
82
 
83
83
  ch.close
84
84
  end
85
85
 
86
86
  it "can be bound to a custom exchange" do
87
87
  ch = connection.create_channel
88
- q = ch.queue("", :exclusive => true)
88
+ q = ch.queue("", exclusive: true)
89
89
 
90
90
  x = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
91
- q.bind(x).should == q
91
+ expect(q.bind(x)).to eq q
92
92
 
93
93
  x.delete
94
94
  ch.close
@@ -96,12 +96,12 @@ describe "A server-named", Bunny::Queue do
96
96
 
97
97
  it "can be bound from a custom exchange" do
98
98
  ch = connection.create_channel
99
- q = ch.queue("", :exclusive => true)
99
+ q = ch.queue("", exclusive: true)
100
100
 
101
101
  name = "bunny.tests.exchanges.fanout#{rand}"
102
102
  x = ch.fanout(name)
103
103
  q.bind(x)
104
- q.unbind(name).should == q
104
+ expect(q.unbind(name)).to eq q
105
105
 
106
106
  x.delete
107
107
  ch.close
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Bunny::Queue do
4
4
  let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
5
+ c = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
6
  c.start
7
7
  c
8
8
  end
@@ -18,7 +18,7 @@ describe Bunny::Queue do
18
18
  ch = connection.create_channel
19
19
 
20
20
  q = ch.queue(name)
21
- q.name.should == name
21
+ expect(q.name).to eq name
22
22
 
23
23
  q.delete
24
24
  ch.close
@@ -28,7 +28,7 @@ describe Bunny::Queue do
28
28
  ch = connection.create_channel
29
29
 
30
30
  q = ch.queue(name)
31
- ch.queue(name).object_id.should == q.object_id
31
+ expect(ch.queue(name).object_id).to eq q.object_id
32
32
 
33
33
  q.delete
34
34
  ch.close
@@ -36,14 +36,14 @@ describe Bunny::Queue do
36
36
  end
37
37
 
38
38
 
39
- context "when queue name is passed on as an empty string" do
39
+ context "when queue name is passed as an empty string" do
40
40
  it "uses server-assigned queue name" do
41
41
  ch = connection.create_channel
42
42
 
43
43
  q = ch.queue("")
44
- q.name.should_not be_empty
45
- q.name.should =~ /^amq.gen.+/
46
- q.should be_server_named
44
+ expect(q.name).not_to be_empty
45
+ expect(q.name).to match /^amq.gen.+/
46
+ expect(q).to be_server_named
47
47
  q.delete
48
48
 
49
49
  ch.close
@@ -51,15 +51,26 @@ describe Bunny::Queue do
51
51
  end
52
52
 
53
53
 
54
+ context "when a nil is passed for queue name" do
55
+ it "throws an error" do
56
+ ch = connection.create_channel
57
+
58
+ expect {
59
+ ch.queue(nil, durable: true, auto_delete: false)
60
+ }.to raise_error(ArgumentError)
61
+ end
62
+ end
63
+
64
+
54
65
  context "when queue is declared as durable" do
55
66
  it "declares it as durable" do
56
67
  ch = connection.create_channel
57
68
 
58
- q = ch.queue("bunny.tests.queues.durable", :durable => true)
59
- q.should be_durable
60
- q.should_not be_auto_delete
61
- q.should_not be_exclusive
62
- q.arguments.should be_nil
69
+ q = ch.queue("bunny.tests.queues.durable", durable: true)
70
+ expect(q).to be_durable
71
+ expect(q).not_to be_auto_delete
72
+ expect(q).not_to be_exclusive
73
+ expect(q.arguments).to be_nil
63
74
  q.delete
64
75
 
65
76
  ch.close
@@ -71,9 +82,9 @@ describe Bunny::Queue do
71
82
  it "declares it as exclusive" do
72
83
  ch = connection.create_channel
73
84
 
74
- q = ch.queue("bunny.tests.queues.exclusive", :exclusive => true)
75
- q.should be_exclusive
76
- q.should_not be_durable
85
+ q = ch.queue("bunny.tests.queues.exclusive", exclusive: true)
86
+ expect(q).to be_exclusive
87
+ expect(q).not_to be_durable
77
88
  q.delete
78
89
 
79
90
  ch.close
@@ -85,10 +96,10 @@ describe Bunny::Queue do
85
96
  it "declares it as auto-delete" do
86
97
  ch = connection.create_channel
87
98
 
88
- q = ch.queue("bunny.tests.queues.auto-delete", :auto_delete => true)
89
- q.should be_auto_delete
90
- q.should_not be_exclusive
91
- q.should_not be_durable
99
+ q = ch.queue("bunny.tests.queues.auto-delete", auto_delete: true)
100
+ expect(q).to be_auto_delete
101
+ expect(q).not_to be_exclusive
102
+ expect(q).not_to be_durable
92
103
  q.delete
93
104
 
94
105
  ch.close
@@ -96,18 +107,71 @@ describe Bunny::Queue do
96
107
  end
97
108
 
98
109
 
110
+ context "when queue is declared with a mismatching auto-delete property value" do
111
+ it "raises an exception" do
112
+ ch = connection.create_channel
113
+
114
+ q = ch.queue("bunny.tests.queues.auto-delete", auto_delete: true, durable: false)
115
+ expect {
116
+ # force re-declaration
117
+ ch.queue_declare(q.name, auto_delete: false, durable: false)
118
+ }.to raise_error(Bunny::PreconditionFailed)
119
+
120
+ expect(ch).to be_closed
99
121
 
100
- context "when queue is declared with a different set of attributes" do
122
+ cleanup_ch = connection.create_channel
123
+ cleanup_ch.queue_delete(q.name)
124
+ end
125
+ end
126
+
127
+ context "when queue is declared with a mismatching durable property value" do
101
128
  it "raises an exception" do
102
129
  ch = connection.create_channel
103
130
 
104
- q = ch.queue("bunny.tests.queues.auto-delete", :auto_delete => true, :durable => false)
131
+ q = ch.queue("bunny.tests.queues.durable", durable: true)
105
132
  expect {
106
133
  # force re-declaration
107
- ch.queue_declare("bunny.tests.queues.auto-delete", :auto_delete => false, :durable => true)
134
+ ch.queue_declare(q.name, durable: false)
108
135
  }.to raise_error(Bunny::PreconditionFailed)
109
136
 
110
- ch.should be_closed
137
+ expect(ch).to be_closed
138
+
139
+ cleanup_ch = connection.create_channel
140
+ cleanup_ch.queue_delete(q.name)
141
+ end
142
+ end
143
+
144
+ context "when queue is declared with a mismatching exclusive property value" do
145
+ it "raises an exception" do
146
+ ch = connection.create_channel
147
+
148
+ q = ch.queue("bunny.tests.queues.exclusive.#{rand}", exclusive: true)
149
+ # when there's an exclusivity property mismatch, a different error
150
+ # (405 RESOURCE_LOCKED) is used. This is a leaked queue exclusivity/ownership
151
+ # implementation detail that's now basically a feature. MK.
152
+ expect {
153
+ # force re-declaration
154
+ ch.queue_declare(q.name, exclusive: false)
155
+ }.to raise_error(Bunny::ResourceLocked)
156
+
157
+ expect(ch).to be_closed
158
+ end
159
+ end
160
+
161
+ context "when queue is declared with a set of mismatching values" do
162
+ it "raises an exception" do
163
+ ch = connection.create_channel
164
+
165
+ q = ch.queue("bunny.tests.queues.proprty-equivalence", auto_delete: true, durable: false)
166
+ expect {
167
+ # force re-declaration
168
+ ch.queue_declare(q.name, auto_delete: false, durable: true)
169
+ }.to raise_error(Bunny::PreconditionFailed)
170
+
171
+ expect(ch).to be_closed
172
+
173
+ cleanup_ch = connection.create_channel
174
+ cleanup_ch.queue_delete(q.name)
111
175
  end
112
176
  end
113
177
 
@@ -121,15 +185,46 @@ describe Bunny::Queue do
121
185
  it "causes all messages in it to have a TTL" do
122
186
  ch = connection.create_channel
123
187
 
124
- q = ch.queue("bunny.tests.queues.with-arguments.ttl", :arguments => args, :exclusive => true)
125
- q.arguments.should == args
188
+ q = ch.queue("bunny.tests.queues.with-arguments.ttl", arguments: args, exclusive: true)
189
+ expect(q.arguments).to eq args
126
190
 
127
191
  q.publish("xyzzy")
128
192
  sleep 0.1
129
193
 
130
- q.message_count.should == 1
194
+ expect(q.message_count).to eq 1
131
195
  sleep 1.5
132
- q.message_count.should == 0
196
+ expect(q.message_count).to eq 0
197
+
198
+ ch.close
199
+ end
200
+ end
201
+
202
+
203
+ context "when queue is declared with priorities" do
204
+ let(:args) do
205
+ {"x-max-priority" => 5}
206
+ end
207
+
208
+ it "enables priority implementation" do
209
+ c = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
210
+ c.start
211
+
212
+ ch = c.create_channel
213
+ ch.confirm_select
214
+
215
+ q = ch.queue("bunny.tests.queues.with-arguments.priority #{rand}", arguments: args, exclusive: true)
216
+ expect(q.arguments).to eq args
217
+
218
+ q.publish("xyzzy")
219
+ ch.wait_for_confirms
220
+ sleep 0.1
221
+
222
+ # this test only does sanity checking,
223
+ # without trying to actually test prioritisation.
224
+ #
225
+ # added to guard against issues such as
226
+ # https://github.com/rabbitmq/rabbitmq-server/issues/488
227
+ expect(q.message_count).to eq 1
133
228
 
134
229
  ch.close
135
230
  end
@@ -140,15 +235,15 @@ describe Bunny::Queue do
140
235
  context "when a queue exists" do
141
236
  it "returns true" do
142
237
  ch = connection.create_channel
143
- q = ch.queue("", :exlusive => true)
238
+ q = ch.queue("", exlusive: true)
144
239
 
145
- connection.queue_exists?(q.name).should be_true
240
+ expect(connection.queue_exists?(q.name)).to eq true
146
241
  end
147
242
  end
148
243
 
149
244
  context "when a queue DOES NOT exist" do
150
245
  it "returns false" do
151
- connection.queue_exists?("suf89u9a4jo3ndnakls##{Time.now.to_i}").should be_false
246
+ expect(connection.queue_exists?("suf89u9a4jo3ndnakls##{Time.now.to_i}")).to eq false
152
247
  end
153
248
  end
154
249
  end
@@ -168,19 +263,19 @@ describe Bunny::Queue do
168
263
  it "causes the queue to be bounded" do
169
264
  ch = connection.create_channel
170
265
 
171
- q = ch.queue("bunny.tests.queues.with-arguments.max-length", :arguments => args, :exclusive => true)
172
- q.arguments.should == args
266
+ q = ch.queue("bunny.tests.queues.with-arguments.max-length", arguments: args, exclusive: true)
267
+ expect(q.arguments).to eq args
173
268
 
174
269
  (n * 10).times do
175
270
  q.publish("xyzzy")
176
271
  end
177
272
 
178
- q.message_count.should == n
273
+ expect(q.message_count).to eq n
179
274
  (n * 5).times do
180
275
  q.publish("xyzzy")
181
276
  end
182
277
 
183
- q.message_count.should == n
278
+ expect(q.message_count).to eq n
184
279
  q.delete
185
280
 
186
281
  ch.close