f6606c7d719e6edd20fa488d819a911ce21a32a9
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Example_Bib1.pm
1 # $Id: Example_Bib1.pm,v 1.1 2006-10-02 13:02:58 sondberg Exp $
2
3 # This is an example test probe. The assumptions are:
4
5 # 1. We should reuse as much as possible of the existing framework
6 # 2. Each method is called with a method that inherits from the ZOOM class
7 # 3. The notion of a Pod is dropped, because each connection is completely
8 #    independent.
9 # 4  The wait method should block program execution and control is passed to
10 #    the ZOOM/C layer.
11 # 5. The "handle" property can be more or less institutionalized. But I think
12 #    we need a way to share information between methods and callbacks...
13 # 6. We'll need to discuss how we setup the order in which the tests are
14 #    carried out. I don't like the idea that all connections must be in the
15 #    same test state all the time. I *think* that this can be done multi
16 #    threaded - conceptually (not the perl way of doing threads). Thus the
17 #    method continue(1/0)
18
19 package ZOOM::IRSpy::Test::Search::Example_Bib1;
20
21 use 5.008;
22 use strict;
23 use warnings;
24 use Data::Dumper;
25
26 use ZOOM::IRSpy::Test;
27 our @ISA = qw(ZOOM::IRSpy::Test);
28 our @Bib1_Attr = qw(1 2 3 4 5 6 7 8 9); 
29
30
31 sub run {
32     my $this = shift();         ## Connection object
33     my $irspy = $this->irspy(); ## Each connection shares the irspy object
34
35     ## On your own risk "handle reference" - we simply gonna need that!
36     my $handle = $this->{'handle'};
37
38     ## Callbacks can be overwritten - but they exist in the Test base class
39     ## such that you don't *need* to overwrite them everytime you write a
40     ## new testing module...
41     
42     $this->callback(ZOOM::Event::RECV_SEARCH, \&found);
43
44     foreach my $attr (@Bib1_Attr) {
45         $this->search_pqf('@attr 1=' . $attr . ' water' );
46         $handle->{'bib1_attr'} = $attr;
47         $this->wait();          ## I assume this wait blocks execution!
48     }
49
50     $this->continue(1);         ## Perform the next test in the sequence
51     #$this->continue(0);         ## Perform the next test in the sequence
52
53     return 0;
54 }
55
56
57 sub found {
58     my ($this) = @_;
59     my $irspy = $this->irspy();
60     my $handle = $this->{'handle'};
61     my $bib1_attr = $handle->{'bib1_attr'};
62     my $rs = $this->getResultSet();
63     my $attr = $href->{'attr'};
64     my $n = $rs->size();
65     my $rec = $irspy->record($conn);
66
67     $irspy->log("irspy_test", $conn->option("host"),
68                 " Bib-1 attribute=$attr search found $n record",
69                 $n==1 ? "" : "s");
70
71     $rec->append_entry("irspy:status", "<irspy:search set='bib1' attr='$attr'" .
72                        " ok='1'>" . $irspy->isodate(time()) .
73                        "</irspy:search>");
74     return 0;
75 }
76
77
78
79 1;