]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/circ_load.pl
Fix empty statuses filter
[working/Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / circ_load.pl
1 #!/usr/bin/perl
2 require '../oils_header.pl';
3 use vars qw/ $authtoken /;
4 use strict; use warnings;
5 use Time::HiRes qw/time usleep/;
6
7 #------------------------------------------------------------------------
8 err("\nusage: $0 <config> <oils_login_username> ".
9         "<oils_login_password> <patronid> <barcode_file> ".
10         "<num_iterations> <num_processes> <barcode_file> ".
11         "is a file with a single copy barcode per line") unless $ARGV[6];
12 #------------------------------------------------------------------------
13
14 my $config              = shift; 
15 my $username    = shift;
16 my $password    = shift;
17 my $patronid    = shift;
18 my $barcodes    = shift;
19 my $numiters    = shift;
20 my $numprocs    = shift;
21
22 open(F,$barcodes);
23 my @BARCODES = <F>;
24 close(F);
25
26 $numprocs = ($numprocs and $numprocs < 50) ? $numprocs : 1;
27
28 print "start time = " . time . "\n";
29
30 my $index = 0;
31 for(1..($numprocs - 1)) {
32         last if fork();
33         $index++;
34         sleep(2); # this gives auth time to work
35 }
36
37 go($index);
38
39 sub go {
40         my $index = shift;
41         my $barcode = $BARCODES[$index];
42         chomp $barcode;
43
44         osrf_connect($config);
45         oils_login($username, $password);
46
47         printl("$$ running barcode $barcode");
48
49         my $s = time;
50
51         for(1..$numiters) {
52                 my $start = time;
53                 my $key  = do_permit($patronid, $barcode ); 
54                 die "permit failed\n" unless $key;
55                 do_checkout($key, $patronid, $barcode );
56                 printl("checkout time = " . (time - $start));
57                 $start = time;
58                 do_checkin($barcode);
59                 printl("checkin  time = " . (time - $start));
60         }
61
62         print "\nchild $index, iterations = $numiters, ".
63                 "total time = " . (time - $s) . ", current time = " . time . "\n";
64 }
65
66 #----------------------------------------------------------------
67
68 sub do_permit {
69         my( $patronid, $barcode ) = @_;
70
71         my $args = { patron => $patronid, barcode => $barcode };
72
73         my $resp = simplereq( 
74                 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
75
76         oils_event_die($resp);   
77         
78         if( ref($resp) eq 'ARRAY' ) { # we received a list of non-success events
79                 printl("received event: ".$_->{textcode}) for @$resp;
80                 return undef;
81         } 
82
83         return $resp->{payload};
84 }
85
86
87 sub do_checkout {
88         my( $key, $patronid, $barcode ) = @_;
89         my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
90         my $resp = osrf_request(
91                 'open-ils.circ', 
92                 'open-ils.circ.checkout', $authtoken, $args );
93         oils_event_die($resp);
94 }
95
96
97 sub do_checkin {
98         my $barcode  = shift;
99         my $args = { barcode => $barcode };
100         my $resp = simplereq( 
101                 CIRC(), 'open-ils.circ.checkin', $authtoken, $args );
102         oils_event_die($resp);
103         debug($resp) if(ref($resp) eq 'ARRAY');
104 }
105
106