[libmessage-passing-zeromq-perl] 04/78: Get the ZMQ input working with trivial tests
Jonas Smedegaard
js at alioth.debian.org
Mon Sep 30 09:28:16 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libmessage-passing-zeromq-perl.
commit 4f8e976cdd6625c8aaf9fe9c2c1d073ea0365776
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Sat Feb 25 11:07:23 2012 +0000
Get the ZMQ input working with trivial tests
---
lib/Log/Stash/Input/ZeroMQ.pm | 3 ++-
t/input.t | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/lib/Log/Stash/Input/ZeroMQ.pm b/lib/Log/Stash/Input/ZeroMQ.pm
index cd0682a..c25554a 100644
--- a/lib/Log/Stash/Input/ZeroMQ.pm
+++ b/lib/Log/Stash/Input/ZeroMQ.pm
@@ -3,6 +3,7 @@ use Moose;
use ZeroMQ qw/:all/;
use AnyEvent;
use Scalar::Util qw/ weaken /;
+use Try::Tiny qw/ try catch /;
use namespace::autoclean;
with 'Log::Stash::Mixin::Input';
@@ -40,7 +41,7 @@ sub _try_rx {
my $self = shift();
my $msg = $self->_zmq_recv(ZMQ_NOBLOCK);
if ($msg) {
- my $data = try { $self->decode($msg) }
+ my $data = try { $self->decode($msg->data) }
catch { warn $_ };
$self->output_to->consume($data);
}
diff --git a/t/input.t b/t/input.t
new file mode 100644
index 0000000..90b1981
--- /dev/null
+++ b/t/input.t
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+use Test::More;
+
+use AnyEvent;
+use Log::Stash::Input::ZeroMQ;
+use Log::Stash::Output::Test;
+use ZeroMQ qw/:all/;
+
+my $output = Log::Stash::Output::Test->new();
+my $input = Log::Stash::Input::ZeroMQ->new(
+ output_to => $output,
+);
+ok $input;
+
+my $ctx = ZeroMQ::Context->new();
+my $socket = $ctx->socket(ZMQ_PUB);
+$socket->connect('tcp://127.0.0.1:5558');
+
+$socket->send('{"message":"foo"}');
+
+my $cv = AnyEvent->condvar;
+my $t = AnyEvent->timer(after => 2, cb => sub { $cv->send });
+$cv->recv;
+
+is $output->messages_count, 1;
+
+is_deeply [$output->messages], [{message => "foo"}];
+
+done_testing;
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmessage-passing-zeromq-perl.git
More information about the Pkg-perl-cvs-commits
mailing list