[libanyevent-rabbitmq-perl] 20/151: Added a test for multi channel.

Damyan Ivanov dmn at moszumanska.debian.org
Thu Jan 16 11:03:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

dmn pushed a commit to annotated tag debian/1.12-1
in repository libanyevent-rabbitmq-perl.

commit 6d26b1524ccd8689cad909528ca40f2f35e86306
Author: cooldaemon <cooldaemon at gmail.com>
Date:   Thu Feb 11 21:37:53 2010 +0900

    Added a test for multi channel.
---
 xt/06_multi_channel.t | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/xt/06_multi_channel.t b/xt/06_multi_channel.t
new file mode 100644
index 0000000..5a723fa
--- /dev/null
+++ b/xt/06_multi_channel.t
@@ -0,0 +1,88 @@
+use Test::More;
+use Test::Exception;
+
+use FindBin;
+use JSON::Syck;
+
+my $conf = JSON::Syck::LoadFile($FindBin::Bin . '/../config.json');
+
+eval {
+    use IO::Socket::INET;
+
+    my $socket = IO::Socket::INET->new(
+        Proto    => 'tcp',
+        PeerAddr => $conf->{host},
+        PeerPort => $conf->{port},
+        Timeout  => 1,
+    ) or die 'Error connecting to AMQP Server!';
+
+    close $socket;
+};
+
+plan skip_all => 'Connection failure: '
+               . $conf->{host} . ':' . $conf->{port} if $@;
+plan tests => 6;
+
+use Coro;
+use RabbitFoot;
+
+my $rf = RabbitFoot->new(
+    timeout => 1,
+)->load_xml_spec(
+    $FindBin::Bin . '/../fixed_amqp0-8.xml',
+)->connect(
+    (map {$_ => $conf->{$_}} qw(host port user pass vhost))
+);
+
+my $main = $Coro::current;
+my $done = 0;
+
+my @queues = map {
+    my $queue = 'test_q' . $_;
+    my $ch = $rf->open_channel();
+    isa_ok($ch, 'RabbitFoot::Channel');
+
+    $ch->declare_queue(queue => $queue);
+
+    my $frame; $frame = $ch->consume(
+        queue      => $queue,
+        on_consume => unblock_sub {
+            my $response = shift;
+            return if 'stop' ne $response->{body}->payload;
+
+            $ch->cancel(consumer_tag => $frame->method_frame->consumer_tag);
+            $done++;
+            $main->ready;
+            schedule;
+        },
+    );
+
+    $queue;
+} (1 .. 5);
+
+my $ch = $rf->open_channel();
+for my $queue (@queues) {
+    publish($ch, $queue, 'Hello Coro.');
+    publish($ch, $queue, 'stop');
+}
+schedule while $done < 5;
+
+is($done, 5, 'consume count');
+
+$ch->delete_queue(queue => $_) for @queues;
+
+$rf->close;
+
+sub publish {
+    my ($ch, $queue, $message,) = @_;
+
+    $ch->publish(
+        routing_key => $queue,
+        body        => $message,
+        mandatory   => 1,
+        on_return   => unblock_sub {die Dumper(@_);},
+    );
+
+    return;
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libanyevent-rabbitmq-perl.git



More information about the Pkg-perl-cvs-commits mailing list