bunny 1.7.1 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CONTRIBUTING.md +14 -0
  4. data/ChangeLog.md +21 -6
  5. data/Gemfile +1 -1
  6. data/LICENSE +1 -1
  7. data/README.md +22 -23
  8. data/bunny.gemspec +1 -1
  9. data/lib/bunny/channel.rb +12 -0
  10. data/lib/bunny/concurrent/continuation_queue.rb +30 -13
  11. data/lib/bunny/exchange.rb +0 -5
  12. data/lib/bunny/jruby/socket.rb +1 -2
  13. data/lib/bunny/queue.rb +9 -0
  14. data/lib/bunny/session.rb +7 -6
  15. data/lib/bunny/version.rb +1 -1
  16. data/spec/higher_level_api/integration/basic_ack_spec.rb +9 -9
  17. data/spec/higher_level_api/integration/basic_cancel_spec.rb +4 -4
  18. data/spec/higher_level_api/integration/basic_consume_spec.rb +22 -22
  19. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +1 -1
  20. data/spec/higher_level_api/integration/basic_get_spec.rb +2 -2
  21. data/spec/higher_level_api/integration/basic_nack_spec.rb +6 -6
  22. data/spec/higher_level_api/integration/basic_publish_spec.rb +14 -14
  23. data/spec/higher_level_api/integration/basic_qos_spec.rb +11 -2
  24. data/spec/higher_level_api/integration/basic_recover_spec.rb +2 -2
  25. data/spec/higher_level_api/integration/basic_reject_spec.rb +6 -6
  26. data/spec/higher_level_api/integration/basic_return_spec.rb +1 -1
  27. data/spec/higher_level_api/integration/channel_close_spec.rb +2 -2
  28. data/spec/higher_level_api/integration/channel_open_spec.rb +11 -11
  29. data/spec/higher_level_api/integration/connection_recovery_spec.rb +52 -52
  30. data/spec/higher_level_api/integration/connection_spec.rb +83 -83
  31. data/spec/higher_level_api/integration/connection_stop_spec.rb +11 -11
  32. data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +2 -2
  33. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +3 -3
  34. data/spec/higher_level_api/integration/dead_lettering_spec.rb +6 -6
  35. data/spec/higher_level_api/integration/exchange_bind_spec.rb +1 -1
  36. data/spec/higher_level_api/integration/exchange_declare_spec.rb +20 -20
  37. data/spec/higher_level_api/integration/exchange_delete_spec.rb +11 -11
  38. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +2 -2
  39. data/spec/higher_level_api/integration/merry_go_round_spec.rb +2 -2
  40. data/spec/higher_level_api/integration/message_properties_access_spec.rb +27 -27
  41. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +1 -1
  42. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +19 -19
  43. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +9 -9
  44. data/spec/higher_level_api/integration/queue_bind_spec.rb +13 -13
  45. data/spec/higher_level_api/integration/queue_declare_spec.rb +23 -23
  46. data/spec/higher_level_api/integration/queue_delete_spec.rb +1 -1
  47. data/spec/higher_level_api/integration/queue_purge_spec.rb +2 -2
  48. data/spec/higher_level_api/integration/queue_unbind_spec.rb +2 -2
  49. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +3 -3
  50. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +4 -4
  51. data/spec/higher_level_api/integration/tls_connection_spec.rb +5 -5
  52. data/spec/higher_level_api/integration/with_channel_spec.rb +1 -1
  53. data/spec/issues/issue100_spec.rb +9 -10
  54. data/spec/issues/issue141_spec.rb +11 -12
  55. data/spec/issues/issue224_spec.rb +2 -2
  56. data/spec/issues/issue78_spec.rb +14 -18
  57. data/spec/issues/issue83_spec.rb +5 -6
  58. data/spec/issues/issue97_spec.rb +25 -26
  59. data/spec/lower_level_api/integration/basic_cancel_spec.rb +15 -16
  60. data/spec/lower_level_api/integration/basic_consume_spec.rb +19 -20
  61. data/spec/stress/channel_open_stress_spec.rb +1 -1
  62. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +6 -7
  63. data/spec/stress/concurrent_consumers_stress_spec.rb +6 -7
  64. data/spec/stress/concurrent_publishers_stress_spec.rb +6 -7
  65. data/spec/stress/connection_open_close_spec.rb +6 -6
  66. data/spec/stress/long_running_consumer_spec.rb +6 -7
  67. data/spec/unit/bunny_spec.rb +5 -5
  68. data/spec/unit/concurrent/atomic_fixnum_spec.rb +6 -6
  69. data/spec/unit/concurrent/condition_spec.rb +3 -3
  70. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +2 -2
  71. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +16 -16
  72. data/spec/unit/system_timer_spec.rb +2 -2
  73. data/spec/unit/version_delivery_tag_spec.rb +3 -3
  74. metadata +8 -7
