3 # $Id: stress-test,v 1.2 2007-01-02 14:11:02 sondberg Exp $
4 # -------------------------------------------------
5 # Simulate a search/retrieve session
11 my $url = 'http://test.indexdata.dk:8001/~sondberg/pazpar2/www/search.pz2';
12 my $parser = new XML::LibXML;
13 my $ua = new LWP::UserAgent;
14 my $session_id = get_session($ua);
16 my @terms = qw(water mineral computer java texas energy xml pirsig clinton
17 management environment dinosaur houston washington);
21 my $term = get_random_term(@terms);
23 print STDERR "Search for: '", $term, "'\n";
25 if (start_search($session_id, $ua, $term)) {
26 print STDERR "Success...\n";
28 foreach my $p (0..4) {
32 if (fetch_records($session_id, $ua, $p * 20)) {
33 print STDERR "Fetched...\n";
44 return $terms[int rand($#terms)];
50 my ($status_node) = $root->getElementsByTagName('status');
51 my $status = $status_node->textContent;
53 return ($status eq 'OK');
58 my ($sid, $ua, $offset) = @_;
59 my $uri = $url . '?session=' . $sid . '&command=show&start=' . $offset;
60 my $response = $ua->get($uri);
62 if ($response->is_success) {
63 my $root = get_dom($response);
65 if (check_status($root)) {
67 my (@hits) = $root->getElementsByTagName('hit');
69 foreach my $h (@hits) {
70 my ($title) = $h->getElementsByTagName('title');
71 print STDERR "Title: '", $title->textContent, "'\n";
77 die($0 . ': Unable to fetch records, wrong status');
80 die($0 . ': Unable to fetch records');
87 my ($sid, $ua, $term) = @_;
88 my $uri = $url . '?session=' . $sid . '&command=search&query=' . $term;
89 my $response = $ua->get($uri);
91 if ($response->is_success) {
92 my $root = get_dom($response);
94 if (check_status($root)) {
97 die($0 . ': Unable to search');
100 die($0 . ': Unable to perform search');
107 my $doc = $parser->parse_string($resp->content);
109 return $doc->documentElement();
115 my $response = $ua->get($url . '?command=init');
117 if ($response->is_success) {
118 my $root = get_dom($response);
120 if (check_status($root)) {
121 my ($ses_node) = $root->getElementsByTagName('session');
122 return $ses_node->textContent;
124 die($0 . ':Unable to get session, wrong status');
127 die($0 . ': Unable to get session id');