amq-client 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.gitmodules +9 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/CONTRIBUTORS +3 -0
- data/Gemfile +27 -0
- data/LICENSE +20 -0
- data/README.textile +61 -0
- data/amq-client.gemspec +34 -0
- data/bin/jenkins.sh +23 -0
- data/bin/set_test_suite_realms_up.sh +24 -0
- data/examples/coolio_adapter/basic_consume.rb +49 -0
- data/examples/coolio_adapter/basic_consume_with_acknowledgements.rb +43 -0
- data/examples/coolio_adapter/basic_consume_with_rejections.rb +43 -0
- data/examples/coolio_adapter/basic_publish.rb +35 -0
- data/examples/coolio_adapter/channel_close.rb +24 -0
- data/examples/coolio_adapter/example_helper.rb +39 -0
- data/examples/coolio_adapter/exchange_declare.rb +28 -0
- data/examples/coolio_adapter/kitchen_sink1.rb +48 -0
- data/examples/coolio_adapter/queue_bind.rb +32 -0
- data/examples/coolio_adapter/queue_purge.rb +32 -0
- data/examples/coolio_adapter/queue_unbind.rb +37 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_custom_role_credentials.rb +36 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_default_role_credentials.rb +27 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_incorrect_credentials.rb +18 -0
- data/examples/eventmachine_adapter/basic_cancel.rb +49 -0
- data/examples/eventmachine_adapter/basic_consume.rb +51 -0
- data/examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb +45 -0
- data/examples/eventmachine_adapter/basic_consume_with_rejections.rb +45 -0
- data/examples/eventmachine_adapter/basic_get.rb +57 -0
- data/examples/eventmachine_adapter/basic_get_with_empty_queue.rb +53 -0
- data/examples/eventmachine_adapter/basic_publish.rb +38 -0
- data/examples/eventmachine_adapter/basic_qos.rb +29 -0
- data/examples/eventmachine_adapter/basic_recover.rb +29 -0
- data/examples/eventmachine_adapter/basic_return.rb +34 -0
- data/examples/eventmachine_adapter/channel_close.rb +24 -0
- data/examples/eventmachine_adapter/channel_flow.rb +36 -0
- data/examples/eventmachine_adapter/channel_level_exception_handling.rb +44 -0
- data/examples/eventmachine_adapter/example_helper.rb +39 -0
- data/examples/eventmachine_adapter/exchange_declare.rb +54 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/handling_confirm_select_ok.rb +31 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +56 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_unroutable_message.rb +46 -0
- data/examples/eventmachine_adapter/kitchen_sink1.rb +50 -0
- data/examples/eventmachine_adapter/queue_bind.rb +32 -0
- data/examples/eventmachine_adapter/queue_declare.rb +34 -0
- data/examples/eventmachine_adapter/queue_purge.rb +32 -0
- data/examples/eventmachine_adapter/queue_unbind.rb +37 -0
- data/examples/eventmachine_adapter/tx_commit.rb +29 -0
- data/examples/eventmachine_adapter/tx_rollback.rb +29 -0
- data/examples/eventmachine_adapter/tx_select.rb +27 -0
- data/examples/socket_adapter/basics.rb +19 -0
- data/examples/socket_adapter/connection.rb +53 -0
- data/examples/socket_adapter/multiple_connections.rb +17 -0
- data/irb.rb +66 -0
- data/lib/amq/client.rb +15 -0
- data/lib/amq/client/adapter.rb +356 -0
- data/lib/amq/client/adapters/coolio.rb +221 -0
- data/lib/amq/client/adapters/event_machine.rb +228 -0
- data/lib/amq/client/adapters/socket.rb +89 -0
- data/lib/amq/client/channel.rb +338 -0
- data/lib/amq/client/connection.rb +246 -0
- data/lib/amq/client/entity.rb +117 -0
- data/lib/amq/client/exceptions.rb +86 -0
- data/lib/amq/client/exchange.rb +163 -0
- data/lib/amq/client/extensions/rabbitmq.rb +5 -0
- data/lib/amq/client/extensions/rabbitmq/basic.rb +36 -0
- data/lib/amq/client/extensions/rabbitmq/confirm.rb +254 -0
- data/lib/amq/client/framing/io/frame.rb +32 -0
- data/lib/amq/client/framing/string/frame.rb +62 -0
- data/lib/amq/client/logging.rb +56 -0
- data/lib/amq/client/mixins/anonymous_entity.rb +21 -0
- data/lib/amq/client/mixins/status.rb +62 -0
- data/lib/amq/client/protocol/get_response.rb +55 -0
- data/lib/amq/client/queue.rb +450 -0
- data/lib/amq/client/settings.rb +83 -0
- data/lib/amq/client/version.rb +5 -0
- data/spec/benchmarks/adapters.rb +77 -0
- data/spec/client/framing/io_frame_spec.rb +57 -0
- data/spec/client/framing/string_frame_spec.rb +57 -0
- data/spec/client/protocol/get_response_spec.rb +79 -0
- data/spec/integration/coolio/basic_ack_spec.rb +41 -0
- data/spec/integration/coolio/basic_get_spec.rb +73 -0
- data/spec/integration/coolio/basic_return_spec.rb +33 -0
- data/spec/integration/coolio/channel_close_spec.rb +26 -0
- data/spec/integration/coolio/channel_flow_spec.rb +46 -0
- data/spec/integration/coolio/spec_helper.rb +31 -0
- data/spec/integration/coolio/tx_commit_spec.rb +40 -0
- data/spec/integration/coolio/tx_rollback_spec.rb +44 -0
- data/spec/integration/eventmachine/basic_ack_spec.rb +40 -0
- data/spec/integration/eventmachine/basic_get_spec.rb +73 -0
- data/spec/integration/eventmachine/basic_return_spec.rb +35 -0
- data/spec/integration/eventmachine/channel_close_spec.rb +26 -0
- data/spec/integration/eventmachine/channel_flow_spec.rb +32 -0
- data/spec/integration/eventmachine/spec_helper.rb +22 -0
- data/spec/integration/eventmachine/tx_commit_spec.rb +47 -0
- data/spec/integration/eventmachine/tx_rollback_spec.rb +35 -0
- data/spec/regression/bad_frame_slicing_in_adapters_spec.rb +59 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/unit/client/adapter_spec.rb +49 -0
- data/spec/unit/client/entity_spec.rb +49 -0
- data/spec/unit/client/logging_spec.rb +60 -0
- data/spec/unit/client/mixins/status_spec.rb +72 -0
- data/spec/unit/client/settings_spec.rb +27 -0
- data/spec/unit/client_spec.rb +11 -0
- data/tasks.rb +11 -0
- metadata +202 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/coolio/spec_helper'
|
3
|
+
|
4
|
+
describe "AMQ::Client::Coolio", "Basic.Return", :nojruby => true do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1.0
|
7
|
+
|
8
|
+
context "when messages are sent to a direct exchange not bound to a queue" do
|
9
|
+
let(:messages) { (0..9).map {|i| "Message #{i}" } }
|
10
|
+
|
11
|
+
it "should return all the messages" do
|
12
|
+
@returned_messages = []
|
13
|
+
coolio_amqp_connect do |client|
|
14
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
15
|
+
channel.open do
|
16
|
+
queue = AMQ::Client::Queue.new(client, channel).declare(false, false, false, true)
|
17
|
+
|
18
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "direct-exchange", :direct).declare.on_return do |method|
|
19
|
+
@returned_messages << method.reply_text
|
20
|
+
end
|
21
|
+
|
22
|
+
messages.each do |message|
|
23
|
+
exchange.publish(message, AMQ::Protocol::EMPTY_STRING, {}, false, true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
done(0.6) { @returned_messages.size == messages.size }
|
28
|
+
end
|
29
|
+
|
30
|
+
@returned_messages.should == ["NO_CONSUMERS"] * messages.size
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/coolio/spec_helper'
|
3
|
+
|
4
|
+
describe "AMQ::Client::Coolio", "Channel.Close", :nojruby => true do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1
|
7
|
+
|
8
|
+
it "should close the channel" do
|
9
|
+
@events = []
|
10
|
+
coolio_amqp_connect do |client|
|
11
|
+
@events << :connect
|
12
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
13
|
+
channel.open do
|
14
|
+
@events << :open
|
15
|
+
channel.close do
|
16
|
+
@events << :close
|
17
|
+
client.disconnect do
|
18
|
+
@events << :disconnect
|
19
|
+
done
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@events.should == [:connect, :open, :close, :disconnect]
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/coolio/spec_helper'
|
3
|
+
|
4
|
+
describe "AMQ::Client::Coolio", "Channel.Flow", :nojruby => true do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1
|
7
|
+
|
8
|
+
it "should control the flow of channel" do
|
9
|
+
coolio_amqp_connect do |client|
|
10
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
11
|
+
channel.open do
|
12
|
+
AMQ::Client::Queue.new(client, channel).declare(false, false, false, true) do |q, _, _, _|
|
13
|
+
channel.flow_is_active?.should be_true
|
14
|
+
channel.flow(false) do |_, flow_active|
|
15
|
+
flow_active.should be_false
|
16
|
+
channel.flow(true) do |_, flow_active|
|
17
|
+
flow_active.should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
done
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
it "should not raise errors when no state change occurs" do
|
28
|
+
coolio_amqp_connect do |client|
|
29
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
30
|
+
expect {
|
31
|
+
channel.open do
|
32
|
+
AMQ::Client::Queue.new(client, channel).declare(false, false, false, true) do |q, _, _, _|
|
33
|
+
channel.flow_is_active?.should be_true
|
34
|
+
channel.flow(false) do |_, flow_active|
|
35
|
+
flow_active.should be_false
|
36
|
+
channel.flow(false) do |_, flow_active|
|
37
|
+
flow_active.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
done
|
41
|
+
end
|
42
|
+
end
|
43
|
+
}.to_not raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
begin
|
2
|
+
require "amq/client/adapters/coolio"
|
3
|
+
rescue LoadError => e
|
4
|
+
if RUBY_PLATFORM =~ /java/
|
5
|
+
puts "WARNING: Cool.io specs will not run on jruby"
|
6
|
+
else
|
7
|
+
# reraise, cause unknown
|
8
|
+
raise e
|
9
|
+
end
|
10
|
+
end
|
11
|
+
require "amq/client/queue"
|
12
|
+
require "amq/client/exchange"
|
13
|
+
require "evented-spec"
|
14
|
+
|
15
|
+
case RUBY_VERSION
|
16
|
+
when "1.8.7" then
|
17
|
+
class Array
|
18
|
+
alias sample choice
|
19
|
+
end
|
20
|
+
when /^1.9/ then
|
21
|
+
Encoding.default_internal = Encoding::UTF_8
|
22
|
+
Encoding.default_external = Encoding::UTF_8
|
23
|
+
end
|
24
|
+
|
25
|
+
def coolio_amqp_connect(&block)
|
26
|
+
coolio do
|
27
|
+
AMQ::Client::Coolio.connect(:port => 5672, :vhost => "/amq_client_testbed", :frame_max => 2**16-1, :heartbeat_interval => 1) do |client|
|
28
|
+
yield client
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'integration/coolio/spec_helper'
|
4
|
+
|
5
|
+
describe "AMQ::Client::Coolio", "Tx.Commit", :nojruby => true do
|
6
|
+
include EventedSpec::SpecHelper
|
7
|
+
default_timeout 2
|
8
|
+
let(:message) { "Hello, world!" }
|
9
|
+
|
10
|
+
|
11
|
+
#
|
12
|
+
# Examples
|
13
|
+
#
|
14
|
+
|
15
|
+
it "should confirm transaction completeness" do
|
16
|
+
received_messages = []
|
17
|
+
coolio_amqp_connect do |client|
|
18
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
19
|
+
channel.open do
|
20
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
21
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
22
|
+
|
23
|
+
queue.declare(false, false, false, true) do
|
24
|
+
queue.bind(exchange)
|
25
|
+
end
|
26
|
+
|
27
|
+
channel.tx_select do
|
28
|
+
queue.consume(true) do |header, payload, delivery_tag, redelivered, exchange, routing_key, message_count|
|
29
|
+
received_messages << message
|
30
|
+
done
|
31
|
+
end
|
32
|
+
|
33
|
+
exchange.publish(message)
|
34
|
+
channel.tx_commit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
received_messages.should == [message]
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'integration/coolio/spec_helper'
|
4
|
+
|
5
|
+
describe "AMQ::Client::Coolio", "Tx.Rollback", :nojruby => true do
|
6
|
+
include EventedSpec::SpecHelper
|
7
|
+
default_timeout 2
|
8
|
+
|
9
|
+
let(:message) { "Hello, world!" }
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
#
|
14
|
+
# Examples
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
it "should cancel all the changes done during transaction" do
|
19
|
+
received_messages = []
|
20
|
+
coolio_amqp_connect do |client|
|
21
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
22
|
+
channel.open do
|
23
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
24
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
25
|
+
|
26
|
+
queue.declare(false, false, false, true) do
|
27
|
+
queue.bind(exchange)
|
28
|
+
end
|
29
|
+
|
30
|
+
channel.tx_select do
|
31
|
+
done(0.1)
|
32
|
+
queue.consume(true) do |method, header, message|
|
33
|
+
received_messages << message unless message.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
exchange.publish(message)
|
37
|
+
channel.tx_rollback
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
received_messages.should == []
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/eventmachine/spec_helper'
|
3
|
+
|
4
|
+
describe AMQ::Client::EventMachineClient, "Basic.Ack" do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 4
|
7
|
+
|
8
|
+
context "sending 100 messages" do
|
9
|
+
let(:messages) { (0..99).map {|i| "Message #{i}" } }
|
10
|
+
|
11
|
+
it "should receive all the messages" do
|
12
|
+
@received_messages = []
|
13
|
+
em_amqp_connect do |client|
|
14
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
15
|
+
channel.open do
|
16
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
17
|
+
queue.declare
|
18
|
+
|
19
|
+
queue.bind("amq.fanout")
|
20
|
+
|
21
|
+
queue.consume do |amq_method|
|
22
|
+
queue.on_delivery do |method, header, payload|
|
23
|
+
queue.acknowledge(method.delivery_tag)
|
24
|
+
@received_messages << payload
|
25
|
+
end
|
26
|
+
|
27
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
28
|
+
messages.each do |message|
|
29
|
+
exchange.publish(message)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
done(2.5) {
|
34
|
+
@received_messages.size == messages.size
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/eventmachine/spec_helper'
|
3
|
+
|
4
|
+
describe AMQ::Client::EventMachineClient, "Basic.Get" do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1
|
7
|
+
|
8
|
+
context "when set two messages beforehand" do
|
9
|
+
let(:messages) { ["message 1", "message 2"] }
|
10
|
+
|
11
|
+
it "synchronously fetches all the messages" do
|
12
|
+
@received_messages = []
|
13
|
+
em_amqp_connect do |client|
|
14
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
15
|
+
|
16
|
+
channel.open do
|
17
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
18
|
+
queue.declare(false, false, false, true) do
|
19
|
+
queue.bind("amq.fanout")
|
20
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
21
|
+
|
22
|
+
messages.each do |message|
|
23
|
+
exchange.publish(message) do
|
24
|
+
puts "Published a message: #{message}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
queue.get(true) do |method, header, payload|
|
29
|
+
puts "Got #{payload}"
|
30
|
+
@received_messages << payload
|
31
|
+
end
|
32
|
+
queue.get(true) do |method, header, payload|
|
33
|
+
puts "Got #{payload}"
|
34
|
+
@received_messages << payload
|
35
|
+
end
|
36
|
+
|
37
|
+
done(0.6) {
|
38
|
+
@received_messages.should =~ messages
|
39
|
+
|
40
|
+
queue.purge
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
context "when sent no messages beforehand" do
|
50
|
+
it "should receive nils" do
|
51
|
+
em_amqp_connect do |client|
|
52
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
53
|
+
channel.open do
|
54
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
55
|
+
queue.declare(false, false, false, true)
|
56
|
+
queue.bind("amq.fanout")
|
57
|
+
|
58
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
59
|
+
|
60
|
+
queue.get(true) do |method, header, payload|
|
61
|
+
header.should be_nil
|
62
|
+
payload.should be_nil
|
63
|
+
|
64
|
+
done {
|
65
|
+
queue.purge
|
66
|
+
}
|
67
|
+
end # get
|
68
|
+
end
|
69
|
+
end # em_amqp_connect
|
70
|
+
end # it
|
71
|
+
|
72
|
+
end # context
|
73
|
+
end # describe
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/eventmachine/spec_helper'
|
3
|
+
|
4
|
+
describe AMQ::Client::EventMachineClient, "Basic.Return" do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1.0
|
7
|
+
|
8
|
+
context "when messages are sent to a direct exchange not bound to a queue" do
|
9
|
+
let(:messages) { (0..9).map {|i| "Message #{i}" } }
|
10
|
+
|
11
|
+
it "should return all the messages" do
|
12
|
+
@returned_messages = []
|
13
|
+
em_amqp_connect do |client|
|
14
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
15
|
+
channel.open do
|
16
|
+
queue = AMQ::Client::Queue.new(client, channel).declare(false, false, false, true)
|
17
|
+
|
18
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "direct-exchange", :direct).declare.on_return do |method|
|
19
|
+
@returned_messages << method.reply_text
|
20
|
+
end
|
21
|
+
|
22
|
+
messages.each do |message|
|
23
|
+
exchange.publish(message, AMQ::Protocol::EMPTY_STRING, {}, false, true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
done(0.6) {
|
28
|
+
@returned_messages.size == messages.size
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
@returned_messages.should == ["NO_CONSUMERS"] * messages.size
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/eventmachine/spec_helper'
|
3
|
+
|
4
|
+
describe AMQ::Client::EventMachineClient, "Channel.Close" do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1
|
7
|
+
|
8
|
+
it "should close the channel" do
|
9
|
+
@events = []
|
10
|
+
em_amqp_connect do |client|
|
11
|
+
@events << :connect
|
12
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
13
|
+
channel.open do
|
14
|
+
@events << :open
|
15
|
+
channel.close do
|
16
|
+
@events << :close
|
17
|
+
client.disconnect do
|
18
|
+
@events << :disconnect
|
19
|
+
done
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@events.should == [:connect, :open, :close, :disconnect]
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/eventmachine/spec_helper'
|
3
|
+
|
4
|
+
describe AMQ::Client::EventMachineClient, "Channel#flow" do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1
|
7
|
+
|
8
|
+
it "controls channel flow state" do
|
9
|
+
em_amqp_connect do |client|
|
10
|
+
flow_states = []
|
11
|
+
|
12
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
13
|
+
channel.open do
|
14
|
+
AMQ::Client::Queue.new(client, channel).declare(false, false, false, true) do |amq_method|
|
15
|
+
channel.flow_is_active?.should be_true
|
16
|
+
|
17
|
+
channel.flow(false) do |flow_status1|
|
18
|
+
channel.flow_is_active?.should be_false
|
19
|
+
flow_states << channel.flow_is_active?
|
20
|
+
|
21
|
+
channel.flow(true) do |flow_status2|
|
22
|
+
channel.flow_is_active?.should be_true
|
23
|
+
flow_states << channel.flow_is_active?
|
24
|
+
end # channel.flow
|
25
|
+
end # channel.flow
|
26
|
+
end # Queue.new
|
27
|
+
end # channel.open
|
28
|
+
|
29
|
+
done(0.5) { flow_states.should == [false, true] }
|
30
|
+
end # em_amqp_connect
|
31
|
+
end # it
|
32
|
+
end # describe
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "amq/client/adapters/event_machine"
|
2
|
+
require "amq/client/queue"
|
3
|
+
require "amq/client/exchange"
|
4
|
+
require "evented-spec"
|
5
|
+
|
6
|
+
case RUBY_VERSION
|
7
|
+
when "1.8.7" then
|
8
|
+
class Array
|
9
|
+
alias sample choice
|
10
|
+
end
|
11
|
+
when /^1.9/ then
|
12
|
+
Encoding.default_internal = Encoding::UTF_8
|
13
|
+
Encoding.default_external = Encoding::UTF_8
|
14
|
+
end
|
15
|
+
|
16
|
+
def em_amqp_connect(&block)
|
17
|
+
em do
|
18
|
+
AMQ::Client::EventMachineClient.connect(:port => 5672, :vhost => "/amq_client_testbed", :frame_max => 65536, :heartbeat_interval => 1) do |client|
|
19
|
+
yield client
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|