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
data/lib/bunny/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bunny
4
4
  # @return [String] Version of the library
5
- VERSION = "0.10.8"
5
+ VERSION = "1.0.0.pre1"
6
6
  end
@@ -7,65 +7,50 @@ describe Bunny::Channel, "#ack" 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
 
14
+ subject do
15
+ connection.create_channel
16
+ end
17
+
14
18
  context "with a valid (known) delivery tag" do
15
19
  it "acknowleges a message" do
16
- ch = connection.create_channel
17
- q = ch.queue("bunny.basic.ack.manual-acks", :exclusive => true)
18
- x = ch.default_exchange
20
+ q = subject.queue("bunny.basic.ack.manual-acks", :exclusive => true)
21
+ x = subject.default_exchange
19
22
 
20
23
  x.publish("bunneth", :routing_key => q.name)
21
- sleep 0.5
24
+ sleep(0.25)
22
25
  q.message_count.should == 1
23
26
  delivery_details, properties, content = q.pop(:ack => true)
24
27
 
25
- ch.ack(delivery_details.delivery_tag, true)
28
+ subject.ack(delivery_details.delivery_tag, true)
29
+ sleep(0.25)
26
30
  q.message_count.should == 0
27
31
 
28
- ch.close
29
- end
30
- end
31
-
32
-
33
- context "with a valid (known) delivery tag and automatic ack mode" do
34
- it "results in a channel exception" do
35
- ch = connection.create_channel
36
- q = ch.queue("bunny.basic.ack.manual-acks", :exclusive => true)
37
- x = ch.default_exchange
38
-
39
- q.subscribe(:manual_ack => false) do |delivery_info, properties, payload|
40
- ch.ack(delivery_info.delivery_tag, false)
41
- end
42
-
43
- x.publish("bunneth", :routing_key => q.name)
44
- sleep 0.5
45
- lambda do
46
- q.message_count
47
- end.should raise_error(Bunny::ChannelAlreadyClosed)
32
+ subject.close
48
33
  end
49
34
  end
50
35
 
51
36
  context "with an invalid (random) delivery tag" do
52
37
  it "causes a channel-level error" do
53
- ch = connection.create_channel
54
- q = ch.queue("bunny.basic.ack.unknown-delivery-tag", :exclusive => true)
55
- x = ch.default_exchange
38
+ q = subject.queue("bunny.basic.ack.unknown-delivery-tag", :exclusive => true)
39
+ x = subject.default_exchange
56
40
 
57
41
  x.publish("bunneth", :routing_key => q.name)
58
- sleep 0.5
42
+ sleep(0.25)
59
43
  q.message_count.should == 1
60
44
  _, _, content = q.pop(:ack => true)
61
45
 
62
- ch.on_error do |ch, channel_close|
46
+ subject.on_error do |ch, channel_close|
63
47
  @channel_close = channel_close
64
48
  end
65
- ch.ack(82, true)
66
- sleep 0.25
49
+ subject.ack(82, true)
50
+
51
+ sleep 0.5
67
52
 
68
- @channel_close.reply_code.should == AMQ::Protocol::PreconditionFailed::VALUE
53
+ @channel_close.reply_text.should == "PRECONDITION_FAILED - unknown delivery tag 82"
69
54
  end
70
55
  end
71
56
  end
@@ -7,7 +7,7 @@ describe Bunny::Consumer, "#cancel" 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
 
@@ -1,5 +1,4 @@
1
1
  require "spec_helper"
2
- require "set"
3
2
 
4
3
  describe Bunny::Queue, "#subscribe" do
5
4
  let(:connection) do
@@ -8,7 +7,7 @@ describe Bunny::Queue, "#subscribe" do
8
7
  c
9
8
  end
10
9
 
11
- after :each do
10
+ after :all do
12
11
  connection.close if connection.open?
13
12
  end
14
13
 
@@ -42,66 +41,6 @@ describe Bunny::Queue, "#subscribe" do
42
41
 
43
42
  ch.close
44
43
  end
