bunny 2.14.2 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +56 -39
  3. data/lib/bunny/channel.rb +89 -13
  4. data/lib/bunny/consumer.rb +2 -2
  5. data/lib/bunny/consumer_work_pool.rb +1 -1
  6. data/lib/bunny/cruby/socket.rb +3 -0
  7. data/lib/bunny/delivery_info.rb +1 -1
  8. data/lib/bunny/queue.rb +36 -5
  9. data/lib/bunny/reader_loop.rb +21 -13
  10. data/lib/bunny/session.rb +83 -25
  11. data/lib/bunny/transport.rb +49 -12
  12. data/lib/bunny/version.rb +1 -1
  13. data/lib/bunny.rb +45 -4
  14. metadata +37 -235
  15. data/.github/ISSUE_TEMPLATE.md +0 -18
  16. data/.gitignore +0 -28
  17. data/.rspec +0 -1
  18. data/.travis.yml +0 -31
  19. data/.yardopts +0 -8
  20. data/CONTRIBUTING.md +0 -132
  21. data/ChangeLog.md +0 -2072
  22. data/Gemfile +0 -55
  23. data/LICENSE +0 -21
  24. data/Rakefile +0 -54
  25. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  26. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  27. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  28. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  29. data/benchmarks/channel_open.rb +0 -28
  30. data/benchmarks/mutex_and_monitor.rb +0 -42
  31. data/benchmarks/queue_declare.rb +0 -29
  32. data/benchmarks/queue_declare_and_bind.rb +0 -29
  33. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  34. data/benchmarks/synchronized_sorted_set.rb +0 -53
  35. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  36. data/bunny.gemspec +0 -34
  37. data/docker/Dockerfile +0 -20
  38. data/docker/apt/preferences.d/erlang +0 -3
  39. data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
  40. data/docker/docker-entrypoint.sh +0 -26
  41. data/docker/rabbitmq.conf +0 -29
  42. data/docker-compose.yml +0 -28
  43. data/examples/connection/authentication_failure.rb +0 -16
  44. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  45. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  46. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  47. data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
  48. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  49. data/examples/connection/channel_level_exception.rb +0 -27
  50. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  51. data/examples/connection/heartbeat.rb +0 -17
  52. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  53. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  54. data/examples/connection/unknown_host.rb +0 -16
  55. data/examples/consumers/high_and_low_priority.rb +0 -50
  56. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  57. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  58. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  59. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  60. data/examples/guides/extensions/alternate_exchange.rb +0 -30
  61. data/examples/guides/extensions/basic_nack.rb +0 -33
  62. data/examples/guides/extensions/connection_blocked.rb +0 -35
  63. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  64. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  65. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  66. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  67. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  68. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  69. data/examples/guides/extensions/queue_lease.rb +0 -26
  70. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  71. data/examples/guides/getting_started/blabbr.rb +0 -27
  72. data/examples/guides/getting_started/hello_world.rb +0 -22
  73. data/examples/guides/getting_started/weathr.rb +0 -49
  74. data/examples/guides/queues/one_off_consumer.rb +0 -25
  75. data/examples/guides/queues/redeliveries.rb +0 -81
  76. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  77. data/repl +0 -3
  78. data/spec/config/enabled_plugins +0 -1
  79. data/spec/config/rabbitmq.conf +0 -13
  80. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
  81. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
  82. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -349
  83. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  84. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
  85. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
  86. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
  87. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
  88. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
  89. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  90. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -66
  91. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  92. data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -483
  93. data/spec/higher_level_api/integration/connection_spec.rb +0 -563
  94. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
  95. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  96. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
  97. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  98. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
  99. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  100. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  101. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  102. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
  103. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  104. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  105. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
  106. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
  107. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  108. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -285
  109. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  110. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  111. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  112. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  113. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  114. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -250
  115. data/spec/higher_level_api/integration/toxiproxy_spec.rb +0 -76
  116. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  117. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  118. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  119. data/spec/issues/issue100_spec.rb +0 -42
  120. data/spec/issues/issue141_spec.rb +0 -43
  121. data/spec/issues/issue202_spec.rb +0 -15
  122. data/spec/issues/issue224_spec.rb +0 -40
  123. data/spec/issues/issue465_spec.rb +0 -32
  124. data/spec/issues/issue549_spec.rb +0 -30
  125. data/spec/issues/issue78_spec.rb +0 -72
  126. data/spec/issues/issue83_spec.rb +0 -30
  127. data/spec/issues/issue97_attachment.json +0 -1
  128. data/spec/issues/issue97_spec.rb +0 -175
  129. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
  130. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
  131. data/spec/spec_helper.rb +0 -47
  132. data/spec/stress/channel_close_stress_spec.rb +0 -64
  133. data/spec/stress/channel_open_stress_spec.rb +0 -84
  134. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  135. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
  136. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
  137. data/spec/stress/connection_open_close_spec.rb +0 -52
  138. data/spec/stress/merry_go_round_spec.rb +0 -105
  139. data/spec/tls/ca_certificate.pem +0 -29
  140. data/spec/tls/ca_key.pem +0 -52
  141. data/spec/tls/client_certificate.pem +0 -29
  142. data/spec/tls/client_key.pem +0 -51
  143. data/spec/tls/generate-server-cert.sh +0 -8
  144. data/spec/tls/server-openssl.cnf +0 -10
  145. data/spec/tls/server.csr +0 -16
  146. data/spec/tls/server_certificate.pem +0 -29
  147. data/spec/tls/server_key.pem +0 -51
  148. data/spec/toxiproxy_helper.rb +0 -28
  149. data/spec/unit/bunny_spec.rb +0 -15
  150. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  151. data/spec/unit/concurrent/condition_spec.rb +0 -82
  152. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  153. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  154. data/spec/unit/exchange_recovery_spec.rb +0 -39
  155. data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,250 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "spec_helper"
