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);
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 # Here I want to get a use attribute from the session, which we've
29 # managed to search for in the Search/Bib1 or Search/Dan1 tests.
30 # But how? So far we search for title: 1=4
31 $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, {},
32 ZOOM::Event::ZEND, \&completed_search,
33 exception => \&completed_search);
37 sub completed_search {
38 my($conn, $task, $udata, $event) = @_;
40 my $n = $task->{rs}->size();
41 $conn->log("irspy_test", "Fetch test search (", $task->render_query(), ") ",
42 ref $event && $event->isa("ZOOM::Exception") ?
43 "failed: $event" : "found $n records (event=$event)");
45 $task->{rs}->destroy();
46 my $qindex = $udata->{queryindex}+1;
47 my $q = $queries[$qindex];
48 return ZOOM::IRSpy::Status::TEST_SKIPPED
51 $conn->log("irspy_test", "Trying another search ...");
52 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, {},
53 ZOOM::Event::ZEND, \&completed_search,
54 exception => \&completed_search);
55 return ZOOM::IRSpy::Status::TASK_DONE;
79 #@syntax = qw(grs-1 sutrs usmarc xml); # simplify for debugging
80 foreach my $i (0 ..$#syntax) {
81 my $syntax = $syntax[$i];
82 $conn->irspy_rs_record($task->{rs}, 0,
84 last => ($i == $#syntax) },
85 { start => 0, count => 1,
86 preferredRecordSyntax => $syntax },
87 ZOOM::Event::ZEND, \&record,
88 exception => \&fetch_error);
91 return ZOOM::IRSpy::Status::TASK_DONE;
96 my($conn, $task, $udata, $event) = @_;
97 my $syn = $udata->{'syntax'};
100 my $record = _fetch_record($rs, 0, $syn);
102 if (!$record || $record->error()) {
103 $conn->log("irspy_test", "retrieval of $syn record failed: ",
104 defined $record ? $record->exception() :
108 my $text = $record->render();
109 $conn->log("irspy_test", "Successfully retrieved a $syn record");
111 print STDERR "Hits: ", $rs->size(), "\n";
112 print STDERR "Syntax: ", $syn, "\n";
117 $conn->record()->store_result('record_fetch',
121 $rs->destroy() if $udata->{last};
122 return ($udata->{last} ?
123 ZOOM::IRSpy::Status::TEST_GOOD :
124 ZOOM::IRSpy::Status::TASK_DONE);
129 my($rs, $index0, $syntax) = @_;
131 my $oldSyntax = $rs->option(preferredRecordSyntax => $syntax);
132 my $record = $rs->record(0);
133 $oldSyntax = "" if !defined $oldSyntax;
134 $rs->option(preferredRecordSyntax => $oldSyntax);
140 sub __UNUSED_search_error {
141 my($conn, $task, $test_args, $exception) = @_;
143 $conn->log("irspy_test", "Initial search failed: ", $exception);
144 return ZOOM::IRSpy::Status::TEST_SKIPPED;
149 my($conn, $task, $udata, $exception) = @_;
150 my $syn = $udata->{'syntax'};
152 $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
153 $conn->record()->store_result('record_fetch',
156 $task->{rs}->destroy() if $udata->{last};
157 return ZOOM::IRSpy::Status::TASK_DONE;