45
-
46
- context "with a single consumer" do
47
- let(:queue_name) { "bunny.basic_consume#{rand}" }
48
-
49
- it "provides delivery tag access" do
50
- delivery_tags = SortedSet.new
51
-
52
- cch = connection.create_channel
53
- q = cch.queue(queue_name, :auto_delete => true, :durable => false)
54
- q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
55
- delivery_tags << delivery_info.delivery_tag
56
- end
57
- sleep 0.5
58
-
59
- ch = connection.create_channel
60
- x = ch.default_exchange
61
- 100.times do
62
- x.publish("hello", :routing_key => queue_name)
63
- end
64
-
65
- sleep 1.0
66
- delivery_tags.should == SortedSet.new(Range.new(1, 100).to_a)
67
-
68
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
69
-
70
- ch.close
71
- end
72
- end
73
-
74
-
75
- context "with multiple consumers on the same channel" do
76
- let(:queue_name) { "bunny.basic_consume#{rand}" }
77
-
78
- it "provides delivery tag access" do
79
- delivery_tags = SortedSet.new
80
-
81
- cch = connection.create_channel
82
- q = cch.queue(queue_name, :auto_delete => true, :durable => false)
83
-
84
- 7.times do
85
- q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
86
- delivery_tags << delivery_info.delivery_tag
87
- end
88
- end
89
- sleep 1.0
90
-
91
- ch = connection.create_channel
92
- x = ch.default_exchange
93
- 100.times do
94
- x.publish("hello", :routing_key => queue_name)
95
- end
96
-
97
- sleep 1.5
98
- delivery_tags.should == SortedSet.new(Range.new(1, 100).to_a)
99
-
100
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
101
-
102
- ch.close
103
- end
104
- end
105
44
  end
106
45
 
107
46
  context "with manual acknowledgement mode" do
@@ -138,7 +77,7 @@ describe Bunny::Queue, "#subscribe" do
138
77
  end
139
78
  end
140
79
 
141
- ENV.fetch("RUNS", 20).to_i.times do |i|
80
+ 20.times do |i|
142
81
  context "with a queue that already has messages (take #{i})" do
143
82
  let(:queue_name) { "bunny.basic_consume#{rand}" }
144
83
 
@@ -8,7 +8,7 @@ describe Bunny::Queue, "#pop" do
8
8
  c
9
9
  end
10
10
 
11
- after :each do
11
+ after :all do
12
12
  connection.close if connection.open?
13
13
  end
14
14
 
@@ -7,7 +7,7 @@ describe Bunny::Channel, "#nack" 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
 
@@ -8,7 +8,7 @@ if RUBY_VERSION <= "1.9"
8
8
  c
9
9
  end
10
10
 
11
- after :each do
11
+ after :all do
12
12
  connection.close if connection.open?
13
13
  end
14
14
 
@@ -7,22 +7,25 @@ describe Bunny::Channel, "#prefetch" 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
 
14
+
15
+ subject do
16
+ connection.create_channel
17
+ end
18
+
14
19
  context "with a positive integer" do
15
20
  it "sets that prefetch level via basic.qos" do
16
- ch = connection.create_channel
17
- ch.prefetch(10).should be_instance_of(AMQ::Protocol::Basic::QosOk)
21
+ subject.prefetch(10).should be_instance_of(AMQ::Protocol::Basic::QosOk)
18
22
  end
19
23
  end
20
24
 
21
25
  context "with a negative integer" do
22
26
  it "raises an ArgumentError" do
23
- ch = connection.create_channel
24
27
  expect {
25
- ch.prefetch(-2)
28
+ subject.prefetch(-2)
26
29
  }.to raise_error(ArgumentError)
27
30
  end
28
31
  end
@@ -7,64 +7,65 @@ describe Bunny::Channel, "#reject" 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
 
14
+ subject do
15
+ connection.create_channel
16
+ end
17
+
14
18
  context "with requeue = true" do
15
19
  it "requeues a message" do
16
- ch = connection.create_channel
17
- q = ch.queue("bunny.basic.reject.manual-acks", :exclusive => true)
18
- x = ch.default_exchange
20
+ q = subject.queue("bunny.basic.reject.manual-acks", :exclusive => true)
21
+ x = subject.default_exchange
19
22
 
20
23
  x.publish("bunneth", :routing_key => q.name)
21
24
  sleep(0.5)
22
25
  q.message_count.should == 1
23
26
  delivery_info, _, _ = q.pop(:ack => true)
24
27
 
25
- ch.reject(delivery_info.delivery_tag, true)
28
+ subject.reject(delivery_info.delivery_tag, true)
26
29
  sleep(0.5)
27
30
  q.message_count.should == 1
28
31
 
29
- ch.close
32
+ subject.close
30
33
  end
31
34
  end
32
35
 
33
36
  context "with requeue = false" do
34
37
  it "rejects a message" do
35
- ch = connection.create_channel
36
- q = ch.queue("bunny.basic.reject.with-requeue-false", :exclusive => true)
37
- x = ch.default_exchange
38
+ q = subject.queue("bunny.basic.reject.with-requeue-false", :exclusive => true)
39
+ x = subject.default_exchange
38
40
 
39
41
  x.publish("bunneth", :routing_key => q.name)
