bunny 1.3.0 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +18 -0
  3. data/.gitignore +7 -1
  4. data/.rspec +1 -3
  5. data/.travis.yml +21 -14
  6. data/CONTRIBUTING.md +132 -0
  7. data/ChangeLog.md +887 -1
  8. data/Gemfile +13 -13
  9. data/LICENSE +1 -1
  10. data/README.md +46 -60
  11. data/Rakefile +54 -0
  12. data/bunny.gemspec +5 -11
  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/extensions/basic_nack.rb +1 -1
  30. data/examples/guides/extensions/dead_letter_exchange.rb +1 -1
  31. data/examples/guides/getting_started/hello_world.rb +2 -0
  32. data/examples/guides/getting_started/weathr.rb +2 -0
  33. data/examples/guides/queues/one_off_consumer.rb +2 -0
  34. data/examples/guides/queues/redeliveries.rb +4 -2
  35. data/lib/bunny.rb +8 -4
  36. data/lib/bunny/channel.rb +268 -153
  37. data/lib/bunny/channel_id_allocator.rb +6 -4
  38. data/lib/bunny/concurrent/continuation_queue.rb +34 -13
  39. data/lib/bunny/consumer_work_pool.rb +34 -6
  40. data/lib/bunny/cruby/socket.rb +48 -21
  41. data/lib/bunny/cruby/ssl_socket.rb +65 -4
  42. data/lib/bunny/exceptions.rb +25 -4
  43. data/lib/bunny/exchange.rb +24 -28
  44. data/lib/bunny/get_response.rb +1 -1
  45. data/lib/bunny/heartbeat_sender.rb +3 -2
  46. data/lib/bunny/jruby/socket.rb +23 -6
  47. data/lib/bunny/jruby/ssl_socket.rb +5 -0
  48. data/lib/bunny/queue.rb +31 -22
  49. data/lib/bunny/reader_loop.rb +31 -18
  50. data/lib/bunny/session.rb +448 -159
  51. data/lib/bunny/test_kit.rb +14 -0
  52. data/lib/bunny/timeout.rb +1 -12
  53. data/lib/bunny/transport.rb +205 -98
  54. data/lib/bunny/version.rb +1 -1
  55. data/repl +1 -1
  56. data/spec/config/enabled_plugins +1 -0
  57. data/spec/config/rabbitmq.conf +13 -0
  58. data/spec/higher_level_api/integration/basic_ack_spec.rb +175 -16
  59. data/spec/higher_level_api/integration/basic_cancel_spec.rb +77 -11
  60. data/spec/higher_level_api/integration/basic_consume_spec.rb +60 -55
  61. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +6 -6
  62. data/spec/higher_level_api/integration/basic_get_spec.rb +31 -7
  63. data/spec/higher_level_api/integration/basic_nack_spec.rb +22 -19
  64. data/spec/higher_level_api/integration/basic_publish_spec.rb +11 -100
  65. data/spec/higher_level_api/integration/basic_qos_spec.rb +32 -4
  66. data/spec/higher_level_api/integration/basic_reject_spec.rb +94 -16
  67. data/spec/higher_level_api/integration/basic_return_spec.rb +4 -4
  68. data/spec/higher_level_api/integration/channel_close_spec.rb +51 -10
  69. data/spec/higher_level_api/integration/channel_open_spec.rb +12 -12
  70. data/spec/higher_level_api/integration/connection_recovery_spec.rb +424 -221
  71. data/spec/higher_level_api/integration/connection_spec.rb +300 -126
  72. data/spec/higher_level_api/integration/connection_stop_spec.rb +31 -19
  73. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +17 -17
  74. data/spec/higher_level_api/integration/dead_lettering_spec.rb +34 -11
  75. data/spec/higher_level_api/integration/exchange_bind_spec.rb +5 -5
  76. data/spec/higher_level_api/integration/exchange_declare_spec.rb +32 -31
  77. data/spec/higher_level_api/integration/exchange_delete_spec.rb +12 -12
  78. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +5 -5
  79. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +5 -5
  80. data/spec/higher_level_api/integration/heartbeat_spec.rb +26 -8
  81. data/spec/higher_level_api/integration/message_properties_access_spec.rb +49 -49
  82. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +2 -2
  83. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +156 -42
  84. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +19 -19
  85. data/spec/higher_level_api/integration/queue_bind_spec.rb +23 -23
  86. data/spec/higher_level_api/integration/queue_declare_spec.rb +129 -34
  87. data/spec/higher_level_api/integration/queue_delete_spec.rb +2 -2
  88. data/spec/higher_level_api/integration/queue_purge_spec.rb +5 -5
  89. data/spec/higher_level_api/integration/queue_unbind_spec.rb +6 -6
  90. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +9 -9
  91. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +10 -10
  92. data/spec/higher_level_api/integration/tls_connection_spec.rb +224 -89
  93. data/spec/higher_level_api/integration/toxiproxy_spec.rb +76 -0
  94. data/spec/higher_level_api/integration/tx_commit_spec.rb +1 -1
  95. data/spec/higher_level_api/integration/tx_rollback_spec.rb +1 -1
  96. data/spec/higher_level_api/integration/with_channel_spec.rb +2 -2
  97. data/spec/issues/issue100_spec.rb +11 -11
  98. data/spec/issues/issue141_spec.rb +13 -14
  99. data/spec/issues/issue202_spec.rb +1 -1
  100. data/spec/issues/issue224_spec.rb +40 -0
  101. data/spec/issues/issue465_spec.rb +32 -0
  102. data/spec/issues/issue549_spec.rb +30 -0
  103. data/spec/issues/issue78_spec.rb +21 -24
  104. data/spec/issues/issue83_spec.rb +5 -6
  105. data/spec/issues/issue97_spec.rb +44 -45
  106. data/spec/lower_level_api/integration/basic_cancel_spec.rb +15 -16
  107. data/spec/lower_level_api/integration/basic_consume_spec.rb +20 -21
  108. data/spec/spec_helper.rb +8 -26
  109. data/spec/stress/channel_close_stress_spec.rb +64 -0
  110. data/spec/stress/channel_open_stress_spec.rb +15 -9
  111. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +7 -7
  112. data/spec/stress/concurrent_consumers_stress_spec.rb +18 -16
  113. data/spec/stress/concurrent_publishers_stress_spec.rb +16 -19
  114. data/spec/stress/connection_open_close_spec.rb +9 -9
  115. data/spec/stress/merry_go_round_spec.rb +105 -0
  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_key.pem +49 -25
  121. data/spec/toxiproxy_helper.rb +28 -0
  122. data/spec/unit/bunny_spec.rb +5 -5
  123. data/spec/unit/concurrent/atomic_fixnum_spec.rb +6 -6
  124. data/spec/unit/concurrent/condition_spec.rb +8 -8
  125. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +2 -2
  126. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +16 -16
  127. data/spec/unit/exchange_recovery_spec.rb +39 -0
  128. data/spec/unit/version_delivery_tag_spec.rb +3 -3
  129. metadata +65 -47
  130. data/.ruby-version +0 -1
  131. data/lib/bunny/compatibility.rb +0 -24
  132. data/lib/bunny/system_timer.rb +0 -20
  133. data/spec/compatibility/queue_declare_spec.rb +0 -44
  134. data/spec/compatibility/queue_declare_with_default_channel_spec.rb +0 -33
  135. data/spec/higher_level_api/integration/basic_recover_spec.rb +0 -18
  136. data/spec/higher_level_api/integration/confirm_select_spec.rb +0 -19
  137. data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +0 -50
  138. data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
  139. data/spec/stress/long_running_consumer_spec.rb +0 -83
  140. data/spec/tls/cacert.pem +0 -18
  141. data/spec/tls/client_cert.pem +0 -18
  142. data/spec/tls/server_cert.pem +0 -18
  143. data/spec/unit/system_timer_spec.rb +0 -10
