App-Basis-Queue

 view release on metacpan or  search on metacpan

t/02_pubsub.t  view on Meta::CPAN

#!/usr/bin/env perl

=head1 NAME

02_pubsub.t

=head1 DESCRIPTION

perform pubsub tests on App::Basis::Queue
while the tests are setup into subtests, they are not independent of the
preceding tests as the data the preceding tests creates is used in
subsequent ones

=head1 AUTHOR

   kevin mulholland, moodfarm@cpan.org

=cut

use strict ;
use warnings ;
use feature 'state' ;

use Test::More ;
use POSIX qw(strftime) ;
use DBI ;
use Try::Tiny ;
use Time::HiRes qw(gettimeofday tv_interval ) ;

use App::Basis::Queue ;
use Data::Printer ;

BEGIN {
    if ( $ENV{AUTHOR_TESTING} ) {
        plan tests => 5 ;
    } else {
        plan tests => 1 ;
    }
    use_ok('App::Basis::Queue') ;
}


# create a name for the queue we will be testing with, it should not exist!
my $test_q = strftime( "%Y-%m-%d %H:%M:%S", localtime() ) . "_" . $$ . '_' ;
$test_q =~ s/[ :-]/_/g ;
$test_q = 'tst' ;
my $qname       = '/basic_q' ;
my $queue_two   = "$qname/two" ;
my $queue_three = "$qname/three" ;

my ( $queue, $dbh ) ;

# get optional DSN info from the user environment
my $db_loc = "/tmp/queue_simple-pubsub.$test_q.sqlite3" ;
my $dsn
    = $ENV{SQ_DSN}
    ? $ENV{SQ_DSN}
    : "dbi:SQLite:$db_loc" ;
my $user   = $ENV{SQ_USER} ;
my $passwd = $ENV{SQ_PASSWD} ;

# ----------------------------------------------------------------------------

=item query_db

general purpose db query tool, returns all results as a arrayref of hashes
this function was created by kevin outside of home
copyright is retained with him
returns ref to data and a status msg

=cut

sub query_db
{
    my ( $dbh, $query, $p ) = @_ ;
    our @params = $p ? @$p : () ;
    my ( $result, $err, $sth ) ;

    try {
        $sth = $dbh->prepare($query) ;
        my $rv = $sth->execute(@params) ;

        # so as to get an array of hashes
        $result = $sth->fetchall_arrayref( {} ) ;
    }
    catch {} ;
    return $result, $err ;



( run in 2.973 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )