Crixa
view release on metacpan or search on metacpan
t/lib/Test/Role/Crixa.pm view on Meta::CPAN
package Test::Role::Crixa;
use strict;
use warnings;
use namespace::autoclean;
use Crixa;
use Crixa::Message;
use Math::BigInt ();
use Math::UInt64 qw( uint64 );
use Test::Fatal qw( exception );
use Test::More;
use Try::Tiny;
use Moose::Role;
requires qw(
_build_crixa
);
has crixa => (
is => 'ro',
isa => 'Crixa',
lazy => 1,
builder => '_build_crixa',
);
# Using test_setup/teardown would be much more complicated, as we'd have to
# temporarily store the exchange & queue in an object attribute and then clear
# them.
my @test_methods = qw(
test_handle_message
test_check_for_message
test_wait_for_message
test_message_count
test_consume
test_consume_with_timeout
test_partial_consume
);
around \@test_methods => sub {
my $orig = shift;
my $self = shift;
my $exchange = $self->_channel()->exchange(
name => $self->_fq_name('order'),
);
my $queue = $exchange->queue(
name => $self->_fq_name('new-orders'),
routing_keys => ['order.new']
);
try {
$self->$orig( $exchange, $queue );
}
catch {
die $_;
}
finally {
$queue->delete( { if_unused => 0, if_empty => 0 } );
$exchange->delete( { if_unused => 0 } );
};
};
sub test_handle_message {
my $self = shift;
my $exchange = shift;
my $queue = shift;
for my $i ( 1 .. 2 ) {
my $body = 'body-' . $i;
$exchange->publish( { routing_key => 'order.new', body => $body } );
( run in 0.738 second using v1.01-cache-2.11-cpan-54e63673c56 )