@@ -3,7 +3,7 @@ require "set"
3
3
 
4
4
  describe Bunny::Queue, "#subscribe_with" do
5
5
  let(:connection) do
6
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
+ c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
7
7
  c.start
8
8
  c
9
9
  end
@@ -32,23 +32,23 @@ describe Bunny::Queue, "#subscribe_with" do
32
32
  it "requeues messages on channel closure" do
33
33
  ch1 = connection.create_channel
34
34
  ch2 = connection.create_channel
35
- q1 = ch1.queue("bunny.tests.consumer_object1", :exclusive => true)
36
- q2 = ch2.queue("bunny.tests.consumer_object1", :exclusive => true)
35
+ q1 = ch1.queue("bunny.tests.consumer_object1", exclusive: true)
36
+ q2 = ch2.queue("bunny.tests.consumer_object1", exclusive: true)
37
37
  ec = ExampleConsumer.new(ch1, q1, "", false)
38
38
  x = ch2.default_exchange
39
39
 
40
40
  t = Thread.new do
41
41
  50.times do
42
- x.publish("hello", :routing_key => q2.name)
42
+ x.publish("hello", routing_key: q2.name)
43
43
  end
44
44
  end
45
45
  t.abort_on_exception = true
46
46
 
47
- q1.subscribe_with(ec, :ack => true)
47
+ q1.subscribe_with(ec, manual_ack: true)
48
48
  sleep 2