3
-
4
- require "socket"
5
-
6
- unless ENV["CI"]
7
- CERTIFICATE_DIR = ENV.fetch("BUNNY_CERTIFICATE_DIR", "./spec/tls")
8
- puts "Will use certificates from #{CERTIFICATE_DIR}"
9
-
10
- shared_examples_for "successful TLS connection" do
11
- it "succeeds" do
12
- expect(subject).to be_tls
13
- ch = subject.create_channel
14
- ch.confirm_select
15
-
16
- q = ch.queue("", exclusive: true)
17
- x = ch.default_exchange
18
-
19
- x.publish("xyzzy", routing_key: q.name).
20
- publish("xyzzy", routing_key: q.name).
21
- publish("xyzzy", routing_key: q.name).
22
- publish("xyzzy", routing_key: q.name)
23
-
24
- x.wait_for_confirms
25
- expect(q.message_count).to eq 4
26
-
27
- i = 0
28
- q.subscribe do |delivery_info, _, payload|
29
- i += 1
30
- end
31
- sleep 1.0
32
- expect(i).to eq 4
33
- expect(q.message_count).to eq 0
34
-
35
- ch.close
36
- end
37
- end
38
-
39
- def local_hostname
40
- ENV.fetch("BUNNY_RABBITMQ_HOSTNAME", "localhost")
41
- end
42
-
43
- context "initialized with :tls => true" do
44
- let(:subject) do
45
- Bunny.new(
46
- hostname: local_hostname(),
47
- user: "bunny_gem",
48
- password: "bunny_password",
49
- vhost: "bunny_testbed",
50
- tls: true,
51
- verify_peer: verify_peer,
52
- tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
53
- tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
54
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"])
55
- end
56
-
57
- context "peer verification is off" do
58
- let(:verify_peer) { false }
59
-
60
- it "uses TLS port" do
61
- expect(subject.port).to eq AMQ::Protocol::TLS_PORT
62
- end
63
-
64
- it "sends the SNI details" do
65
- # https://github.com/ruby-amqp/bunny/issues/440
66
- subject.start
67
- expect(subject.transport.socket.hostname).to_not be_empty
68
- end
69
-
70
- after :each do
71
- subject.close
72
- end
73
- end
74
-
75
- context "peer verification is on" do
76
- let(:verify_peer) { true }
77
-
78
- it "uses TLS port" do
79
- expect(subject.port).to eq AMQ::Protocol::TLS_PORT
80
- end
81
- end
82
- end
83
-
84
- describe "TLS connection to RabbitMQ with client certificates" do
85
- let(:subject) do
86
- c = Bunny.new(
87
- hostname: local_hostname(),
88
- username: "bunny_gem",
89
- password: "bunny_password",
90
- vhost: "bunny_testbed",
91
- tls: true,
92
- tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
93
- tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
94
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
95
- verify_peer: false)
96
- c.start
97
- c
98
- end
99
-
100
- after :each do
101
- subject.close
102
- end
103
-
104
- include_examples "successful TLS connection"
105
- end
106
-
107
-
108
- describe "TLS connection to RabbitMQ without client certificates" do
109
- let(:subject) do
110
- c = Bunny.new(
111
- hostname: local_hostname(),
112
- username: "bunny_gem",
113
- password: "bunny_password",
114
- vhost: "bunny_testbed",
115
- tls: true,
116
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
117
- verify_peer: false)
118
- c.start
119
- c
120
- end
121
-
122
- after :each do
123
- subject.close
124
- end
125
-
126
- include_examples "successful TLS connection"
127
- end
128
-
129
-
130
- describe "TLS connection to RabbitMQ with a connection string" do
131
- let(:subject) do
132
- c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
133
- tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
134
- tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
135
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
136
- verify_peer: false)
137
- c.start
138
- c
139
- end
140
-
141
- after :each do
142
- subject.close
143
- end
144
-
145
- include_examples "successful TLS connection"
146
-
147
- context "when URI contains query parameters" do
148
- subject(:session) do
149
- Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed?heartbeat=10&connection_timeout=100&channel_max=1000&verify=false&cacertfile=#{CERTIFICATE_DIR}/ca_certificate.pem&certfile=#{CERTIFICATE_DIR}/client_certificate.pem&keyfile=#{CERTIFICATE_DIR}/client_key.pem")
150
- end
151
-
152
- it "parses extra connection parameters" do
153
- session.start
154
-
155
- expect(session.uses_tls?).to eq(true)
156
- expect(session.transport.verify_peer).to eq(false)
157
- expect(session.transport.tls_ca_certificates).to eq(["#{CERTIFICATE_DIR}/ca_certificate.pem"])
158
- expect(session.transport.tls_certificate_path).to eq("#{CERTIFICATE_DIR}/client_certificate.pem")
159
- expect(session.transport.tls_key_path).to eq("#{CERTIFICATE_DIR}/client_key.pem")
160
- end
161
- end
162
- end
163
-
164
-
165
- describe "TLS connection to RabbitMQ with a connection string and w/o client certificate and key" do
166
- let(:subject) do
167
- c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
168
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
169
- verify_peer: verify_peer)
170
- c.start
171
- c
172
- end
173
-
174
- after :each do
175
- subject.close
176
- end
177
-
178
- context "peer verification is off" do
179
- let(:verify_peer) { false }
180
-
181
- include_examples "successful TLS connection"
182
-
183
- it "sends the SNI details" do
184
- # https://github.com/ruby-amqp/bunny/issues/440
185
- expect(subject.transport.socket.hostname).to_not be_empty
186
- end
187
- end
188
-
189
- context "peer verification is on" do
190
- let(:verify_peer) { true }
191
-
192
- include_examples "successful TLS connection"
193
-
194
- it "sends the SNI details" do
195
- # https://github.com/ruby-amqp/bunny/issues/440
196
- expect(subject.transport.socket.hostname).to_not be_empty
197
- end
198
- end
199
- end
200
-
201
-
202
- describe "TLS connection to RabbitMQ with client certificates provided inline" do
203
- let(:subject) do
204
- c = Bunny.new(
205
- hostname: local_hostname(),
206
- username: "bunny_gem",
207
- password: "bunny_password",
208
- vhost: "bunny_testbed",
209
- tls: true,
210
- tls_cert: File.read("#{CERTIFICATE_DIR}/client_certificate.pem"),
211
- tls_key: File.read("#{CERTIFICATE_DIR}/client_key.pem"),
212
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
213
- verify_peer: false)
214
- c.start
215
- c
216
- end
217
-
218
- after :each do
219
- subject.close
220
- end
221
-
222
- include_examples "successful TLS connection"
223
- end
224
-
225
- describe "TLS connection to RabbitMQ with tls_version TLSv1.1 specified" do
226
- let(:subject) do
227
- c = Bunny.new(
228
- hostname: local_hostname(),
229
- username: "bunny_gem",
230
- password: "bunny_password",
231
- vhost: "bunny_testbed",
232
- tls: true,
233
- tls_protocol: :TLSv1_1,
234
- tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
235
- verify_peer: false)
236
- c.start
237
- c
238
- end
239
-
240
- after :each do
241
- subject.close
242
- end
243
-
244
- include_examples "successful TLS connection"
245
-
246
- it "connects using TLSv1.1" do
247
- expect(subject.transport.socket.ssl_version).to eq "TLSv1.1"
248
- end
249
- end
250
- end
@@ -1,76 +0,0 @@
1
- require "spec_helper"
2
- require_relative "../../toxiproxy_helper"
3
-
4
- if ::Toxiproxy.running?
5
- describe Bunny::Channel, "#basic_publish" do
6
- include RabbitMQ::Toxiproxy
7
-
8
- after :each do
9
- @connection.close if @connection.open?
10
- end
11
-
12
- context "when the the connection detects missed heartbeats with automatic recovery" do
13
- before(:each) do
14
- setup_toxiproxy
15
- @connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
16
- host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: true)
17
- @connection.start
18
- end
19
-
20
- let(:queue_name) { "bunny.basic.publish.queue#{rand}" }
21
-
22
- it "raises a ConnectionClosedError" do
23
- ch = @connection.create_channel
24
- begin
25
- rabbitmq_toxiproxy.down do
26
- sleep 2
27
- expect { ch.default_exchange.publish("", :routing_key => queue_name) }.to raise_error(Bunny::ConnectionClosedError)
28
- end
29
- ensure
30
- cleanup_toxiproxy
31
- end
32
- end
33
- end
34
-
35
- context "when the the connection detects missed heartbeats without automatic recovery" do
36
- before(:each) do
37
- setup_toxiproxy
38
- @connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
39
- host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: false, threaded: false)
40
- @connection.start
41
- end
42
-
43
- it "does not raise an exception on session thread" do
44
- rabbitmq_toxiproxy.down do
45
- sleep 5
46
- end
47
- end
48
- end
49
-
50
- context "recovery attempt limit that's exceeded" do
51
- before(:each) do
52
- setup_toxiproxy
53
- @connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
54
- host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: true, network_recovery_interval: 1,
55
- recovery_attempts: 2, reset_recovery_attempts_after_reconnection: true,
56
- disconnect_timeout: 1)
57
- @connection.start
58
- end
59
-
60
- it "permanently closes connection" do
61
- expect(@connection.open?).to be(true)
62
-
63
- rabbitmq_toxiproxy.down do
64
- sleep 5
65
- end
66
- # give the connection one last chance to recover
67
- sleep 3
68
-
69
- expect(@connection.open?).to be(false)
70
- expect(@connection.closed?).to be(true)
71
- end
72
- end # context
73
- end # describe
74
- else
75
- puts "Toxiproxy isn't running, some examples will be skipped"
76
- end
@@ -1,21 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#tx_commit" do
4
- let(:connection) do
5
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- it "is supported" do
15
- ch = connection.create_channel
16
- ch.tx_select
17
- ch.tx_commit
18
-
19
- ch.close
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#tx_rollback" do
4
- let(:connection) do
5
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- it "is supported" do
15
- ch = connection.create_channel
16
- ch.tx_select
17
- ch.tx_rollback
18
-
19
- ch.close
20
- end
21
- end
@@ -1,25 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#with_channel" do
4
- let(:connection) do
5
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- it "closes if the block throws an exception" do
15
- ch = nil
16
- begin
17
- connection.with_channel do |wch|
18
- ch = wch
19
- raise Exception.new
20
- end
21
- rescue Exception
22
- end
23
- expect(ch).to be_closed
24
- end
25
- end
@@ -1,42 +0,0 @@
1
- require "spec_helper"
2
-
3
- unless ENV["CI"]
4
- describe Bunny::Channel, "#basic_publish" do
5
- before :all do
6
- @connection = Bunny.new(username: "bunny_gem",
7
- password: "bunny_password",
8
- vhost: "bunny_testbed",
9
- write_timeout: 0,
10
- read_timeout: 0)
11
- @connection.start
12
- end
13
-
14
- after :all do
15
- @connection.close if @connection.open?
16
- end
17
-
18
-
19
- context "when publishing thousands of messages" do
20
- let(:n) { 2_000 }
21
- let(:m) { 10 }
22
-
23
- it "successfully publishers them all" do
24
- ch = @connection.create_channel
25
-
26
- q = ch.queue("", exclusive: true)
27
- x = ch.default_exchange
28
-
29
- body = "x" * 1024
30
- m.times do |i|
31
- n.times do
32
- x.publish(body, routing_key: q.name)
33
- end
34
- puts "Published #{i * n} 1K messages..."
35
- end
36
-
37
- q.purge
38
- ch.close
39
- end
40
- end
41
- end
42
- end
@@ -1,43 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Registering 2nd exclusive consumer on queue" do
4
- before :all do
5
- @connection = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
6
- @connection.start
7
- end
8
-
9
- after :each do
10
- @connection.close if @connection.open?
11
- end
12
-
13
-
14
- it "raises a meaningful exception" do
15
- xs = []
16
-
17
- ch1 = @connection.create_channel
18
- ch2 = @connection.create_channel
19
- q1 = ch1.queue("", :auto_delete => true)
20
- q2 = ch2.queue(q1.name, :auto_delete => true, :passive => true)
21
-
22
- c1 = q1.subscribe(exclusive: true) do |_, _, payload|
23
- xs << payload
24
- end
25
- sleep 0.1
26
-
27
- expect do
28
- q2.subscribe(exclusive: true) do |_, _, _|
29
- end
30
- end.to raise_error(Bunny::AccessRefused)
31
-
32
- expect(ch1).to be_open
33
- expect(ch2).to be_closed
34
-
35
- q1.publish("abc")
36
- sleep 0.1
37
-
38
- # verify that the first consumer is fine
39
- expect(xs).to eq ["abc"]
40
-
41
- q1.delete
42
- end
43
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Session do
4
- context "with unreachable host" do
5
- it "raises Bunny::TCPConnectionFailed" do
6
- begin
7
- conn = Bunny.new(:hostname => "192.192.192.192")
8
- conn.start
9
-
10
- fail "expected 192.192.192.192 to be unreachable"
11
- rescue Bunny::TCPConnectionFailed => e
12
- end
13
- end
14
- end
15
- end
@@ -1,40 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "spec_helper"
3
-
4
- unless ENV["CI"]
5
- describe "Message framing implementation" do
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))
11
- c.start
12
- c
13
- end
14
-
15
- after :each do
16
- connection.close if connection.open?
17
- end
18
-
19
-
20
- context "with payload 272179 bytes in size" do
21
- it "successfully frames the message" do
22
- ch = connection.create_channel
23
-
24
- q = ch.queue("", exclusive: true)
25
- x = ch.default_exchange
26
-
27
- as = ("a" * 272179)
28
- x.publish(as, routing_key: q.name, persistent: true)
29
-
30
- sleep(1)
31
- expect(q.message_count).to eq 1
32
-
33
- _, _, payload = q.pop
34
- expect(payload.bytesize).to eq as.bytesize
35
-
36
- ch.close
37
- end
38
- end
39
- end
40
- end
@@ -1,32 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Bunny::Session do
5
- let(:connection) do
6
- c = Bunny.new(
7
- user: 'bunny_gem', password: 'bunny_password',
8
- vhost: 'bunny_testbed',
9
- port: ENV.fetch('RABBITMQ_PORT', 5672)
10
- )
11
- c.start
12
- c
13
- end
14
-
15
- context 'after the connection has been manually closed' do
16
- before :each do
17
- connection.close
18
- end
19
-
20
- after :each do
21
- connection.close if connection.open?
22
- end
23
-
24
- describe '#create_channel' do
25
- it 'should raise an exception' do
26
- expect {
27
- connection.create_channel
28
- }.to raise_error(Bunny::ConnectionAlreadyClosed)
29
- end
30
- end
31
- end
32
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bunny::Session do
4
- context 'when retry attempts have been exhausted' do
5
- let(:io) { StringIO.new } # keep test output clear
6
-
7
- def create_session
8
- described_class.new(
9
- host: 'fake.host',
10
- recovery_attempts: 0,
11
- connection_timeout: 0,
12
- network_recovery_interval: 0,
13
- logfile: io,
14
- )
15
- end
16
-
17
- it 'closes the session' do
18
- session = create_session
19
- session.handle_network_failure(StandardError.new)
20
- expect(session.closed?).to be true
21
- end
22
-
23
- it 'stops the reader loop' do
24
- session = create_session
25
- reader_loop = session.reader_loop
26
- session.handle_network_failure(StandardError.new)
27
- expect(reader_loop.stopping?).to be true
28
- end
29
- end
30
- end
@@ -1,72 +0,0 @@
1
- require "spec_helper"
2
-
3
- unless ENV["CI"]
4
- describe Bunny::Queue, "#subscribe" do
5
- before :all do
6
- @connection1 = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
7
- @connection1.start
8
- @connection2 = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
9
- @connection2.start
10
- end
11
-
12
- after :all do
13
- [@connection1, @connection2].select { |c| !!c }.each do |c|
14
- c.close if c.open?
15
- end
16
- end
17
-
18
-
19
- context "with an empty queue" do
20
- it "consumes messages" do
21
- delivered_data = []
22
-
23
- ch1 = @connection1.create_channel
24
- ch2 = @connection1.create_channel
25
-
26
- q = ch1.queue("", exclusive: true)
27
- q.subscribe(manual_ack: false, block: false) do |delivery_info, properties, payload|
28
- delivered_data << payload
29
- end
30
- sleep 0.5
31
-
32
- x = ch2.default_exchange
33
- x.publish("abc", routing_key: q.name)
34
- sleep 0.7
35
-
36
- expect(delivered_data).to eq ["abc"]
37
-
38
- ch1.close
39
- ch2.close
40
- end
41
- end
42
-
43
- context "with a non-empty queue" do
44
- let(:queue_name) { "queue#{rand}" }
45
-
46
- it "consumes messages" do
47
- delivered_data = []
48
-
49
- ch1 = @connection1.create_channel
50
- ch2 = @connection1.create_channel
51
-
52
- q = ch1.queue(queue_name, exclusive: true)
53
- x = ch2.default_exchange
54
- 3.times do |i|
55
- x.publish("data#{i}", routing_key: queue_name)
56
- end
57
- sleep 0.7
58
- expect(q.message_count).to eq 3
59
-
60
- q.subscribe(manual_ack: false, block: false) do |delivery_info, properties, payload|
61
- delivered_data << payload
62
- end
63
- sleep 0.7
64
-
65
- expect(delivered_data).to eq ["data0", "data1", "data2"]
66
-
67
- ch1.close
68
- ch2.close
69
- end
70
- end
71
- end
72
- end