test/adapters/bunny_test.rb in message_queue-0.0.4 vs test/adapters/bunny_test.rb in message_queue-0.1.0

- old
+ new

@@ -10,73 +10,88 @@ :tls_certificates => ["path"]) assert_equal "amqp", connection.settings[:scheme] assert_equal ["path"], connection.settings[:tls_certificates] connection = MessageQueue::Adapters::Bunny.new_connection MessageQueue::Serializers::Plain - bunny = connection.connect - assert bunny.open? + connection.connect + assert connection.connected? connection.disconnect - assert bunny.closed? + assert !connection.connected? end - def test_new_publisher + def test_new_producer connection = MessageQueue::Adapters::Bunny.new_connection MessageQueue::Serializers::Plain connection.with_connection do |conn| - publisher = conn.new_publisher( + producer = conn.new_producer( :exchange => { - :name => "test", - :type => :direct + :name => "test_producer", + :type => :direct, + :auto_delete => true }, :message => { - :routing_key => "test" + :routing_key => "test_producer" } ) - assert_equal "test", publisher.exchange_name - assert_equal :direct, publisher.exchange_type - assert_equal "test", publisher.message_options[:routing_key] + assert_equal "test_producer", producer.exchange_name + assert_equal :direct, producer.exchange_type + assert_equal "test_producer", producer.message_options[:routing_key] + ch = connection.connection.create_channel + queue = ch.queue("test_producer", :auto_delete => true).bind("test_producer", :routing_key => "test_producer") + + @payload = nil + queue.subscribe do |_, _, payload| + @payload = payload + end + msg = Time.now.to_s - publisher.publish msg + producer.publish msg - ch = connection.connection.create_channel - queue = ch.queue("test") - _, _, m = queue.pop + sleep 1 - assert_equal msg, m + assert_equal msg, @payload end end def test_new_consumer connection = MessageQueue::Adapters::Bunny.new_connection MessageQueue::Serializers::Plain connection.with_connection do |conn| + producer = conn.new_producer( + :exchange => { + :name => "test_consumer", + :type => :direct, + :auto_delete => true + }, + :message => { + :routing_key => "test_consumer" + } + ) + consumer = conn.new_consumer( :queue => { - :name => "test" + :name => "test_consumer", + :auto_delete => true }, :exchange => { - :name => "test" + :name => "test_consumer" } ) - assert_equal "test", consumer.queue_name - assert_equal "test", consumer.exchange_name + assert_equal "test_consumer", consumer.queue_name + assert_equal "test_consumer", consumer.exchange_name - publisher = conn.new_publisher( - :exchange => { - :name => "test", - :type => :direct - }, - :message => { - :routing_key => "test" - } - ) + @payload = nil + consumer.subscribe do |message| + @payload = message.payload + end msg = Time.now.to_s - publisher.publish msg + producer.publish msg, :type => :foo - _, _, m = consumer.queue.pop - assert_equal msg, m + sleep 1 + + assert_equal msg, @payload end end end