Business-OCV

 view release on metacpan or  search on metacpan

utilities/ocvtest  view on Meta::CPAN

#!/usr/bin/perl -w
# (should also use taint mode (-T) for production)
#
# ocvtest.pl
#
#  Show a couple of test transactions to the (development) OCV server, 
# using both blocking (non-polled) and polled modes.
# Note the test OCV server (at least v1.15) does not respond well to polled 
# requests, see usage() below.

use strict;

use POSIX;

# load the module and import all constants
use OCV;

use constant CLIENTID => 'ocvtest';	# up to 8 chars

# to avoid confusion with the live server, the test server should always be 
# run on a different port than a live server
use constant PORT		=> 53995;	# my 'standard' test port

use constant TIMEOUT	=> 15;		# OCV send/recv timeout (seconds)
use constant BUSYWAIT	=> 2;		# OCV SERVER BUSY - (avg) wait time
use constant BUSYATTEMPTS	=> 2;	# OCV SERVER BUSY - number of attempts

use constant LOGDIR		=> './var';	# link to OCV txn log dir
use constant TXNLOG		=> 'test.txnlog';
use constant DEBUGLOG	=> 'test.debuglog';
use constant TRUNCATE	=> 0;	# truncate logs?

my $server = shift;
my $accountnum = shift;
my $polled = shift;

STDOUT->autoflush(1);
STDERR->autoflush(1);

die "usage: $0 <development server<:port>> <account number> <polled mode>\n" 
	unless ($server and $accountnum);

# create an OCV object

$server = $server . ':' . PORT unless $server =~ /:\d+/;

print <<EOM;

OCV Arguments

          Server: $server          (standard test port = ${\PORT})
  Account Number: $accountnum

         Timeout: ${\TIMEOUT} s
       BUSY Wait: ${\BUSYWAIT} s
   BUSY Attempts: ${\BUSYATTEMPTS}

       Client ID: ${\CLIENTID}

   Log Directory: ${\LOGDIR}
 Transaction Log: ${\TXNLOG}
       Debug Log: ${\DEBUGLOG}
    Logs will be: ${TRUNCATE ? \'truncated' : \'appended'}

 Polled/Blocking: ${$polled ? \'POLLED' : \'BLOCKING'}

NOTES:
  - you should adjust the OCV simulated service time to say < 500ms for
    this test (unless you have all day :-)

EOM

print <<EOM if $polled;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NOTE: the test OCV server (at least v1.15) does not respond well to polled 
requests. It 'locks' the account after serving some polled requests (i.e. 
subsequent transactions on the account return SERVER BUSY or RECORD NOT FOUND).
In addition, on subsequent connections it erroneously sends a response to the 
polled request which missynchronises the rest of the communications.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

EOM

# the OCV always appends to its logs, so manually truncate them if required
# - create/truncate the log files now, so as to allow them to be tailed 
#   before starting the test
map { my $f = LOGDIR . $_; open (FH, TRUNCATE ? ">$f" : ">>$f") }
	TXNLOG, DEBUGLOG;
close FH;

$server =~ /:(\d+)/;
if ($1 != PORT)
{
	print "Are you sure you want to use a non-'standard' test port? [yN] ";
	exit 1 unless (<STDIN> =~ /y/i);
}
else
{
	print "Press enter to continue, Ctrl-C to quit...";
	<STDIN>;
}

my $ocv = new OCV (Server => $server, ClientID => CLIENTID, 
		AccountNum => $accountnum, timeout => TIMEOUT, 
		BusyWait => BUSYWAIT, BusyAttempts => BUSYATTEMPTS,
		LogDir => LOGDIR, TxnLog => TXNLOG, DebugLog => DEBUGLOG, 
		debug => 1)
	or die "Could not create OCV object: $@\n";

# set the Transaction Reference number generator
# - the OCV allows a 16 character field for the transaction reference
# - basically a client identifier string, a hex-encoded time (32 bits == 8 hex
#   digits), and a sequence number.
my $sn = 0;



( run in 2.055 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )