bunny 0.10.8 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -4
  3. data/ChangeLog.md +1 -152
  4. data/Gemfile +1 -1
  5. data/README.md +5 -5
  6. data/bunny.gemspec +1 -1
  7. data/lib/bunny.rb +14 -2
  8. data/lib/bunny/channel.rb +94 -158
  9. data/lib/bunny/channel_id_allocator.rb +1 -2
  10. data/lib/bunny/concurrent/condition.rb +1 -2
  11. data/lib/bunny/concurrent/continuation_queue.rb +1 -1
  12. data/lib/bunny/consumer.rb +0 -13
  13. data/lib/bunny/consumer_work_pool.rb +2 -5
  14. data/lib/bunny/delivery_info.rb +1 -3
  15. data/lib/bunny/exceptions.rb +1 -4
  16. data/lib/bunny/heartbeat_sender.rb +1 -1
  17. data/lib/bunny/reader_loop.rb +3 -23
  18. data/lib/bunny/session.rb +19 -103
  19. data/lib/bunny/socket.rb +1 -1
  20. data/lib/bunny/transport.rb +7 -31
  21. data/lib/bunny/version.rb +1 -1
  22. data/spec/higher_level_api/integration/basic_ack_spec.rb +19 -34
  23. data/spec/higher_level_api/integration/basic_cancel_spec.rb +1 -1
  24. data/spec/higher_level_api/integration/basic_consume_spec.rb +2 -63
  25. data/spec/higher_level_api/integration/basic_get_spec.rb +1 -1
  26. data/spec/higher_level_api/integration/basic_nack_spec.rb +1 -1
  27. data/spec/higher_level_api/integration/basic_publish_spec.rb +1 -1
  28. data/spec/higher_level_api/integration/basic_qos_spec.rb +8 -5
  29. data/spec/higher_level_api/integration/basic_reject_spec.rb +17 -16
  30. data/spec/higher_level_api/integration/basic_return_spec.rb +1 -1
  31. data/spec/higher_level_api/integration/channel_close_spec.rb +10 -6
  32. data/spec/higher_level_api/integration/channel_flow_spec.rb +9 -6
  33. data/spec/higher_level_api/integration/channel_open_spec.rb +20 -11
  34. data/spec/higher_level_api/integration/confirm_select_spec.rb +1 -1
  35. data/spec/higher_level_api/integration/connection_spec.rb +1 -1
  36. data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +1 -1
  37. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +1 -46
  38. data/spec/higher_level_api/integration/dead_lettering_spec.rb +1 -1
  39. data/spec/higher_level_api/integration/exchange_bind_spec.rb +1 -1
  40. data/spec/higher_level_api/integration/exchange_declare_spec.rb +1 -1
  41. data/spec/higher_level_api/integration/exchange_delete_spec.rb +1 -1
  42. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +1 -1
  43. data/spec/higher_level_api/integration/merry_go_round_spec.rb +1 -1
  44. data/spec/higher_level_api/integration/message_properties_access_spec.rb +1 -1
  45. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +1 -1
  46. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +1 -1
  47. data/spec/higher_level_api/integration/queue_declare_spec.rb +1 -1
  48. data/spec/higher_level_api/integration/queue_delete_spec.rb +2 -2
  49. data/spec/higher_level_api/integration/queue_purge_spec.rb +1 -1
  50. data/spec/higher_level_api/integration/queue_unbind_spec.rb +2 -2
  51. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +1 -1
  52. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +2 -2
  53. data/spec/higher_level_api/integration/tls_connection_spec.rb +2 -86
  54. data/spec/higher_level_api/integration/tx_commit_spec.rb +1 -1
  55. data/spec/higher_level_api/integration/tx_rollback_spec.rb +1 -1
  56. data/spec/unit/concurrent/condition_spec.rb +46 -53
  57. metadata +5 -25
  58. data/benchmarks/mutex_and_monitor.rb +0 -42
  59. data/benchmarks/synchronized_sorted_set.rb +0 -53
  60. data/lib/amq/protocol/extensions.rb +0 -16
  61. data/lib/bunny/concurrent/atomic_fixnum.rb +0 -74
  62. data/lib/bunny/concurrent/synchronized_sorted_set.rb +0 -56
  63. data/lib/bunny/timeout.rb +0 -18
  64. data/lib/bunny/versioned_delivery_tag.rb +0 -28
  65. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -26
  66. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  67. data/spec/issues/issue141_spec.rb +0 -44
  68. data/spec/stress/connection_open_close_spec.rb +0 -40
  69. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  70. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
