2 # See the "Main" test package for documentation
4 package ZOOM::IRSpy::Test::Record::Fetch;
10 use ZOOM::IRSpy::Test;
11 our @ISA = qw(ZOOM::IRSpy::Test);
13 our $max_timeout_errors = $ZOOM::IRSpy::max_timeout_errors;
17 "\@attr 1=4 computer",
18 "\@attr 1=44 mineral", # Smithsonian doesn't support AP 4!
19 "\@attr 1=1016 water", # Connector Framework only does 1016
20 ### We can add more queries here
28 $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, {},
29 ZOOM::Event::ZEND, \&completed_search,
30 exception => \&completed_search);
34 sub completed_search {
35 my($conn, $task, $udata, $event) = @_;
37 my $n = $task->{rs}->size();
38 $conn->log("irspy_test", "Fetch test search (", $task->render_query(), ") ",
39 ref $event && $event->isa("ZOOM::Exception") ?
40 "failed: $event" : "found $n records (event=$event)");
42 # remember how often a target record hit a timeout
43 if (ref $event && $event->isa("ZOOM::Exception")) {
44 if ($event =~ /Timeout/i) {
45 $conn->record->zoom_error->{TIMEOUT}++;
46 $conn->log("irspy_test", "Increase timeout error counter to: " .
47 $conn->record->zoom_error->{TIMEOUT});
52 $task->{rs}->destroy();
53 my $qindex = $udata->{queryindex}+1;
54 my $q = $queries[$qindex];
55 return ZOOM::IRSpy::Status::TEST_SKIPPED
56 if !defined $q || $conn->record->zoom_error->{TIMEOUT} >= $max_timeout_errors;
58 $conn->log("irspy_test", "Trying another search ...");
59 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, {},
60 ZOOM::Event::ZEND, \&completed_search,
61 exception => \&completed_search);
62 return ZOOM::IRSpy::Status::TASK_DONE;
86 #@syntax = qw(grs-1 sutrs usmarc xml); # simplify for debugging
87 foreach my $i (0 ..$#syntax) {
88 my $syntax = $syntax[$i];
89 $conn->irspy_rs_record($task->{rs}, 0,
91 last => ($i == $#syntax) },
92 { start => 0, count => 1,
93 preferredRecordSyntax => $syntax },
94 ZOOM::Event::ZEND, \&record,
95 exception => \&fetch_error);
98 return ZOOM::IRSpy::Status::TASK_DONE;
103 my($conn, $task, $udata, $event) = @_;
104 my $syn = $udata->{'syntax'};
105 my $rs = $task->{rs};
107 my $record = _fetch_record($rs, 0, $syn);
109 if (!$record || $record->error()) {
110 $conn->log("irspy_test", "retrieval of $syn record failed: ",
111 defined $record ? $record->exception() :
115 my $text = $record->render();
116 $conn->log("irspy_test", "Successfully retrieved a $syn record");
118 print STDERR "Hits: ", $rs->size(), "\n";
119 print STDERR "Syntax: ", $syn, "\n";
124 $conn->record()->store_result('record_fetch',
128 $rs->destroy() if $udata->{last};
129 return ($udata->{last} ?
130 ZOOM::IRSpy::Status::TEST_GOOD :
131 ZOOM::IRSpy::Status::TASK_DONE);
136 my($rs, $index0, $syntax) = @_;
138 my $oldSyntax = $rs->option(preferredRecordSyntax => $syntax);
139 my $record = $rs->record(0);
140 $oldSyntax = "" if !defined $oldSyntax;
141 $rs->option(preferredRecordSyntax => $oldSyntax);
147 sub __UNUSED_search_error {
148 my($conn, $task, $test_args, $exception) = @_;
150 $conn->log("irspy_test", "Initial search failed: ", $exception);
151 return ZOOM::IRSpy::Status::TEST_SKIPPED;
156 my($conn, $task, $udata, $exception) = @_;
157 my $syn = $udata->{'syntax'};
159 $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
160 $conn->record()->store_result('record_fetch',
163 $task->{rs}->destroy() if $udata->{last};
164 return ZOOM::IRSpy::Status::TASK_DONE;