49
49
  ch1.close
50
50
 
51
- q2.message_count.should == 50
51
+ expect(q2.message_count).to eq 50
52
52
  end
53
53
  end
54
54
  end
@@ -2,8 +2,8 @@ require "spec_helper"
2
2
 
3
3
  describe Bunny::Queue, "#pop" do
4
4
  let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed",
6
- :automatically_recover => false)
5
+ c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
6
+ automatically_recover: false)
7
7
  c.start
8
8
  c
9
9
  end
@@ -16,11 +16,11 @@ describe Bunny::Queue, "#pop" do
16
16
  it "fetches a messages which is automatically acknowledged" do
17
17
  ch = connection.create_channel
18
18
 
19
- q = ch.queue("", :exclusive => true)
19
+ q = ch.queue("", exclusive: true)
20
20
  x = ch.default_exchange
21
21
 
22
22
  msg = "xyzzy"
23
- x.publish(msg, :routing_key => q.name)
23
+ x.publish(msg, routing_key: q.name)
24
24
 
25
25
  sleep(0.5)
26
26
  get_ok, properties, content = q.pop
@@ -30,7 +30,7 @@ describe Bunny::Queue, "#pop" do
30
30
  expect(get_ok.routing_key).to eq(q.name)
31
31
  expect(get_ok.delivery_tag).to be_kind_of(Bunny::VersionedDeliveryTag)
32
32
  expect(content).to eq(msg)
33
- q.message_count.should == 0
33
+ expect(q.message_count).to eq 0
34
34
 
35
35
  ch.close
36
36
  end
@@ -41,16 +41,40 @@ describe Bunny::Queue, "#pop" do
41
41
  it "returns an empty response" do
42
42
  ch = connection.create_channel
43
43
 
44
- q = ch.queue("", :exclusive => true)
44
+ q = ch.queue("", exclusive: true)
45
45
  q.purge
46
46
 
47
47
  get_empty, properties, content = q.pop
48
48
  expect(get_empty).to eq(nil)
49
49
  expect(properties).to eq(nil)
50
50
  expect(content).to eq(nil)
51
- q.message_count.should == 0
51
+ expect(q.message_count).to eq 0
52
52
 
53
53
  ch.close
54
54
  end
55
55
  end
56
56
  end
57
+
58
+
59
+ describe Bunny::Channel, "#basic_get" do
60
+ let(:connection) do
61
+ c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
62
+ automatically_recover: false, continuation_timeout: 3000)
63
+ c.start
64
+ c
65
+ end
66
+
67
+ after :each do
68
+ connection.close if connection.open?
69
+ end
70
+
71
+ context "with a non-existent queue" do
72
+ it "throws a NOT_FOUND" do
73
+ ch = connection.create_channel
74
+
75
+ expect do
76
+ ch.basic_get "non_existent_#{rand.to_s}"
77
+ end.to raise_error(Bunny::NotFound)
78
+ end
79
+ end
80
+ end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Bunny::Channel, "#nack" 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
@@ -17,39 +17,42 @@ describe Bunny::Channel, "#nack" do
17
17
 
18
18
  context "with requeue = false" do
19
19
  it "rejects a message" do
20
- q = subject.queue("bunny.basic.nack.with-requeue-false", :exclusive => true)
20
+ q = subject.queue("bunny.basic.nack.with-requeue-false", exclusive: true)
21
21
  x = subject.default_exchange
22
22
 
23
- x.publish("bunneth", :routing_key => q.name)
23
+ x.publish("bunneth", routing_key: q.name)
24
24
  sleep(0.5)