@@ -1,33 +1,32 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Bunny::Channel, "#basic_consume" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
- c.start
7
- c
4
+ before(:all) do
5
+ @connection = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
+ @connection.start
8
7
  end
9
8
 
10
9
  after :all do
11
- connection.close if connection.open?
10
+ @connection.close if @connection.open?
12
11
  end
13
12
 
14
13
  it "returns basic.consume-ok when it is received" do
15
- ch = connection.create_channel
14
+ ch = @connection.create_channel
16
15
  q = ch.queue("", :exclusive => true)
17
16
 
18
17
  consume_ok = ch.basic_consume(q)
19
- consume_ok.should be_instance_of(AMQ::Protocol::Basic::ConsumeOk)
20
- consume_ok.consumer_tag.should_not be_nil
18
+ expect(consume_ok).to be_instance_of AMQ::Protocol::Basic::ConsumeOk
19
+ expect(consume_ok.consumer_tag).not_to be_nil
21
20
 
22
21
  ch.close
23
22
  end
24
23
 
25
24
  it "carries server-generated consumer tag with basic.consume-ok" do
26
- ch = connection.create_channel
25
+ ch = @connection.create_channel
27
26
  q = ch.queue("", :exclusive => true)
28
27
 
29
28
  consume_ok = ch.basic_consume(q, "")
30
- consume_ok.consumer_tag.should =~ /amq\.ctag.*/
29
+ expect(consume_ok.consumer_tag).to match /amq\.ctag.*/
31
30
 
32
31
  ch.close
33
32
  end
@@ -40,7 +39,7 @@ describe Bunny::Channel, "#basic_consume" do
40
39
  delivered_data = []
41
40
 
42
41
  t = Thread.new do
43
- ch = connection.create_channel
42
+ ch = @connection.create_channel
44
43
  q = ch.queue(queue_name, :auto_delete => true, :durable => false)
45
44
  ch.basic_consume(q, "", true, false) do |delivery_info, properties, payload|
46
45
  delivered_keys << delivery_info.routing_key
@@ -50,15 +49,15 @@ describe Bunny::Channel, "#basic_consume" do
50
49
  t.abort_on_exception = true
51
50
  sleep 0.5
52
51
 
53
- ch = connection.create_channel
52
+ ch = @connection.create_channel
54
53
  x = ch.default_exchange
55
54
  x.publish("hello", :routing_key => queue_name)
56
55
 
57
56
  sleep 0.7
58
- delivered_keys.should include(queue_name)
59
- delivered_data.should include("hello")
57
+ expect(delivered_keys).to include queue_name
58
+ expect(delivered_data).to include "hello"
60
59
 
61
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
60
+ expect(ch.queue(queue_name, :auto_delete => true, :durable => false).message_count).to eq 0
62
61
 
63
62
  ch.close
64
63
  end
@@ -72,7 +71,7 @@ describe Bunny::Channel, "#basic_consume" do
72
71
  delivered_data = []
73
72
 
74
73
  t = Thread.new do
75
- ch = connection.create_channel
74
+ ch = @connection.create_channel
76
75
  q = ch.queue(queue_name, :auto_delete => true, :durable => false)
77
76
  ch.basic_consume(q, "", false, false) do |delivery_info, properties, payload|
78
77
  delivered_keys << delivery_info.routing_key
@@ -84,15 +83,15 @@ describe Bunny::Channel, "#basic_consume" do
84
83
  t.abort_on_exception = true
85
84
  sleep 0.5
86
85
 
87
- ch = connection.create_channel
86
+ ch = @connection.create_channel
88
87
  x = ch.default_exchange
89
88
  x.publish("hello", :routing_key => queue_name)
90
89
 
91
90
  sleep 0.7
