bunny 2.7.4 → 2.22.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 (156) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +61 -35
  3. data/lib/bunny/channel.rb +186 -50
  4. data/lib/bunny/channel_id_allocator.rb +3 -1
  5. data/lib/bunny/consumer.rb +2 -2
  6. data/lib/bunny/consumer_work_pool.rb +2 -1
  7. data/lib/bunny/cruby/socket.rb +3 -0
  8. data/lib/bunny/cruby/ssl_socket.rb +6 -1
  9. data/lib/bunny/delivery_info.rb +1 -1
  10. data/lib/bunny/heartbeat_sender.rb +2 -1
  11. data/lib/bunny/jruby/ssl_socket.rb +5 -0
  12. data/lib/bunny/queue.rb +36 -8
  13. data/lib/bunny/reader_loop.rb +22 -10
  14. data/lib/bunny/session.rb +152 -65
  15. data/lib/bunny/test_kit.rb +14 -0
  16. data/lib/bunny/transport.rb +132 -49
  17. data/lib/bunny/version.rb +1 -1
  18. data/lib/bunny.rb +45 -4
  19. metadata +37 -225
  20. data/.github/ISSUE_TEMPLATE.md +0 -18
  21. data/.gitignore +0 -28
  22. data/.rspec +0 -1
  23. data/.travis.yml +0 -20
  24. data/.yardopts +0 -8
  25. data/CONTRIBUTING.md +0 -111
  26. data/ChangeLog.md +0 -1831
  27. data/Gemfile +0 -53
  28. data/LICENSE +0 -21
  29. data/Rakefile +0 -46
  30. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  31. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  32. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  33. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  34. data/benchmarks/channel_open.rb +0 -28
  35. data/benchmarks/mutex_and_monitor.rb +0 -42
  36. data/benchmarks/queue_declare.rb +0 -29
  37. data/benchmarks/queue_declare_and_bind.rb +0 -29
  38. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  39. data/benchmarks/synchronized_sorted_set.rb +0 -53
  40. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  41. data/bin/ci/before_build +0 -46
  42. data/bunny.gemspec +0 -35
  43. data/docker/Dockerfile +0 -16
  44. data/docker/docker-entrypoint.sh +0 -37
  45. data/docker-compose.yml +0 -18
  46. data/examples/connection/authentication_failure.rb +0 -16
  47. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  48. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  49. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  50. data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
  51. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  52. data/examples/connection/channel_level_exception.rb +0 -27
  53. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  54. data/examples/connection/heartbeat.rb +0 -17
  55. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  56. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  57. data/examples/connection/unknown_host.rb +0 -16
  58. data/examples/consumers/high_and_low_priority.rb +0 -50
  59. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  60. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  61. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  62. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  63. data/examples/guides/extensions/alternate_exchange.rb +0 -30
  64. data/examples/guides/extensions/basic_nack.rb +0 -33
  65. data/examples/guides/extensions/connection_blocked.rb +0 -35
  66. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  67. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  68. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  69. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  70. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  71. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  72. data/examples/guides/extensions/queue_lease.rb +0 -26
  73. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  74. data/examples/guides/getting_started/blabbr.rb +0 -27
  75. data/examples/guides/getting_started/hello_world.rb +0 -22
  76. data/examples/guides/getting_started/weathr.rb +0 -49
  77. data/examples/guides/queues/one_off_consumer.rb +0 -25
  78. data/examples/guides/queues/redeliveries.rb +0 -81
  79. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  80. data/repl +0 -3
  81. data/spec/config/enabled_plugins +0 -1
  82. data/spec/config/rabbitmq.config +0 -19
  83. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
  84. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
  85. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -349
  86. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  87. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
  88. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
  89. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
  90. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
  91. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
  92. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  93. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -25
  94. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  95. data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -471
  96. data/spec/higher_level_api/integration/connection_spec.rb +0 -559
  97. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
  98. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  99. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
  100. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  101. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
  102. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  103. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  104. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  105. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
  106. data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
  107. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  108. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  109. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
  110. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
  111. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  112. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -221
  113. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  114. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  115. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  116. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  117. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  118. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -222
  119. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  120. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  121. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  122. data/spec/issues/issue100_spec.rb +0 -42
  123. data/spec/issues/issue141_spec.rb +0 -43
  124. data/spec/issues/issue202_spec.rb +0 -15
  125. data/spec/issues/issue224_spec.rb +0 -40
  126. data/spec/issues/issue465_spec.rb +0 -32
  127. data/spec/issues/issue78_spec.rb +0 -72
  128. data/spec/issues/issue83_spec.rb +0 -30
  129. data/spec/issues/issue97_attachment.json +0 -1
  130. data/spec/issues/issue97_spec.rb +0 -175
  131. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
  132. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
  133. data/spec/spec_helper.rb +0 -51
  134. data/spec/stress/channel_close_stress_spec.rb +0 -64
  135. data/spec/stress/channel_open_stress_spec.rb +0 -84
  136. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  137. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
  138. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
  139. data/spec/stress/connection_open_close_spec.rb +0 -52
  140. data/spec/stress/long_running_consumer_spec.rb +0 -84
  141. data/spec/tls/ca_certificate.pem +0 -29
  142. data/spec/tls/ca_key.pem +0 -52
  143. data/spec/tls/client_certificate.pem +0 -29
  144. data/spec/tls/client_key.pem +0 -51
  145. data/spec/tls/generate-server-cert.sh +0 -8
  146. data/spec/tls/server-openssl.cnf +0 -10
  147. data/spec/tls/server.csr +0 -16
  148. data/spec/tls/server_certificate.pem +0 -29
  149. data/spec/tls/server_key.pem +0 -51
  150. data/spec/unit/bunny_spec.rb +0 -15
  151. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  152. data/spec/unit/concurrent/condition_spec.rb +0 -82
  153. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  154. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  155. data/spec/unit/exchange_recovery_spec.rb +0 -39
  156. data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,559 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Session do