25
- q.message_count.should == 1
26
- delivery_info, _, content = q.pop(:ack => true)
25
+ expect(q.message_count).to eq 1
26
+ delivery_info, _, content = q.pop(manual_ack: true)
27
27
 
28
28
  subject.nack(delivery_info.delivery_tag, false, false)
29
29
  sleep(0.5)
30
- q.message_count.should == 0
31
-
32
30
  subject.close
31
+
32
+ ch = connection.create_channel
33
+ q = ch.queue("bunny.basic.nack.with-requeue-false", exclusive: true)
34
+ expect(q.message_count).to eq 0
35
+ ch.close
33
36
  end
34
37
  end
35
38
 
36
39
  context "with multiple = true" do
37
40
  it "rejects multiple messages" do
38
- q = subject.queue("bunny.basic.nack.with-requeue-true-multi-true", :exclusive => true)
41
+ q = subject.queue("bunny.basic.nack.with-requeue-true-multi-true", exclusive: true)
39
42
  x = subject.default_exchange
40
43
 
41
44
  3.times do
42
- x.publish("bunneth", :routing_key => q.name)
45
+ x.publish("bunneth", routing_key: q.name)
43
46
  end
44
47
  sleep(0.5)
45
- q.message_count.should == 3
46
- _, _, _ = q.pop(:ack => true)
47
- _, _, _ = q.pop(:ack => true)
48
- delivery_info, _, content = q.pop(:ack => true)
48
+ expect(q.message_count).to eq 3
49
+ _, _, _ = q.pop(manual_ack: true)
50
+ _, _, _ = q.pop(manual_ack: true)
51
+ delivery_info, _, content = q.pop(manual_ack: true)
49
52
 
50
53
  subject.nack(delivery_info.delivery_tag, true, true)
51
54
  sleep(0.5)
52
- q.message_count.should == 3
55
+ expect(q.message_count).to eq 3
53
56
 
54
57
  subject.close
55
58
  end
