Test is BAD if database is unavailable.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Bib1.pm
1 # $Id: Bib1.pm,v 1.17 2007-02-28 17:32:48 mike Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Search::Bib1;
6
7 use 5.008;
8 use strict;
9 use warnings;
10
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
13
14
15 sub start {
16     my $class = shift();
17     my($conn) = @_;
18     my @attrs = ( 1..63, 1000..1036,            # Bib-1
19                   1037..1096, 1185..1209,       # Extended Bib-1
20                   1097..1111,                   # Dublin-Core
21                   1112..1184                    # GILS
22                 );
23
24     foreach my $attr (@attrs) {
25         $conn->irspy_search_pqf("\@attr 1=$attr mineral",
26                                 {'attr' => $attr}, {},
27                                 ZOOM::Event::ZEND, \&found,
28                                 exception => \&error);
29     }
30 }
31
32
33 sub found {
34     my($conn, $task, $test_args, $event) = @_;
35     my $attr = $test_args->{'attr'};
36     my $n = $task->{rs}->size();
37
38     $conn->log("irspy_test", "search on access-point $attr found $n record",
39                $n==1 ? "" : "s");
40     update($conn, $attr, 1);
41
42     return ZOOM::IRSpy::Status::TASK_DONE;
43 }
44
45
46 sub error {
47     my($conn, $task, $test_args, $exception) = @_;
48     my $attr = $test_args->{'attr'};
49
50     $conn->log("irspy_test", "search on access-point $attr had error: ",
51                $exception);
52     update($conn, $attr, 0);
53
54     return ZOOM::IRSpy::Status::TEST_BAD
55         if ($exception->code() == 1 || # permanent system error
56             $exception->code() == 109); # Database unavailable
57
58     return ZOOM::IRSpy::Status::TASK_DONE;
59 }
60
61
62 sub update {
63     my ($conn, $attr, $ok) = @_;
64     $conn->record()->store_result('search', 'set'       => 'bib-1',
65                                             'ap'        => $attr,
66                                             'ok'        => $ok);
67 }
68
69
70 1;