4
- let(:port) { AMQ::Protocol::DEFAULT_PORT }
5
- let(:username) { "guest" }
6
-
7
- let(:tls_port) { AMQ::Protocol::TLS_PORT }
8
-
9
- context "initialized via connection URI" do
10
- after :each do
11
- subject.close if subject.open?
12
- end
13
-
14
- context "when schema is not one of [amqp, amqps]" do
15
- it "raises ArgumentError" do
16
- expect {
17
- described_class.new("http://127.0.0.1")
18
- }.to raise_error(ArgumentError, /amqp or amqps schema/)
19
- end
20
- end
21
-
22
- it "handles amqp:// URIs w/o path part" do
23
- session = described_class.new("amqp://127.0.0.1")
24
- session.start
25
-
26
- expect(session.vhost).to eq "/"
27
- expect(session.host).to eq "127.0.0.1"
28
- expect(session.port).to eq 5672
29
- expect(session.ssl?).to eq false
30
-
31
- session.close
32
- end
33
-
34
- context "when URI ends in a slash" do
35
- it "parses vhost as an empty string" do
36
- session = described_class.new("amqp://127.0.0.1/")
37
-
38
- expect(session.hostname).to eq "127.0.0.1"
39
- expect(session.port).to eq 5672
40
- expect(session.vhost).to eq ""
41
- end
42
- end
43
-
44
- context "when URI is amqp://dev.rabbitmq.com/a/path/with/slashes" do
45
- it "raises an ArgumentError" do
46
- expect { described_class.new("amqp://dev.rabbitmq.com/a/path/with/slashes") }.to raise_error(ArgumentError)
47
- end
48
- end
49
- end
50
-
51
- context "initialized with all defaults" do
52
- it "provides a way to fine tune socket options" do
53
- conn = Bunny.new
54
- conn.start
55
- expect(conn.transport.socket).to respond_to(:setsockopt)
56
-
57
- conn.close
58
- end
59
-
60
- it "successfully negotiates the connection" do
61
- conn = Bunny.new
62
- conn.start
63
- expect(conn).to be_connected
64
-
65
- expect(conn.server_properties).not_to be_nil
66
- expect(conn.server_capabilities).not_to be_nil
67
-
68
- props = conn.server_properties
69
-
70
- expect(props["product"]).not_to be_nil
71
- expect(props["platform"]).not_to be_nil
72
- expect(props["version"]).not_to be_nil
73
-
74
- conn.close
75
- end
76
- end
77
-
78
- unless ENV["CI"]
79
- context "initialized with TCP connection timeout = 5" do
80
- it "successfully connects" do
81
- conn = described_class.new(connection_timeout: 5)
82
- conn.start
83
- expect(conn).to be_connected
84
-
85
- expect(conn.server_properties).not_to be_nil
86
- expect(conn.server_capabilities).not_to be_nil
87
-
88
- props = conn.server_properties
89
-
90
- expect(props["product"]).not_to be_nil
91
- expect(props["platform"]).not_to be_nil
92
- expect(props["version"]).not_to be_nil
93
-
94
- conn.close
95
- end
96
- end
97
-
98
- context "initialized with hostname: 127.0.0.1" do
99
- after :each do
100
- subject.close if subject.open?
101
- end
102
-
103
- let(:host) { "127.0.0.1" }
104
- subject do
105
- described_class.new(hostname: host)
106
- end
107
-
108
- it "uses hostname = 127.0.0.1" do
109
- expect(subject.host).to eq host
110
- expect(subject.hostname).to eq host
111
- end
112
-
113
- it "uses port 5672" do
114
- expect(subject.port).to eq port
115
- end
116
-
117
- it "uses username = guest" do
118
- expect(subject.username).to eq username
119
- end
120
- end
121
-
122
- context "initialized with hostname: localhost" do
123
- after :each do
124
- subject.close if subject.open?
125
- end
126
-
127
- let(:host) { "localhost" }
128
- let(:subject) { described_class.new(hostname: host) }
129
-
130
- it "uses hostname = localhost" do
131
- expect(subject.host).to eq host
132
- expect(subject.hostname).to eq host
133
- end
134
-
135
- it "uses port 5672" do
136
- expect(subject.port).to eq port
137
- end
138
-
139
- it "uses username = guest" do
140
- expect(subject.username).to eq username
141
- expect(subject.user).to eq username
142
- end
143
- end
144
-
145
- context "initialized with a list of hosts" do
146
- after :each do
147
- subject.close if subject.open?
148
- end
149
-
150
- let(:host) { "192.168.1.10" }
151
- let(:hosts) { [host] }
152
- let(:subject) { described_class.new(hosts: hosts) }
153
-
154
- it "uses hostname = 192.168.1.10" do
155
- expect(subject.host).to eq host
156
- expect(subject.hostname).to eq host
157
- end
158
-
159
- it "uses port 5672" do
160
- expect(subject.port).to eq port
161
- end
162
-
163
- it "uses username = guest" do
164
- expect(subject.username).to eq username
165
- expect(subject.user).to eq username
166
- end
167
- end
168
-
169
- context "initialized with a list of addresses" do
170
- after :each do
171
- subject.close if subject.open?
172
- end
173
-
174
- let(:host) { "192.168.1.10" }
175
- let(:port) { 5673 }
176
- let(:address) { "#{host}:#{port}" }
177
- let(:addresses) { [address] }
178
- let(:subject) { described_class.new(addresses: addresses) }
179
-
180
- it "uses hostname = 192.168.1.10" do
181
- expect(subject.host).to eq host
182
- expect(subject.hostname).to eq host
183
- end
184
-
185
- it "uses port 5673" do
186
- expect(subject.port).to eq port
187
- end
188
-
189
- it "uses username = guest" do
190
- expect(subject.username).to eq username
191
- expect(subject.user).to eq username
192
- end
193
- end
194
-
195
- context "initialized with addresses: [...] with quoted IPv6 hostnames" do
196
- after :each do
197
- subject.close if subject.open?
198
- end
199
-
200
- let(:host) { "[2001:db8:85a3:8d3:1319:8a2e:370:7348]" }
201
- let(:port) { 5673 }
202
- let(:address) { "#{host}:#{port}" }
203
- let(:addresses) { [address] }
204
- let(:subject) { described_class.new(addresses: addresses) }
205
-
206
- it "uses correct hostname" do
207
- expect(subject.host).to eq host
208
- expect(subject.hostname).to eq host
209
- end
210
-
211
- it "uses port 5673" do
212
- expect(subject.port).to eq port
213
- end
214
-
215
- it "uses username = guest" do
216
- expect(subject.username).to eq username
217
- expect(subject.user).to eq username
218
- end
219
- end
220
-
221
- context "initialized with addresses: [...] with quoted IPv6 hostnames without ports" do
222
- after :each do
223
- subject.close if subject.open?
224
- end
225
-
226
- let(:host) { "[2001:db8:85a3:8d3:1319:8a2e:370:7348]" }
227
- let(:address) { host }
228
- let(:addresses) { [address] }
229
- let(:subject) { described_class.new(addresses: addresses) }
230
-
231
- it "uses correct hostname" do
232
- expect(subject.host).to eq host
233
- expect(subject.hostname).to eq host
234
- end
235
-
236
- it "uses port 5672" do
237
- expect(subject.port).to eq 5672
238
- end
239
-
240
- it "uses username = guest" do
241
- expect(subject.username).to eq username
242
- expect(subject.user).to eq username
243
- end
244
- end
245
-
246
- context "initialized with addresses: [...] with an quoted IPv6 hostnames" do
247
- after :each do
248
- subject.close if subject.open?
249
- end
250
-
251
- let(:host) { "2001:db8:85a3:8d3:1319:8a2e:370:7348" }
252
- let(:port) { 5673 }
253
- let(:address) { "#{host}:#{port}" }
254
- let(:addresses) { [address] }
255
- let(:subject) { described_class.new(addresses: addresses) }
256
-
257
- it "fails to correctly parse the host (and emits a warning)" do
258
- expect(subject.host).to eq "2001"
259
- expect(subject.hostname).to eq "2001"
260
- end
261
-
262
- it "fails to correctly parse the port (and emits a warning)" do
263
- expect(subject.port).to eq 0
264
- end
265
-
266
- it "uses username = guest" do
267
- expect(subject.username).to eq username
268
- expect(subject.user).to eq username
269
- end
270
- end
271
-
272
- context "initialized with conflicting hosts and addresses" do
273
- let(:host) { "192.168.1.10" }
274
- let(:port) { 5673 }
275
- let(:address) { "#{host}:#{port}" }
276
- let(:io) { StringIO.new }
277
- let(:logger) { ::Logger.new(io) }
278
-
279
- it "raises an argument error when there is are hosts and an address" do
280
- expect { described_class.new(addresses: [address], hosts: [host]) }.to raise_error(ArgumentError)
281
- end
282
-
283
- it "logs a warning when there is a single host and an array" do
284
- described_class.new(addresses: [address], host: host, logger: logger)
285
- expect(io.string).to match(/both a host and an array of hosts/)
286
- end
287
-
288
- it "converts hosts in addresses to addresses" do
289
- strategy = Proc.new { |addresses| addresses }
290
- session = described_class.new(addresses: [address,host ], hosts_shuffle_strategy: strategy)
291
- strategy = Proc.new { |addresses| addresses }
292
-
293
- expect(session.to_s).to include 'addresses=[192.168.1.10:5673,192.168.1.10:5672]'
294
- end
295
- end
296
-
297
- context "initialized with channel_max: 4096" do
298
- after :each do
299
- subject.close if subject.open?
300
- end
301
-
302
- let(:channel_max) { 1024 }
303
- let(:subject) { described_class.new(channel_max: channel_max) }
304
-
305
- # this assumes RabbitMQ has no lower value configured. In 3.2
306
- # it is 0 (no limit) by default and 1024 is still a fairly low value
307
- # for future releases. MK.
308
- it "negotiates channel max to be 1024" do
309
- subject.start
310
- expect(subject.channel_max).to eq channel_max
311
-
312
- subject.close
313
- end
314
- end
315
-
316
- context "initialized with ssl: true" do
317
- let(:subject) do
318
- described_class.new(username: "bunny_gem",
319
- password: "bunny_password",
320
- vhost: "bunny_testbed",
321
- ssl: true,
322
- ssl_cert: "spec/tls/client_cert.pem",
323
- ssl_key: "spec/tls/client_key.pem",
324
- ssl_ca_certificates: ["./spec/tls/cacert.pem"])
325
- end
326
-
327
- it "uses TLS port" do
328
- expect(subject.port).to eq tls_port
329
- end
330
- end
331
-
332
- context "initialized with tls: true" do
333
- let(:subject) do
334
- described_class.new(username: "bunny_gem",
335
- password: "bunny_password",
336
- vhost: "bunny_testbed",
337
- tls: true,
338
- tls_cert: "spec/tls/client_certificate.pem",
339
- tls_key: "spec/tls/client_key.pem",
340
- tls_ca_certificates: ["./spec/tls/ca_certificate.pem"])
341
- end
342
-
343
- it "uses TLS port" do
344
- expect(subject.port).to eq tls_port
345
- end
346
- end
347
- end
348
-
349
- context "initialized with hostname: 127.0.0.1 and non-default credentials" do
350
- after :each do
351
- subject.close if subject.open?
352
- end
353
-
354
- let(:host) { "127.0.0.1" }
355
- # see ./bin/ci/before_build
356
- let(:username) { "bunny_gem" }
357
- let(:password) { "bunny_password" }
358
- let(:vhost) { "bunny_testbed" }
359
-
360
- subject do
361
- described_class.new(hostname: host, username: username, password: password, virtual_host: vhost)
362
- end
363
-
364
- it "successfully connects" do
365
- 5.times { subject.start }
366
- expect(subject).to be_connected
367
-
368
- expect(subject.server_properties).not_to be_nil
369
- expect(subject.server_capabilities).not_to be_nil
370
-
371
- props = subject.server_properties
372
-
373
- expect(props["product"]).not_to be_nil
374
- expect(props["platform"]).not_to be_nil
375
- expect(props["version"]).not_to be_nil
376
- end
377
-
378
- it "uses hostname = 127.0.0.1" do
379
- expect(subject.host).to eq host
380
- expect(subject.hostname).to eq host
381
- end
382
-
383
- it "uses port 5672" do
384
- expect(subject.port).to eq port
385
- end
386
-
387
- it "uses provided vhost" do
388
- expect(subject.vhost).to eq vhost
389
- expect(subject.virtual_host).to eq vhost
390
- end
391
-
392
- it "uses provided username" do
393
- expect(subject.username).to eq username
394
- end
395
-
396
- it "uses provided password" do
397
- expect(subject.password).to eq password
398
- end
399
- end
400
-
401
- context "initialized with hostname: 127.0.0.1 and non-default credentials (take 2)" do
402
- after :each do
403
- subject.close if subject.open?
404
- end
405
-
406
- let(:host) { "127.0.0.1" }
407
- # see ./bin/ci/before_build
408
- let(:username) { "bunny_gem" }
409
- let(:password) { "bunny_password" }
410
- let(:vhost) { "bunny_testbed" }
411
-
412
- subject do
413
- described_class.new(hostname: host, username: username, password: password, vhost: vhost)
414
- end
415
-
416
- it "successfully connects" do
417
- subject.start
418
- expect(subject).to be_connected
419
-
420
- expect(subject.server_properties).not_to be_nil
421
- expect(subject.server_capabilities).not_to be_nil
422
-
423
- props = subject.server_properties
424
-
425
- expect(props["product"]).not_to be_nil
426
- expect(props["platform"]).not_to be_nil
427
- expect(props["version"]).not_to be_nil
428
- end
429
-
430
- it "uses hostname = 127.0.0.1" do
431
- expect(subject.host).to eq host
432
- expect(subject.hostname).to eq host
433
- end
434
-
435
- it "uses port 5672" do
436
- expect(subject.port).to eq port
437
- end
438
-
439
- it "uses provided username" do
440
- expect(subject.username).to eq username
441
- end
442
-
443
- it "uses provided password" do
444
- expect(subject.password).to eq password
445
- end
446
- end
447
-
448
- context "initialized with hostname: 127.0.0.1 and non-default credentials (take 2)" do
449
- after :each do
450
- subject.close if subject.open?
451
- end
452
-
453
- let(:host) { "127.0.0.1" }
454
- # see ./bin/ci/before_build
455
- let(:username) { "bunny_gem" }
456
- let(:password) { "bunny_password" }
457
- let(:vhost) { "bunny_testbed" }
458
- let(:interval) { 1 }
459
-
460
- subject do
461
- described_class.new(hostname: host, username: username, password: password, vhost: vhost, heartbeat_interval: interval)
462
- end
463
-
464
- it "successfully connects" do
465
- subject.start
466
- expect(subject).to be_connected
467
-
468
- expect(subject.server_properties).not_to be_nil
469
- expect(subject.server_capabilities).not_to be_nil
470
-
471
- props = subject.server_properties
472
-
473
- expect(props["product"]).not_to be_nil
474
- expect(props["platform"]).not_to be_nil
475
- expect(props["version"]).not_to be_nil
476
- expect(props["capabilities"]).not_to be_nil
477
-
478
- # this is negotiated with RabbitMQ, so we need to
479
- # establish the connection first
480
- expect(subject.heartbeat).to eq interval
481
- end
482
- end
483
-
484
- context "initialized with hostname: 127.0.0.1 and INVALID credentials" do
485
- let(:host) { "127.0.0.1" }
486
- # see ./bin/ci/before_build
487
- let(:username) { "bunny_gem#{Time.now.to_i}" }
488
- let(:password) { "sdjkfhsdf8ysd8fy8" }
489
- let(:vhost) { "___sd89aysd98789" }
490
-
491
- subject do
492
- described_class.new(hostname: host, username: username, password: password, vhost: vhost)
493
- end
494
-
495
- it "fails to connect" do
496
- expect do
497
- subject.start
498
- end.to raise_error(Bunny::PossibleAuthenticationFailureError)
499
- end
500
-
501
- it "uses provided username" do
502
- expect(subject.username).to eq username
503
- end
504
-
505
- it "uses provided password" do
506
- expect(subject.password).to eq password
507
- end
508
- end
509
-
510
- context "initialized with unreachable host or port" do
511
- it "fails to connect" do
512
- expect do
513
- c = described_class.new(port: 38000)
514
- c.start
515
- end.to raise_error(Bunny::TCPConnectionFailed)
516
- end
517
-
518
- it "is not connected" do
519
- begin
520
- c = described_class.new(port: 38000)
521
- c.start
522
- rescue Bunny::TCPConnectionFailed => e
523
- true
524
- end
525
-
526
- expect(subject.status).to eq :not_connected
527
- end
528
-
529
- it "is not open" do
530
- begin
531
- c = described_class.new(port: 38000)
532
- c.start
533
- rescue Bunny::TCPConnectionFailed => e
534
- true
535
- end
536
-
537
- expect(subject).not_to be_open
538
- end
539
- end
540
-
541
- context "initialized with a custom logger object" do
542
- let(:io) { StringIO.new }
543
- let(:logger) { ::Logger.new(io) }
544
-
545
- it "uses provided logger" do
546
- conn = described_class.new(logger: logger)
547
- conn.start
548
-
549
- expect(io.string.length).to be > 100
550
-
551
- conn.close
552
- end
553
-
554
- it "doesn't reassign the logger's progname attribute" do
555
- expect(logger).not_to receive(:progname=)
556
- described_class.new(logger: logger)
557
- end
558
- end
559
- end
@@ -1,83 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Session do
4
- let(:http_client) { RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672") }
5
-
6
- def close_connection(client_port)
7
- # let whatever actions were taken before
8
- # this call a chance to propagate, e.g. to make
9
- # sure that connections are accounted for in the
10
- # stats DB.
11
- #
12
- # See bin/ci/before_build for management plugin
13
- # pre-configuration.
14
- #
15
- # MK.
16
- sleep 1.1
17
- c = http_client.
18
- list_connections.
19
- find { |conn_info| conn_info && conn_info.peer_port.to_i == client_port }
20
-
21
- http_client.close_connection(c.name) if c
22
- end
23
-
24
- def wait_for_recovery
25
- sleep 1.5
26
- end
27
-
28
- it "can be closed" do
29
- c = Bunny.new(automatically_recover: false)
30
- c.start
31
- ch = c.create_channel
32
-
33
- expect(c).to be_connected
34
- c.stop
35
- expect(c).to be_closed
36
- end
37
-
38
- it "can be closed twice (Session#close is idempotent)" do
39
- c = Bunny.new(automatically_recover: false)
40
- c.start
41
- ch = c.create_channel
42
-
43
- expect(c).to be_connected
44
- c.stop
45
- expect(c).to be_closed
46
- c.stop
47
- expect(c).to be_closed
48
- end
49
-
50
- describe "in a single threaded mode" do
51
- it "can be closed" do
52
- c = Bunny.new(automatically_recover: false, threaded: false)
53
- c.start
54
- ch = c.create_channel
55
-
56
- expect(c).to be_connected
57
- c.stop
58
- expect(c).to be_closed
59
- end
60
- end
61
-
62
-
63
- describe "that recovers from connection.close" do
64
- it "can be closed" do
65
- c = Bunny.new(automatically_recover: true,
66
- recover_from_connection_close: true,
67
- network_recovery_interval: 0.2)
68
- c.start
69
- ch = c.create_channel
70
-
71
- sleep 1.5
72
- expect(c).to be_open
73
- sleep 1.5
74
- close_connection(c.local_port)
75
-
76
- wait_for_recovery
77
- expect(c).to be_open
78
- expect(ch).to be_open
79
-
80
- c.close
81
- end
82
- end
83
- end