@@ -7,7 +7,7 @@ describe Bunny::Channel, "#confirm_select" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -284,7 +284,7 @@ describe Bunny::Session do
284
284
 
285
285
 
286
286
  context "initialized with :host => 127.0.0.1 and non-default credentials (take 2)" do
287
- after :each do
287
+ after :all do
288
288
  subject.close if subject.open?
289
289
  end
290
290
 
@@ -9,7 +9,7 @@ unless ENV["CI"]
9
9
  c
10
10
  end
11
11
 
12
- after :each do
12
+ after :all do
13
13
  connection.close
14
14
  end
15
15
 
@@ -7,7 +7,7 @@ describe Bunny::Channel do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -80,49 +80,4 @@ describe Bunny::Channel do
80
80
  ch.close
81
81
  end
82
82
  end
83
-
84
-
85
-
86
- context "with consumer re-registration" do
87
- class ExampleConsumerThatReregisters < Bunny::Consumer
88
- def handle_cancellation(_)
89
- @queue = @channel.queue("basic.consume.after_cancellation", :auto_delete => true)
90
- @channel.basic_consume_with(self)
91
- end
92
- end
93
-
94
- let(:queue_name) { "basic.consume#{rand}" }
95
-
96
- it "works correctly" do
97
- consumer = nil
98
- xs = []
99
-
100
- ch = connection.create_channel
101
- t = Thread.new do
102
- ch2 = connection.create_channel
103
- q = ch2.queue(queue_name, :auto_delete => true)
104
-
105
- consumer = ExampleConsumerThatReregisters.new(ch2, q, "")
106
- consumer.on_delivery do |_, _, payload|
107
- xs << payload
108
- end
109
- q.subscribe_with(consumer)
110
- end
111
- t.abort_on_exception = true
112
-
113
- sleep 0.5
114
- x = ch.default_exchange
115
- x.publish("abc", :routing_key => queue_name)
116
-
117
- sleep 0.5
118
- ch.queue(queue_name, :auto_delete => true).delete
119
-
120
- x.publish("abc", :routing_key => queue_name)
121
- sleep 0.5
122
- q = ch.queue("basic.consume.after_cancellation", :auto_delete => true)
123
- xs.should == ["abc"]
124
-
125
- ch.close
126
- end
127
- end
128
83
  end
@@ -7,7 +7,7 @@ describe "A message" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Exchange do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Exchange do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Exchange, "#delete" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Exchange do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -31,7 +31,7 @@ describe "A message that is proxied by multiple intermediate consumers" do
31
31
  c
32
32
  end
33
33
 
34
- after :each do
34
+ after :all do
35
35
  [c1, c2, c3, c4, c5].each do |c|
36
36
  c.close if c.open?
37
37
  end
@@ -7,7 +7,7 @@ describe Bunny::Queue, "#subscribe" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe "amq.* exchanges" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -11,7 +11,7 @@ unless ENV["CI"]
11
11
  c
12
12
  end
13
13
 
14
- after :each do
14
+ after :all do
15
15
  connection.close if connection.open?
16
16
  end
17
17
 
@@ -7,7 +7,7 @@ describe Bunny::Queue do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Queue, "#delete" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close
12
12
  end
13
13
 
@@ -22,7 +22,7 @@ describe Bunny::Queue, "#delete" do
22
22
  expect {
23
23
  q.delete
24
24
  }.to raise_error(Bunny::NotFound)
25
-
25
+
26
26
  ch.queues.size.should == 0
27
27
  end
28
28
  end
@@ -7,7 +7,7 @@ describe Bunny::Queue do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Queue, "bound to an exchange" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close
12
12
  end
13
13
 
@@ -37,7 +37,7 @@ describe Bunny::Queue, "NOT bound to an exchange" do
37
37
  c
38
38
  end
39
39
 
40
- after :each do
40
+ after :all do
41
41
  connection.close