@@ -58,13 +61,13 @@ q = subject.queue("bunny.basic.nack.with-requeue-true-multi-true", :exclusive =>
58
61
 
59
62
  context "with an invalid (random) delivery tag" do
60
63
  it "causes a channel-level error" do
61
- q = subject.queue("bunny.basic.nack.unknown-delivery-tag", :exclusive => true)
64
+ q = subject.queue("bunny.basic.nack.unknown-delivery-tag", exclusive: true)
62
65
  x = subject.default_exchange
63
66
 
64
- x.publish("bunneth", :routing_key => q.name)
67
+ x.publish("bunneth", routing_key: q.name)
65
68
  sleep(0.25)
66
- q.message_count.should == 1
67
- _, _, content = q.pop(:ack => true)
69
+ expect(q.message_count).to eq 1
70
+ _, _, content = q.pop(manual_ack: true)
68
71
 
69
72
  subject.on_error do |ch, channel_close|
70
73
  @channel_close = channel_close
@@ -73,7 +76,7 @@ q = subject.queue("bunny.basic.nack.with-requeue-true-multi-true", :exclusive =>
73
76
 
74
77
  sleep 0.5
75
78
 
76
- @channel_close.reply_text.should == "PRECONDITION_FAILED - unknown delivery tag 82"
79
+ expect(@channel_close.reply_text).to eq "PRECONDITION_FAILED - unknown delivery tag 82"
77
80
  end
78
81
  end
79
82
  end
@@ -1,97 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
- if RUBY_VERSION <= "1.9"
4
- describe "Publishing a message to the default exchange" do
5
- let(:connection) do
6
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
7
- c.start
8
- c
9
- end
10
-
11
- after :each do
12
- connection.close if connection.open?
13
- end
14
-
15
-
16
- context "with all default delivery and message properties" do
17
- it "routes messages to a queue with the same name as the routing key" do
18
- connection.should be_threaded
19
- ch = connection.create_channel
20
-
21
- q = ch.queue("", :exclusive => true)
22
- x = ch.default_exchange
23
-
24
- x.publish("xyzzy", :routing_key => q.name).
25
- publish("xyzzy", :routing_key => q.name).
26
- publish("xyzzy", :routing_key => q.name).
27
- publish("xyzzy", :routing_key => q.name)
28
-
29
- sleep(1)
30
- q.message_count.should == 4
31
-
32
- ch.close
33
- end
34
- end
35
-
36
-
37
- context "with all default delivery and message properties" do
38
- it "routes the messages and preserves all the metadata" do
39
- connection.should be_threaded
40
- ch = connection.create_channel
41
-
42
- q = ch.queue("", :exclusive => true)
43
- x = ch.default_exchange
44
-
45
- x.publish("xyzzy", :routing_key => q.name, :persistent => true)
46
-
47
- sleep(1)
48
- q.message_count.should == 1
49
-
50
- envelope, headers, payload = q.pop
51
-
52
- payload.should == "xyzzy"
53
-
54
- headers[:content_type].should == "application/octet-stream"
55
- headers[:delivery_mode].should == 2
56
- headers[:priority].should == 0
57
-
58
- ch.close
59
- end
60
- end
61
-
62
-
63
- context "with all default delivery and message properties on a single-threaded connection" do
64
- let(:connection) do
65
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :threaded => false)
66
- c.start
67
- c
68
- end
69
-
70
- it "routes messages to a queue with the same name as the routing key" do
71
- connection.should_not be_threaded
72
- ch = connection.create_channel
73
-
74
- q = ch.queue("", :exclusive => true)
75
- x = ch.default_exchange
76
-
77
- x.publish("xyzzy", :routing_key => q.name).
78
- publish("xyzzy", :routing_key => q.name).
79
- publish("xyzzy", :routing_key => q.name).
80
- publish("xyzzy", :routing_key => q.name)
81
-
82
- sleep(1)
83
- q.message_count.should == 4
84
-
85
- ch.close
86
- end
87
- end
88
- end
89
- end
90
-
91
-
92
3
  describe "Published message" do
93
4
  let(:connection) do
94
- 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")
95
6
  c.start
96
7
  c
97
8
  end
@@ -104,19 +15,19 @@ describe "Published message" do
104
15
  it "routes the messages" do
105
16
  ch = connection.create_channel
106
17
 
107
- q = ch.queue("", :exclusive => true)
18
+ q = ch.queue("", exclusive: true)
108
19
  x = ch.fanout("amq.fanout")
109
20
  q.bind(x)
110
21
 
111
22
  rk = "a" * 254
112
- x.publish("xyzzy", :routing_key => rk, :persistent => true)
23
+ x.publish("xyzzy", routing_key: rk, persistent: true)
113
24
 
114
25
  sleep(1)
115
- q.message_count.should == 1
26
+ expect(q.message_count).to eq 1
116
27
 
117
28
  _, _, payload = q.pop
118
29
 
119
- payload.should == "xyzzy"
30
+ expect(payload).to eq "xyzzy"
120
31
 
121
32
  ch.close
122
33
  end
@@ -126,19 +37,19 @@ describe "Published message" do
126
37
  it "routes the messages" do
127
38
  ch = connection.create_channel
128
39
 
129
- q = ch.queue("", :exclusive => true)
40
+ q = ch.queue("", exclusive: true)
130
41
  x = ch.fanout("amq.fanout")
131
42
  q.bind(x)
132
43
 
133
44
  rk = "a" * 255
134
- x.publish("xyzzy", :routing_key => rk, :persistent => true)
45
+ x.publish("xyzzy", routing_key: rk, persistent: true)
135
46
 
136
47
  sleep(1)
137
- q.message_count.should == 1
48
+ expect(q.message_count).to eq 1
138
49
 
139
50
  _, _, payload = q.pop
140
51
 
141
- payload.should == "xyzzy"
52
+ expect(payload).to eq "xyzzy"
142
53
 
143
54
  ch.close
144
55
  end
@@ -148,13 +59,13 @@ describe "Published message" do
148
59
  it "fails with a connection exception" do
149
60
  ch = connection.create_channel
150
61
 
151
- q = ch.queue("", :exclusive => true)
62
+ q = ch.queue("", exclusive: true)
152
63
  x = ch.fanout("amq.fanout")
153
64
  q.bind(x)
154
65
 
155
66
  rk = "a" * 256
156
67
  expect do
157
- x.publish("xyzzy", :routing_key => rk, :persistent => true)
68
+ x.publish("xyzzy", routing_key: rk, persistent: true)
158
69
  end.to raise_error(ArgumentError)
159
70
 
160
71
  ch.close
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Bunny::Channel, "#prefetch" 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
@@ -11,10 +11,35 @@ describe Bunny::Channel, "#prefetch" do
11
11
  connection.close
12
12
  end
13
13
 
14
- context "with a positive integer" do
14
+ context "with a positive integer < 65535" do
15
15
  it "sets that prefetch level via basic.qos" do
16
16
  ch = connection.create_channel
17
- ch.prefetch(10).should be_instance_of(AMQ::Protocol::Basic::QosOk)
17
+ expect(ch.prefetch_count).not_to eq 10
18
+ expect(ch.prefetch_global).to be_nil
19
+ expect(ch.prefetch(10)).to be_instance_of(AMQ::Protocol::Basic::QosOk)
20
+ expect(ch.prefetch_count).to eq 10
21
+ expect(ch.prefetch_global).to be false
22
+ end
23
+
24
+ it "sets that prefetch global via basic.qos" do
25
+ ch = connection.create_channel
26
+ expect(ch.prefetch_count).not_to eq 42
27
+ expect(ch.prefetch_global).to be_nil
28
+ expect(ch.prefetch(42, true)).to be_instance_of(AMQ::Protocol::Basic::QosOk)
29
+ expect(ch.prefetch_count).to eq 42
30
+ expect(ch.prefetch_global).to be true
31
+ end
32
+ end
33
+
34
+ context "with a positive integer > 65535" do
35
+ it "raises an ArgumentError" do
36
+ ch = connection.create_channel
37
+ expect {
38
+ ch.prefetch(100_000)
39
+ }.to raise_error(
40
+ ArgumentError,
41
+ "prefetch count must be no greater than #{Bunny::Channel::MAX_PREFETCH_COUNT}, given: 100000"
42
+ )
18
43
  end
19
44
  end
20
45
 
@@ -23,7 +48,10 @@ describe Bunny::Channel, "#prefetch" do
23
48
  ch = connection.create_channel
24
49
  expect {
25
50
  ch.prefetch(-2)
26
- }.to raise_error(ArgumentError)
51
+ }.to raise_error(
52
+ ArgumentError,
53
+ "prefetch count must be a positive integer, given: -2"
54
+ )
27
55
  end