92
- delivered_keys.should include(queue_name)
93
- delivered_data.should include("hello")
91
+ expect(delivered_keys).to include queue_name
92
+ expect(delivered_data).to include "hello"
94
93
 
95
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
94
+ expect(ch.queue(queue_name, :auto_delete => true, :durable => false).message_count).to eq 0
96
95
 
97
96
  ch.close
98
97
  end
@@ -18,7 +18,7 @@ describe "Rapidly opening and closing lots of channels" do
18
18
  xs = Array.new(n) { @connection.create_channel }
19
19
  puts "Opened #{n} channels"
20
20
 
21
- xs.size.should == n
21
+ expect(xs.size).to eq n
22
22
  xs.each do |ch|
23
23
  ch.close
24
24
  end
@@ -2,23 +2,22 @@ require "spec_helper"
2
2
 
3
3
  unless ENV["CI"]
4
4
  describe "Rapidly opening and closing lots of channels on a non-threaded connection" do
5
- let(:connection) do
6
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false, :threaded => false)
7
- c.start
8
- c
5
+ before :all do
6
+ @connection = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false, :threaded => false)
7
+ @connection.start
9
8
  end
10
9
 
11
10
  after :all do
12
- connection.close
11
+ @connection.close
13
12
  end
14
13
 
15
14
  context "in a single-threaded scenario" do
16
15
  let(:n) { 500 }
17
16
 
18
17
  it "works correctly" do
19
- xs = Array.new(n) { connection.create_channel }
18
+ xs = Array.new(n) { @connection.create_channel }
20
19
 
21
- xs.size.should == n
20
+ expect(xs.size).to eq n
22
21
  xs.each do |ch|
23
22
  ch.close
24
23
  end
@@ -3,15 +3,14 @@ require "spec_helper"
3
3
 
4
4
  unless ENV["CI"]
5
5
  describe "Concurrent consumers sharing a connection" do
6
- let(:connection) do
7
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed",
6
+ before :all do
7
+ @connection = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed",
8
8
  :automatic_recovery => false, :continuation_timeout => 6000)
9
- c.start
10
- c
9
+ @connection.start
11
10
  end
12
11
 
13
12
  after :all do
14
- connection.close
13
+ @connection.close
15
14
  end
16
15
 
17
16
  def any_not_drained?(qs)
@@ -25,13 +24,13 @@ unless ENV["CI"]
25
24
  let(:m) { 1000 }
26
25
 
27
26
  it "successfully drain all queues" do
28
- ch = connection.create_channel
27
+ ch = @connection.create_channel
29
28
  body = "абвг"
30
29
  x = ch.topic("bunny.stress.concurrent.consumers.topic", :durable => true)
31
30
 
32
31
  chs = {}
33
32
  n.times do |i|
34
- chs[i] = connection.create_channel
33
+ chs[i] = @connection.create_channel
35
34
  end
36
35
  qs = []
37
36
 
@@ -3,21 +3,20 @@ require "spec_helper"
3
3
 
4
4
  unless ENV["CI"]
5
5
  describe "Concurrent publishers sharing a connection" do
6
- let(:connection) do
7
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatically_recover => false, :continuation_timeout => 20.0)
8
- c.start
9
- c
6
+ before :all do
7
+ @connection = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatically_recover => false, :continuation_timeout => 20.0)
8
+ @connection.start
10
9
  end
11
10
 
12
11
  after :all do
13
- connection.close
12
+ @connection.close
14
13
  end
15
14
 
16
15
  let(:concurrency) { 24 }
17
16
  let(:rate) { 5_000 }
18
17
 
19
18
  it "successfully finish publishing" do
20
- ch = connection.create_channel
19
+ ch = @connection.create_channel
21
20
 
22
21
  q = ch.queue("", :exclusive => true)
23
22
  body = "сообщение"
@@ -27,7 +26,7 @@ unless ENV["CI"]
27
26
 
28
27
  chs = {}
29
28
  concurrency.times do |i|
30
- chs[i] = connection.create_channel
29
+ chs[i] = @connection.create_channel
31
30
  end
32
31
 
33
32
  ts = []
@@ -17,9 +17,9 @@ unless defined?(JRUBY_VERSION) && !ENV["FORCE_JRUBY_RUN"]
17
17
  c.start
