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;
18 "\@attr 1=4 computer",
19 "\@attr 1=44 mineral", # Smithsonian doesn't support AP 4!
20 "\@attr 1=1016 water", # Connector Framework only does 1016
21 ### We can add more queries here
29 # Here I want to get a use attribute from the session, which we've
30 # managed to search for in the Search/Bib1 or Search/Dan1 tests.
31 # But how? So far we search for title: 1=4
32 $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, {},
33 ZOOM::Event::ZEND, \&completed_search,
34 exception => \&completed_search);
38 sub completed_search {
39 my($conn, $task, $udata, $event) = @_;
41 my $n = $task->{rs}->size();
42 $conn->log("irspy_test", "Fetch test search (", $task->render_query(), ") ",
43 ref $event && $event->isa("ZOOM::Exception") ?
44 "failed: $event" : "found $n records (event=$event)");
46 # remember how often a target record hit a timeout
47 if (ref $event && $event->isa("ZOOM::Exception")) {
48 if ($event =~ /Timeout/i) {
49 $conn->record->zoom_error->{TIMEOUT}++;
50 $conn->log("irspy_test", "Increase timeout error counter to: " .
51 $conn->record->zoom_error->{TIMEOUT});
56 $task->{rs}->destroy();
57 my $qindex = $udata->{queryindex}+1;
58 my $q = $queries[$qindex];
59 return ZOOM::IRSpy::Status::TEST_SKIPPED
60 if !defined $q || $conn->record->zoom_error->{TIMEOUT} >= $max_timeout_errors;
62 $conn->log("irspy_test", "Trying another search ...");
63 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, {},
64 ZOOM::Event::ZEND, \&completed_search,
65 exception => \&completed_search);
66 return ZOOM::IRSpy::Status::TASK_DONE;
90 #@syntax = qw(grs-1 sutrs usmarc xml); # simplify for debugging
91 foreach my $i (0 ..$#syntax) {
92 my $syntax = $syntax[$i];
93 $conn->irspy_rs_record($task->{rs}, 0,
95 last => ($i == $#syntax) },
96 { start => 0, count => 1,
97 preferredRecordSyntax => $syntax },
98 ZOOM::Event::ZEND, \&record,
99 exception => \&fetch_error);
102 return ZOOM::IRSpy::Status::TASK_DONE;
107 my($conn, $task, $udata, $event) = @_;
108 my $syn = $udata->{'syntax'};
109 my $rs = $task->{rs};
111 my $record = _fetch_record($rs, 0, $syn);
113 if (!$record || $record->error()) {
114 $conn->log("irspy_test", "retrieval of $syn record failed: ",
115 defined $record ? $record->exception() :
119 my $text = $record->render();
120 $conn->log("irspy_test", "Successfully retrieved a $syn record");
122 print STDERR "Hits: ", $rs->size(), "\n";
123 print STDERR "Syntax: ", $syn, "\n";
128 $conn->record()->store_result('record_fetch',
132 $rs->destroy() if $udata->{last};
133 return ($udata->{last} ?
134 ZOOM::IRSpy::Status::TEST_GOOD :
135 ZOOM::IRSpy::Status::TASK_DONE);
140 my($rs, $index0, $syntax) = @_;
142 my $oldSyntax = $rs->option(preferredRecordSyntax => $syntax);
143 my $record = $rs->record(0);
144 $oldSyntax = "" if !defined $oldSyntax;
145 $rs->option(preferredRecordSyntax => $oldSyntax);
151 sub __UNUSED_search_error {
152 my($conn, $task, $test_args, $exception) = @_;
154 $conn->log("irspy_test", "Initial search failed: ", $exception);
155 return ZOOM::IRSpy::Status::TEST_SKIPPED;
160 my($conn, $task, $udata, $exception) = @_;
161 my $syn = $udata->{'syntax'};
163 $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
164 $conn->record()->store_result('record_fetch',
167 $task->{rs}->destroy() if $udata->{last};
168 return ZOOM::IRSpy::Status::TASK_DONE;