3 # $Id: test-zoom.pl,v 1.2 2007-02-26 14:48:52 mike Exp $
5 # Run the same way as "test-pod.pl". This is supposed to be an
6 # exactly equivalent program but written using the ZOOM-Perl
7 # asynchronous-event API directly rather than through the intermediary
16 printf STDERR "Usage: $0 <target1> [<target2> ...]\n";
20 ZOOM::Log::mask_str("appl");
22 my %rs; # maps connection to result-set
23 my %state; # maps connection to app. state structure
24 foreach my $target (@ARGV) {
25 my $conn = new ZOOM::Connection($target, 0, async => 1,
26 elementSetName => "b");
28 $rs{$conn} = $conn->search_pqf("the");
32 while ((my $i = ZOOM::event(\@conn)) != 0) {
33 my $conn = $conn[$i-1];
34 my $ev = $conn->last_event();
35 my $evstr = ZOOM::event_str($ev);
36 ZOOM::Log::log("pod", "connection ", $i-1, ": event $ev ($evstr)");
37 $conn->check(); # die if any errors occur
39 if ($ev == ZOOM::Event::RECV_SEARCH) {
40 $res = completed_search($conn, \%state, $rs{$conn}, $ev);
41 die "recieve search failed with error $res" if $res;
42 } elsif ($ev == ZOOM::Event::RECV_RECORD) {
43 $res = got_record($conn, \%state, $rs{$conn}, $ev);
44 die "recieve record failed with error $res" if $res;
51 sub completed_search {
52 my($conn, $arg, $rs, $event) = @_;
54 my $host = $conn->option("host");
55 print "$host : found ", $rs->size(), " records\n";
56 my %state = (next_to_show => 0, next_to_fetch => 0);
57 request_records($conn, $rs, \%state, 2);
58 $arg->{$host} = \%state;
63 my($conn, $arg, $rs, $event) = @_;
65 my $host = $conn->option("host");
66 my $state = $arg->{$host};
69 # Sanity-checking assertions. These should be impossible
70 my $ns = $state->{next_to_show};
71 my $nf = $state->{next_to_fetch};
73 die "next_to_show > next_to_fetch ($ns > $nf)";
74 } elsif ($ns == $nf) {
75 die "next_to_show == next_to_fetch ($ns)";
79 my $i = $state->{next_to_show}++;
80 my $rec = $rs->record($i);
81 print "$host: record $i is ", render_record($rec), "\n";
82 request_records($conn, $rs, $state, 3)
83 if $i == $state->{next_to_fetch}-1;
89 my($conn, $rs, $state, $count) = @_;
91 my $i = $state->{next_to_fetch};
92 ZOOM::Log::log("appl", "requesting $count records from $i for ",
93 $conn->option("host"));
94 $rs->records($i, $count, 0);
95 $state->{next_to_fetch} += $count;
101 return "undefined" if !defined $rec;
102 return "'" . $rec->render() . "'";