18
18
  ch = c.create_channel
19
19
 
20
- c.should be_connected
20
+ expect(c).to be_connected
21
21
  c.stop
22
- c.should be_closed
22
+ expect(c).to be_closed
23
23
  end
24
24
  end
25
25
 
@@ -29,9 +29,9 @@ unless defined?(JRUBY_VERSION) && !ENV["FORCE_JRUBY_RUN"]
29
29
  c.start
30
30
  ch = c.create_channel
31
31
 
32
- c.should be_connected
32
+ expect(c).to be_connected
33
33
  c.stop
34
- c.should be_closed
34
+ expect(c).to be_closed
35
35
  end
36
36
  end
37
37
 
@@ -42,9 +42,9 @@ unless defined?(JRUBY_VERSION) && !ENV["FORCE_JRUBY_RUN"]
42
42
  c.start
43
43
  ch = c.create_channel
44
44
 
45
- c.should be_connected
45
+ expect(c).to be_connected
46
46
  c.stop
47
- c.should be_closed
47
+ expect(c).to be_closed
48
48
  end
49
49
  end
50
50
  end
@@ -6,14 +6,13 @@ unless ENV["CI"]
6
6
  require "bunny/test_kit"
7
7
 
8
8
  describe "Long running [relatively to heartbeat interval] consumer that never publishes" do
9
- let(:connection) do
10
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false, :heartbeat_interval => 6)
11
- c.start
12
- c
9
+ before :all do
10
+ @connection = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false, :heartbeat_interval => 6)
11
+ @connection.start
13
12
  end
14
13
 
15
14
  after :all do
16
- connection.close
15
+ @connection.close
17
16
  end
18
17
 
19
18
  let(:target) { 512 * 1024 * 1024 }
@@ -29,7 +28,7 @@ unless ENV["CI"]
29
28
 
30
29
  ct = Thread.new do
31
30
  t = 0
32
- ch = connection.create_channel(nil, 6)
31
+ ch = @connection.create_channel(nil, 6)
33
32
  begin
34
33
  q = ch.queue(queue, :exclusive => true)
35
34
 
@@ -53,7 +52,7 @@ unless ENV["CI"]
53
52
 
54
53
  pt = Thread.new do
55
54
  t = 0
56
- ch = connection.create_channel
55
+ ch = @connection.create_channel
57
56
  begin
58
57
  x = ch.fanout("amq.fanout")
59
58
 
@@ -2,14 +2,14 @@ require "spec_helper"
2
2
 
3
3
  describe Bunny do
4
4
  it "has library version" do
5
- Bunny::VERSION.should_not be_nil
6
- Bunny.version.should_not be_nil
5
+ expect(Bunny::VERSION).not_to be_nil
6
+ expect(Bunny.version).not_to be_nil
7
7
  end
8
8
 
9
9
 
10
10
  it "has AMQP protocol version" do
11
- Bunny::PROTOCOL_VERSION.should == "0.9.1"
12
- AMQ::Protocol::PROTOCOL_VERSION.should == "0.9.1"
13
- Bunny.protocol_version.should == "0.9.1"
11
+ expect(Bunny::PROTOCOL_VERSION).to eq "0.9.1"
12
+ expect(AMQ::Protocol::PROTOCOL_VERSION).to eq "0.9.1"
13
+ expect(Bunny.protocol_version).to eq "0.9.1"
14
14
  end
15
15
  end
@@ -5,31 +5,31 @@ describe Bunny::Concurrent::AtomicFixnum do
5
5
  it "allows retrieving the current value" do
6
6
  af = described_class.new(0)
7
7
 
8
- af.get.should == 0
9
- af.should == 0
8
+ expect(af.get).to eq 0
9
+ expect(af).to eq 0
10
10
  end
11
11
 
12
12
  it "can be updated" do
13
13
  af = described_class.new(0)
14
14
 
15
- af.get.should == 0
15
+ expect(af.get).to eq 0
16
16
  Thread.new do
17
17
  af.set(10)
18
18
  end
19
19
  sleep 0.6
20
- af.get.should == 10
20
+ expect(af.get).to eq 10
21
21
  end
22
22
 
23
23
  it "can be incremented" do
24
24
  af = described_class.new(0)
25
25
 
26
- af.get.should == 0
26
+ expect(af.get).to eq 0
27
27
  10.times do
