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
44 #@syntax = qw(grs-1 sutrs usmarc xml); # simplify for debugging
51 $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, {},
52 ZOOM::Event::ZEND, \&completed_search,
53 exception => \&completed_search);
57 sub completed_search {
58 my($conn, $task, $udata, $event) = @_;
60 my $n = $task->{rs}->size();
61 $conn->log("irspy_test", "Fetch test search (", $task->render_query(), ") ",
62 ref $event && $event->isa("ZOOM::Exception") ?
63 "failed: $event" : "found $n records (event=$event)");
65 # remember how often a target record hit a timeout
66 if (ref $event && $event->isa("ZOOM::Exception")) {
67 if ($event =~ /Timeout/i) {
68 $conn->record->zoom_error->{TIMEOUT}++;
69 $conn->log("irspy_test", "Increase timeout error counter to: " .
70 $conn->record->zoom_error->{TIMEOUT});
75 $task->{rs}->destroy();
76 my $qindex = $udata->{queryindex}+1;
77 my $q = $queries[$qindex];
78 return ZOOM::IRSpy::Status::TEST_SKIPPED
79 if !defined $q || $conn->record->zoom_error->{TIMEOUT} >= $max_timeout_errors;
81 $conn->log("irspy_test", "Trying another search ...");
82 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, {},
83 ZOOM::Event::ZEND, \&completed_search,
84 exception => \&completed_search);
85 return ZOOM::IRSpy::Status::TASK_DONE;
88 foreach my $i (0 ..$#syntax) {
89 my $syntax = $syntax[$i];
90 $conn->irspy_rs_record($task->{rs}, 0,
92 last => ($i == $#syntax) },
93 { start => 0, count => 1,
94 preferredRecordSyntax => $syntax },
95 ZOOM::Event::ZEND, \&record,
96 exception => \&fetch_error);
99 return ZOOM::IRSpy::Status::TASK_DONE;
104 my($conn, $task, $udata, $event) = @_;
105 my $syn = $udata->{'syntax'};
106 my $rs = $task->{rs};
108 my $record = _fetch_record($conn, $rs, 0, $syn);
110 if (!$record || $record->error()) {
111 $conn->log("irspy_test", "retrieval of $syn record failed: ",
112 defined $record ? $record->exception() :
116 my $text = $record->render();
117 $conn->log("irspy_test", "Successfully retrieved a $syn record");
119 print STDERR "Hits: ", $rs->size(), "\n";
120 print STDERR "Syntax: ", $syn, "\n";
125 $conn->record()->store_result('record_fetch',
129 $rs->destroy() if $udata->{last};
130 return ($udata->{last} ?
131 ZOOM::IRSpy::Status::TEST_GOOD :
132 ZOOM::IRSpy::Status::TASK_DONE);
136 # By the time this is called, the record has already been physically
137 # fetched from the server in the correct syntax, and placed in the
138 # result-set's cache. But in order to actually get hold of it from
139 # that cache, we need to set the record-syntax again, to the same
140 # value, otherwise ZOOM will make a fresh request.
142 # ZOOM::IRSpy::Task::Retrieve sets options into the connection object
143 # rather than the result-set object (because it's a subclass of
144 # ZOOM::IRSpy::Task, which doesn't know about result-sets). Therefore
145 # it's important that this function also set into the connection:
146 # otherwise any value subsequently set into the connection by
147 # ZOOM::IRSpy::Task::Retrieve will be ignored by ZOOM-C operations, as
148 # the value previously set into the result-set will override it.
149 # (This was the very subtle cause of bug #3534).
152 my($conn, $rs, $index0, $syntax) = @_;
154 my $oldSyntax = $conn->option(preferredRecordSyntax => $syntax);
155 my $record = $rs->record(0);
156 $oldSyntax = "" if !defined $oldSyntax;
157 $conn->option(preferredRecordSyntax => $oldSyntax);
163 sub __UNUSED_search_error {
164 my($conn, $task, $test_args, $exception) = @_;
166 $conn->log("irspy_test", "Initial search failed: ", $exception);
167 return ZOOM::IRSpy::Status::TEST_SKIPPED;
172 my($conn, $task, $udata, $exception) = @_;
173 my $syn = $udata->{'syntax'};
175 $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
176 $conn->record()->store_result('record_fetch',
179 $task->{rs}->destroy() if $udata->{last};
180 return ZOOM::IRSpy::Status::TASK_DONE;