40
42
  sleep(0.5)
41
43
  q.message_count.should == 1
42
44
  delivery_info, _, _ = q.pop(:ack => true)
43
45
 
44
- ch.reject(delivery_info.delivery_tag, false)
46
+ subject.reject(delivery_info.delivery_tag, false)
45
47
  sleep(0.5)
46
48
  q.message_count.should == 0
47
49
 
48
- ch.close
50
+ subject.close
49
51
  end
50
52
  end
51
53
 
52
54
 
53
55
  context "with an invalid (random) delivery tag" do
54
56
  it "causes a channel-level error" do
55
- ch = connection.create_channel
56
- q = ch.queue("bunny.basic.reject.unknown-delivery-tag", :exclusive => true)
57
- x = ch.default_exchange
57
+ q = subject.queue("bunny.basic.reject.unknown-delivery-tag", :exclusive => true)
58
+ x = subject.default_exchange
58
59
 
59
60
  x.publish("bunneth", :routing_key => q.name)
60
61
  sleep(0.25)
61
62
  q.message_count.should == 1
62
63
  _, _, content = q.pop(:ack => true)
63
64
 
64
- ch.on_error do |ch, channel_close|
65
+ subject.on_error do |ch, channel_close|
65
66
  @channel_close = channel_close
66
67
  end
67
- ch.reject(82, true)
68
+ subject.reject(82, true)
68
69
 
69
70
  sleep 0.5
70
71
 
@@ -7,7 +7,7 @@ describe Bunny::Exchange, "#publish" 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,17 +7,21 @@ describe Bunny::Channel, "when closed" 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
 
14
+
15
+ subject do
16
+ connection.create_channel
17
+ end
18
+
14
19
  it "releases the id" do
15
- ch = connection.create_channel
16
- n = ch.number
20
+ n = subject.number
17
21
 
18
- ch.should be_open
19
- ch.close
20
- ch.should be_closed
22
+ subject.should be_open
23
+ subject.close
24
+ subject.should be_closed
21
25
 
22
26
  # a new channel with the same id can be created
23
27
  connection.create_channel(n)
@@ -7,15 +7,18 @@ describe Bunny::Channel, "#flow" 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
 
14
- it "is supported" do
15
- ch = connection.create_channel
16
14
 
17
- ch.flow(true).should be_instance_of(AMQ::Protocol::Channel::FlowOk)
18
- ch.flow(false).should be_instance_of(AMQ::Protocol::Channel::FlowOk)
19
- ch.flow(true).should be_instance_of(AMQ::Protocol::Channel::FlowOk)
15
+ subject do
16
+ connection.create_channel
17
+ end
18
+
19
+ it "is supported" do
20
+ subject.flow(true).should be_instance_of(AMQ::Protocol::Channel::FlowOk)
21
+ subject.flow(false).should be_instance_of(AMQ::Protocol::Channel::FlowOk)
22
+ subject.flow(true).should be_instance_of(AMQ::Protocol::Channel::FlowOk)
20
23
  end
21
24
  end
@@ -7,42 +7,51 @@ describe Bunny::Channel, "when opened" 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
 
14
14
  context "without explicitly provided id" do
15
+ subject do
16
+ connection.create_channel
17
+ end
18
+
15
19
  it "gets an allocated id and is successfully opened" do
16
20
  connection.should be_connected
17
- ch = connection.create_channel
18
- ch.should be_open
21
+ subject.should be_open
19
22
 
20
- ch.id.should be > 0
23
+ subject.id.should be > 0
21
24
  end
22
25
  end
23
26
 
24
27
 
25
28
  context "with explicitly provided id" do
29
+ subject do
30
+ connection.create_channel(767)
31
+ end
32
+
26
33
  it "uses that id and is successfully opened" do
27
- ch = connection.create_channel(767)
28
34
  connection.should be_connected
29
- ch.should be_open
35
+ subject.should be_open
30
36
 
31
- ch.id.should == 767
37
+ subject.id.should == 767
32
38
  end
33
39
  end
34
40
 
35
41
 
36
42
 
37
43
  context "with explicitly provided id that is already taken" do
44
+ subject do
45
+ connection.create_channel(767)
46
+ end
47
+
38
48
  it "reuses the channel that is already opened" do
39
- ch = connection.create_channel(767)
40
49
  connection.should be_connected
41
- ch.should be_open
50
+ subject.should be_open
42
51
 
43
- ch.id.should == 767
52
+ subject.id.should == 767
44
53
 
45
- connection.create_channel(767).should == ch
54
+ connection.create_channel(767).should == subject
46
55
  end
47
56
  end
48
57
  end