42
42
  end
43
43
 
@@ -13,7 +13,7 @@ describe Bunny::Queue, "#subscribe" do
13
13
  c
14
14
  end
15
15
 
16
- after :each do
16
+ after :all do
17
17
  publisher_connection.close if publisher_connection.open?
18
18
  consumer_connection.close if consumer_connection.open?
19
19
  end
@@ -7,7 +7,7 @@ describe "Sender-selected distribution" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -23,7 +23,7 @@ describe "Sender-selected distribution" do
23
23
  n.times do |i|
24
24
  x.publish("Message #{i}", :routing_key => "one", :headers => {"CC" => ["two", "three"]})
25
25
  end
26
-
26
+
27
27
  sleep 0.5
28
28
 
29
29
  q1.message_count.should == n
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  unless ENV["CI"]
5
- describe "TLS connection to RabbitMQ with client certificates" do
5
+ describe "TLS connection to RabbitMQ" do
6
6
  let(:connection) do
7
7
  c = Bunny.new(:user => "bunny_gem",
8
8
  :password => "bunny_password",
@@ -15,7 +15,7 @@ unless ENV["CI"]
15
15
  c
16
16
  end
17
17
 
18
- after :each do
18
+ after :all do
19
19
  connection.close
20
20
  end
21
21
 
@@ -44,88 +44,4 @@ unless ENV["CI"]
44
44
  ch.close
45
45
  end
46
46
  end
47
-
48
-
49
- describe "TLS connection to RabbitMQ without client certificates" do
50
- let(:connection) do
51
- c = Bunny.new(:user => "bunny_gem",
52
- :password => "bunny_password",
53
- :vhost => "bunny_testbed",
54
- :tls => true,
55
- :tls_ca_certificates => ["./spec/tls/cacert.pem"])
56
- c.start
57
- c
58
- end
59
-
60
- after :each do
61
- connection.close
62
- end
63
-
64
- it "provides the same API as a regular connection" do
65
- ch = connection.create_channel
66
-
67
- q = ch.queue("", :exclusive => true)
68
- x = ch.default_exchange
69
-
70
- x.publish("xyzzy", :routing_key => q.name).
71
- publish("xyzzy", :routing_key => q.name).
72
- publish("xyzzy", :routing_key => q.name).
73
- publish("xyzzy", :routing_key => q.name)
74
-
75
- sleep 0.5
76
- q.message_count.should == 4
77
-
78
- i = 0
79
- q.subscribe do |delivery_info, _, payload|
80
- i += 1
81
- end
82
- sleep 1.0
83
- i.should == 4
84
- q.message_count.should == 0
85
-
86
- ch.close
87
- end
88
- end
89
-
90
-
91
- describe "TLS connection to RabbitMQ with a connection string" do
92
- let(:connection) do
93
- c = Bunny.new("amqps://bunny_gem:bunny_password@127.0.0.1/bunny_testbed",
94
- :tls_cert => "spec/tls/client_cert.pem",
95
- :tls_key => "spec/tls/client_key.pem",
96
- :tls_ca_certificates => ["./spec/tls/cacert.pem"])
97
- c.start
98
- c
99
- end
100
-
101
- after :each do
102
- connection.close
103
- end
104
-
105
- it "provides the same API as a regular connection" do
106
- connection.should be_tls
107
- ch = connection.create_channel
108
-
109
- q = ch.queue("", :exclusive => true)
110
- x = ch.default_exchange
111
-
112
- x.publish("xyzzy", :routing_key => q.name).
113
- publish("xyzzy", :routing_key => q.name).
114
- publish("xyzzy", :routing_key => q.name).
115
- publish("xyzzy", :routing_key => q.name)
116
-
117
- sleep 0.5
118
- q.message_count.should == 4
119
-
120
- i = 0
121
- q.subscribe do |delivery_info, _, payload|
122
- i += 1
123
- end
124
- sleep 1.0
125
- i.should == 4
126
- q.message_count.should == 0
127
-
128
- ch.close
129
- end
130
- end
131
47
  end
@@ -7,7 +7,7 @@ describe Bunny::Channel, "#tx_commit" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ describe Bunny::Channel, "#tx_rollback" do
7
7
  c
8
8
  end
9
9
 
10
- after :each do
10
+ after :all do
11
11
  connection.close if connection.open?
12
12
  end
13
13
 
@@ -2,80 +2,73 @@ require "spec_helper"
2
2
  require "bunny/concurrent/condition"
3
3
 
4
4
  describe Bunny::Concurrent::Condition do
5
-
6
5
  describe "#wait" do
7
- 100.times do |i|
8
- it "blocks current thread until notified (take #{i})" do
9
- condition = described_class.new
10
- xs = []
6
+ it "blocks current thread until notified" do
7
+ condition = described_class.new
8
+ xs = []
11
9
 
12
- t = Thread.new do
13
- xs << :notified
10
+ t = Thread.new do
11
+ xs << :notified
14
12
 
15
- sleep 0.25
16
- condition.notify
17
- end
18
- t.abort_on_exception = true
19
-
20
- condition.wait
21
- xs.should == [:notified]
13
+ sleep 0.25
14
+ condition.notify
22
15
  end
16
+ t.abort_on_exception = true
17
+
18
+ condition.wait
19
+ xs.should == [:notified]
23
20
  end
24
21
  end
25
22
 
26
23
  describe "#notify" do
27
- 100.times do |i|
28
- it "notifies a single thread waiting on the latch (take #{i})" do
29
- mutex = Mutex.new
30
- condition = described_class.new
31
- xs = []
32
-
33
- t1 = Thread.new do
34
- condition.wait
35
- mutex.synchronize { xs << :notified1 }
36
- end
37
- t1.abort_on_exception = true
24
+ it "notifies a single thread waiting on the latch" do
25
+ mutex = Mutex.new
26
+ condition = described_class.new
27
+ xs = []
38
28
 
39
- t2 = Thread.new do
40
- condition.wait
41
- mutex.synchronize { xs << :notified2 }
42
- end
43
- t2.abort_on_exception = true
29
+ t1 = Thread.new do
30
+ condition.wait
31
+ mutex.synchronize { xs << :notified1 }
32
+ end
33
+ t1.abort_on_exception = true
44
34
 
45
- sleep 0.25
46
- condition.notify
47
- sleep 0.5
48
- xs.should satisfy { |ys| ys.size == 1 && (ys.include?(:notified1) || ys.include?(:notified2)) }
35
+ t2 = Thread.new do
36
+ condition.wait
37
+ mutex.synchronize { xs << :notified2 }
49
38
  end
39
+ t2.abort_on_exception = true
40
+
41
+ sleep 0.25
42
+ condition.notify
43
+ sleep 0.5
44
+ xs.should satisfy { |ys| ys.size == 1 && (ys.include?(:notified1) || ys.include?(:notified2)) }
50
45
  end
51
46
  end
52
47
 
53
48
  describe "#notify_all" do
54
- let(:n) { 30 }
49
+ let(:n) { 120 }
55
50
 
56
- 100.times do |i|
57
- it "notifies all the threads waiting on the latch (take #{i})" do
58
- mutex = Mutex.new
59
- condition = described_class.new
60
- @xs = []
51
+ it "notifies all the threads waiting on the latch" do
52
+ mutex = Mutex.new
53
+ condition = described_class.new
54
+ @xs = []
61
55
 
62
- n.times do |i|
63
- t = Thread.new do
64
- condition.wait
65
- mutex.synchronize { @xs << "notified#{i + 1}".to_sym }
66
- end
67
- t.abort_on_exception = true
56
+ n.times do |i|
57
+ t = Thread.new do
58
+ condition.wait
59
+ mutex.synchronize { @xs << "notified#{i + 1}".to_sym }
68
60
  end
61
+ t.abort_on_exception = true
62
+ end
69
63
 
70
- sleep 0.5
71
- condition.notify_all
72
- sleep 0.5
64
+ sleep 0.5
65
+ condition.notify_all
66
+ sleep 0.5
73
67
 
74
- n.times do |i|
75
- item = "notified#{i + 1}".to_sym
68
+ n.times do |i|
69
+ item = "notified#{i + 1}".to_sym
76
70
 
77
- @xs.should include(item)
78
- end
71
+ @xs.should include(item)
79
72
  end
80
73
  end
81
74
  end