28
28
  Thread.new do
29
29
  af.increment
30
30
  end
31
31
  end
32
32
  sleep 0.6
33
- af.get.should == 10
33
+ expect(af.get).to eq 10
34
34
  end
35
35
  end
@@ -18,7 +18,7 @@ describe Bunny::Concurrent::Condition do
18
18
  t.abort_on_exception = true
19
19
 
20
20
  condition.wait
21
- xs.should == [:notified]
21
+ expect(xs).to eq [:notified]
22
22
  end
23
23
  end
24
24
  end
@@ -45,7 +45,7 @@ describe Bunny::Concurrent::Condition do
45
45
  sleep 0.25
46
46
  condition.notify
47
47
  sleep 0.5
48
- xs.should satisfy { |ys| ys.size == 1 && (ys.include?(:notified1) || ys.include?(:notified2)) }
48
+ expect(xs).to satisfy { |ys| ys.size == 1 && (ys.include?(:notified1) || ys.include?(:notified2)) }
49
49
  end
50
50
  end
51
51
  end
@@ -74,7 +74,7 @@ describe Bunny::Concurrent::Condition do
74
74
  n.times do |i|
75
75
  item = "notified#{i + 1}".to_sym
76
76
 
77
- @xs.should include(item)
77
+ expect(@xs).to include item
78
78
  end
79
79
  end
80
80
  end
@@ -14,7 +14,7 @@ if defined?(JRUBY_VERSION)
14
14
  t.abort_on_exception = true
15
15
 
16
16
  v = subject.poll(500)
17
- v.should == 10
17
+ expect(v).to eq 10
18
18
  end
19
19
  end
20
20
 
@@ -28,7 +28,7 @@ if defined?(JRUBY_VERSION)
28
28
  end
29
29
  t.abort_on_exception = true
30
30
 
31
- lambda { subject.poll(500) }.should raise_error(::Timeout::Error)
31
+ expect { subject.poll(500) }.to raise_error(::Timeout::Error)
32
32
  end
33
33
  end
34
34
  end
@@ -6,42 +6,42 @@ unless ENV["CI"]
6
6
  50.times do |i|
7
7
  it "provides the same API as SortedSet for key operations (take #{i})" do
8
8
  s = described_class.new
9
- s.length.should == 0
9
+ expect(s.length).to eq 0
10
10
 
11
11
  s << 1
12
- s.length.should == 1
12
+ expect(s.length).to eq 1
13
13
  s << 1
14
- s.length.should == 1
14
+ expect(s.length).to eq 1
15
15
  s << 2
16
- s.length.should == 2
16
+ expect(s.length).to eq 2
17
17
  s << 3
18
- s.length.should == 3
18
+ expect(s.length).to eq 3
19
19
  s << 4
20
- s.length.should == 4
20
+ expect(s.length).to eq 4
21
21
  s << 4
22
22
  s << 4
23
23
  s << 4
24
- s.length.should == 4
24
+ expect(s.length).to eq 4
25
25
  s << 5
26
- s.length.should == 5
26
+ expect(s.length).to eq 5
27
27
  s << 5
28
28
  s << 5
29
29
  s << 5
30
- s.length.should == 5
30
+ expect(s.length).to eq 5
31
31
  s << 6
32
- s.length.should == 6
32
+ expect(s.length).to eq 6
33
33
  s << 7
34
- s.length.should == 7
34
+ expect(s.length).to eq 7
35
35
  s << 8
36
- s.length.should == 8
36
+ expect(s.length).to eq 8
37
37
  s.delete 8
38
- s.length.should == 7
38
+ expect(s.length).to eq 7
39
39
  s.delete_if { |i| i == 1 }
40
- s.length.should == 6
40
+ expect(s.length).to eq 6
41
41
  end
42
42
  it "synchronizes common operations needed by Bunny (take #{i})" do
43
43
  s = described_class.new
44
- s.length.should == 0
44
+ expect(s.length).to eq 0
45
45
 
46
46
  10.times do
47
47
  Thread.new do
@@ -66,7 +66,7 @@ unless ENV["CI"]
66
66
  end
67
67
  sleep 0.5
68
68
 
69
- s.length.should == 6
69
+ expect(s.length).to eq 6
70
70
  end
71
71
  end
72
72
  end