--- trunk/t/5_Node.t 2006/02/19 13:50:50 105 +++ trunk/t/5_Node.t 2006/05/10 13:34:17 138 @@ -3,7 +3,7 @@ use strict; use blib; -use Test::More tests => 101; +use Test::More tests => 132; use Test::Exception; use Data::Dumper; @@ -12,8 +12,8 @@ my $debug = 0; # name of node for test -my $test1_node = 'test1'; -my $test2_node = 'test2'; +my $test1_node = '_test1_' . $$; +my $test2_node = '_test2_' . $$; ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new'); isa_ok($node, 'Search::Estraier::Node'); @@ -30,19 +30,98 @@ cmp_ok($node->status, '==', -1, 'status'); -SKIP: { +# test master functionality -skip "no $test1_node node in Hyper Estraier", 91, unless($node->name); +#diag "not testing shutdown\n"; -my @res = ( -1, 200 ); +my $msg; -my $nodelist; -foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) { - cmp_ok( - $node->shuttle_url( $url, 'text/plain', undef, \$nodelist) - ,'==', shift @res, 'nodelist'); +ok($msg = $node->master( action => 'sync' ), "sync: $msg"); + +#diag "not testing backup\n"; + +ok(my @users = $node->master( action => 'userlist' ), 'userlist'); + +#diag "users: ", Dumper( \@users ); +diag "found ", $#users + 1, " users"; + +my $user = { + name => '_test_' . $$, + flags => 'b', + fname => 'Search::Estraier', + misc => 'test user', +}; + +ok($msg = $node->master( + action => 'useradd', + %{ $user }, + passwd => 'test1234', +), "useradd: $msg"); + +ok(my @users2 = $node->master( action => 'userlist' ), 'userlist'); +cmp_ok($#users2, '==', $#users + 1, 'added user'); + +while (my $row = shift @users2) { + next unless ($row->{name} eq $user); + map { + cmp_ok($user->{$_}, 'eq', $row->{$_}, "$_"); + } keys %{ $user }; } +ok($msg = $node->master( + action => 'userdel', + name => $user->{name}, +), "userdel: $msg"); + +ok(@users2 = $node->master( action => 'userlist' ), 'userlist'); +cmp_ok($#users2, '==', $#users, 'removed user'); + +ok(my @nodes = $node->master( action => 'nodelist' ), 'nodelist' ); +#diag "nodelist: ", Dumper( \@nodes ); +diag "found ", $#nodes + 1, " nodes"; + +if ($#nodes > 42) { + diag <<'_END_OF_WARNING_'; + +This tests create three nodes in your Hyper Estraier. + +Since you have more than 43 modes, and Hyper Estraier needs more than +1024 file descriptors for more than 46 nodes, expect tests to fail. + +If tests do fail, you can try to add + +ulimit -n 2048 + +before staring estmaster, which will increase number of available nodes +to 96 before estmaster runs out of file descriptors. + +_END_OF_WARNING_ +} + +my $temp_node = "_test_temp_$$"; + +foreach my $node_name ( $test1_node , $test2_node, $temp_node ) { + ok($msg = $node->master( + action => 'nodeadd', + name => $node_name, + label => "$node_name label", + ), "nodeadd $node_name: $msg"); +} + +ok($msg = $node->master( + action => 'nodeclr', + name => $temp_node, +), "nodeclr $temp_node: $msg"); + +ok($msg = $node->master( + action => 'nodedel', + name => $temp_node, +), "nodedel $temp_node: $msg"); + +#diag "not testing logrtt\n"; + +# test document creation + my $draft = <<'_END_OF_DRAFT_'; @uri=data001 @title=Material Girl @@ -100,17 +179,25 @@ cmp_ok($nres->hits, '==', $data_max, "hits"); -for ( 6 .. 10 ) { - my $uri = 'test' . $_; +for my $i ( 0 .. ($nres->hits - 1) ) { + my $uri = 'test' . ($i + $data_max + 1); + + if ($i < $nres->doc_num) { + ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i"); + + cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); + ok( my $k = $rdoc->keywords( $id ), "rdoc keywords"); + } + ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id"); ok( $node->get_doc( $id ), "get_doc $id"); ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id"); cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id"); - ok( my $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); + ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri"); #diag Dumper($k, $k2); - ok( eq_hash( $k, $k2 ), "keywords"); + ok( eq_hash( $k1, $k2 ), "keywords"); } ok(my $hints = $nres->hints, 'hints'); @@ -122,7 +209,7 @@ ok($v = $node->name, "name: $v"); ok($v = $node->label, "label: $v"); ok($v = $node->doc_num, "doc_num: $v"); -ok($v = $node->word_num, "word_num: $v"); +ok(defined($v = $node->word_num), "word_num: $v"); ok($v = $node->size, "size: $v"); ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); @@ -139,17 +226,37 @@ throws_ok { $node->name } qr/404/, 'croak on error'; # croak_on_error -ok($node = new Search::Estraier::Node( url => "http://localhost:1978/$test1_node", croak_on_error => 1 ), "new $test1_node"); +ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node"); ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak'); -SKIP: { - skip "no $test2_node in Hyper Estraier, skipping set_link", 2 unless (my $test2_label = $node2->label); - - ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 42), "set_link $test2_node ($test2_label) 42"); - ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); -} # SKIP 2 -} # SKIP 1 +# test users +ok(! $node->admins, 'no admins'); +ok(! $node->guests, 'no guests'); + + +# test search without results +ok($cond = new Search::Estraier::Condition, 'new cond'); +ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase'); + +ok($nres = $node->search( $cond, 0 ), 'search'); + +# now, test links +my $test2_label = "$test2_node label"; +my $link_url = "http://localhost:1978/node/$test2_node"; +ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42"); +ok(my $links = $node->links, 'links'); +cmp_ok($#{$links}, '==', 0, 'one link'); +like($links->[0], qr/^$link_url/, 'link correct'); +ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); + +# cleanup test nodes +foreach my $node_name ( $test1_node , $test2_node ) { + ok($msg = $node->master( + action => 'nodedel', + name => $node_name, + ), "nodedel $node_name: $msg"); +} diag "over";