28
56
  end
29
57
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Bunny::Channel, "#reject" 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
@@ -14,17 +14,17 @@ describe Bunny::Channel, "#reject" do
14
14
  context "with requeue = true" do
15
15
  it "requeues a message" do
16
16
  ch = connection.create_channel
17
- q = ch.queue("bunny.basic.reject.manual-acks", :exclusive => true)
17
+ q = ch.queue("bunny.basic.reject.manual-acks", exclusive: true)
18
18
  x = ch.default_exchange
19
19
 
20
- x.publish("bunneth", :routing_key => q.name)
20
+ x.publish("bunneth", routing_key: q.name)
21
21
  sleep(0.5)
22
- q.message_count.should == 1
23
- delivery_info, _, _ = q.pop(:ack => true)
22
+ expect(q.message_count).to eq 1
23
+ delivery_info, _, _ = q.pop(manual_ack: true)
24
24
 
25
25
  ch.reject(delivery_info.delivery_tag, true)
26
26
  sleep(0.5)
27
- q.message_count.should == 1
27
+ expect(q.message_count).to eq 1
28
28
 
29
29
  ch.close
30
30
  end
@@ -33,18 +33,21 @@ describe Bunny::Channel, "#reject" do
33
33
  context "with requeue = false" do
34
34
  it "rejects a message" do
35
35
  ch = connection.create_channel
36
- q = ch.queue("bunny.basic.reject.with-requeue-false", :exclusive => true)
36
+ q = ch.queue("bunny.basic.reject.with-requeue-false", exclusive: true)
37
37
  x = ch.default_exchange
38
38
 
39
- x.publish("bunneth", :routing_key => q.name)
39
+ x.publish("bunneth", routing_key: q.name)
40
40
  sleep(0.5)
41
- q.message_count.should == 1
42
- delivery_info, _, _ = q.pop(:ack => true)
41
+ expect(q.message_count).to eq 1
42
+ delivery_info, _, _ = q.pop(manual_ack: true)
43
43
 
44
44
  ch.reject(delivery_info.delivery_tag, false)
45
45
  sleep(0.5)
46
- q.message_count.should == 0
46
+ ch.close
47
47
 
