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
62 if ($conn->record->zoom_error->{TIMEOUT} >= $max_timeout_errors) {
63 $conn->log("irspy_test", "Got $max_timeout_errors timeouts, give up...");
65 $conn->log("irspy_test", "Trying another search ...");
66 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, {},
67 ZOOM::Event::ZEND, \&completed_search,
68 exception => \&completed_search);
70 return ZOOM::IRSpy::Status::TASK_DONE;
94 #@syntax = qw(grs-1 sutrs usmarc xml); # simplify for debugging
95 foreach my $i (0 ..$#syntax) {
96 my $syntax = $syntax[$i];
97 $conn->irspy_rs_record($task->{rs}, 0,
99 last => ($i == $#syntax) },
100 { start => 0, count => 1,
101 preferredRecordSyntax => $syntax },
102 ZOOM::Event::ZEND, \&record,
103 exception => \&fetch_error);
106 return ZOOM::IRSpy::Status::TASK_DONE;
111 my($conn, $task, $udata, $event) = @_;
112 my $syn = $udata->{'syntax'};
113 my $rs = $task->{rs};
115 my $record = _fetch_record($rs, 0, $syn);
117 if (!$record || $record->error()) {
118 $conn->log("irspy_test", "retrieval of $syn record failed: ",
119 defined $record ? $record->exception() :
123 my $text = $record->render();
124 $conn->log("irspy_test", "Successfully retrieved a $syn record");
126 print STDERR "Hits: ", $rs->size(), "\n";
127 print STDERR "Syntax: ", $syn, "\n";
132 $conn->record()->store_result('record_fetch',
136 $rs->destroy() if $udata->{last};
137 return ($udata->{last} ?
138 ZOOM::IRSpy::Status::TEST_GOOD :
139 ZOOM::IRSpy::Status::TASK_DONE);
144 my($rs, $index0, $syntax) = @_;
146 my $oldSyntax = $rs->option(preferredRecordSyntax => $syntax);
147 my $record = $rs->record(0);
148 $oldSyntax = "" if !defined $oldSyntax;
149 $rs->option(preferredRecordSyntax => $oldSyntax);
155 sub __UNUSED_search_error {
156 my($conn, $task, $test_args, $exception) = @_;
158 $conn->log("irspy_test", "Initial search failed: ", $exception);
159 return ZOOM::IRSpy::Status::TEST_SKIPPED;
164 my($conn, $task, $udata, $exception) = @_;
165 my $syn = $udata->{'syntax'};
167 $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
168 $conn->record()->store_result('record_fetch',
171 $task->{rs}->destroy() if $udata->{last};
172 return ZOOM::IRSpy::Status::TASK_DONE;