48
+ ch = connection.create_channel
49
+ q = ch.queue("bunny.basic.reject.with-requeue-false", exclusive: true)
50
+ expect(q.message_count).to eq 0
48
51
  ch.close
49
52
  end
50
53
  end
@@ -53,13 +56,13 @@ describe Bunny::Channel, "#reject" do
53
56
  context "with an invalid (random) delivery tag" do
54
57
  it "causes a channel-level error" do
55
58
  ch = connection.create_channel
56
- q = ch.queue("bunny.basic.reject.unknown-delivery-tag", :exclusive => true)
59
+ q = ch.queue("bunny.basic.reject.unknown-delivery-tag", exclusive: true)
57
60
  x = ch.default_exchange
58
61
 
59
- x.publish("bunneth", :routing_key => q.name)
62
+ x.publish("bunneth", routing_key: q.name)
60
63
  sleep(0.25)
61
- q.message_count.should == 1
62
- _, _, content = q.pop(:ack => true)
64
+ expect(q.message_count).to eq 1
65
+ _, _, content = q.pop(manual_ack: true)
63
66
 
64
67
  ch.on_error do |ch, channel_close|
65
68
  @channel_close = channel_close
@@ -68,7 +71,82 @@ describe Bunny::Channel, "#reject" do
68
71
 
69
72
  sleep 0.5
70
73
 
71
- @channel_close.reply_text.should == "PRECONDITION_FAILED - unknown delivery tag 82"
74
+ expect(@channel_close.reply_text).to eq "PRECONDITION_FAILED - unknown delivery tag 82"
75
+ end
76
+ end
77
+ end
78
+
79
+ describe Bunny::Channel, "#basic_reject" do
80
+ let(:connection) do
81
+ c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
82
+ c.start
83
+ c
84
+ end
85
+
86
+ after :each do
87
+ connection.close if connection.open?
88
+ end
89
+
90
+ context "with requeue = true" do
91
+ it "requeues a message" do
92
+ ch = connection.create_channel
93
+ q = ch.queue("bunny.basic.reject.manual-acks", exclusive: true)
94
+ x = ch.default_exchange
95
+
96
+ x.publish("bunneth", routing_key: q.name)
97
+ sleep(0.5)
98
+ expect(q.message_count).to eq 1
99
+ delivery_info, _, _ = q.pop(manual_ack: true)
100
+
101
+ ch.basic_reject(delivery_info.delivery_tag.to_i, true)
102
+ sleep(0.5)
103
+ expect(q.message_count).to eq 1
104
+
105
+ ch.close
106
+ end
107
+ end
108
+
109
+ context "with requeue = false" do
110
+ it "rejects a message" do
111
+ ch = connection.create_channel
112
+ q = ch.queue("bunny.basic.reject.with-requeue-false", exclusive: true)
113
+ x = ch.default_exchange
114
+
115
+ x.publish("bunneth", routing_key: q.name)
116
+ sleep(0.5)
117
+ expect(q.message_count).to eq 1
118
+ delivery_info, _, _ = q.pop(manual_ack: true)
119
+
120
+ ch.basic_reject(delivery_info.delivery_tag.to_i, false)
121
+ sleep(0.5)
122
+ ch.close
123
+
124
+ ch = connection.create_channel
125
+ q = ch.queue("bunny.basic.reject.with-requeue-false", exclusive: true)
126
+ expect(q.message_count).to eq 0
127
+ ch.close
128
+ end
129
+ end
130
+
131
+ context "with requeue = default" do
132
+ it "rejects a message" do
133
+ ch = connection.create_channel
134
+ q = ch.queue("bunny.basic.reject.with-requeue-false", exclusive: true)
135
+ x = ch.default_exchange
136
+
137
+ x.publish("bunneth", routing_key: q.name)
138
+ sleep(0.5)
139
+ expect(q.message_count).to eq 1
140
+ delivery_info, _, _ = q.pop(manual_ack: true)
141
+
142
+ ch.basic_reject(delivery_info.delivery_tag.to_i)
143
+ sleep(0.5)
144
+ ch.close
145
+
146
+ ch = connection.create_channel
147
+ q = ch.queue("bunny.basic.reject.with-requeue-false", exclusive: true)
148
+ expect(q.message_count).to eq 0
149
+ ch.close
72
150
  end
73
151
  end
74
152
  end