--- trunk/t/5_Node.t 2006/05/15 22:26:08 150 +++ trunk/t/5_Node.t 2006/06/24 15:34:42 160 @@ -3,22 +3,28 @@ use strict; use blib; -use Test::More tests => 252; +my $tests = 271; + +use Test::More; use Test::Exception; use Data::Dumper; BEGIN { use_ok('Search::Estraier') }; +plan tests => $tests; + my $debug = shift @ARGV; # name of node for test my $test1_node = '_test1_' . $$; my $test2_node = '_test2_' . $$; +my $estmaster_uri = $ENV{'ESTMASTER_URI'} || 'http://localhost:1978'; + ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new'); isa_ok($node, 'Search::Estraier::Node'); -ok($node->set_url("http://localhost:1978/node/$test1_node"), "set_url $test1_node"); +ok($node->set_url("$estmaster_uri/node/$test1_node"), "set_url $test1_node"); ok($node->set_proxy('', 8080), 'set_proxy'); throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN'; @@ -26,17 +32,25 @@ ok($node->set_timeout(42), 'set_timeout'); throws_ok {$node->set_timeout('foo') } qr/timeout/, 'set_timeout NaN'; -ok($node->set_auth('admin','admin'), 'set_auth'); +my ($user, $passwd) = ( + $ENV{EST_USER} || 'admin', + $ENV{EST_PASSWD} || 'admin' +); + +ok($node->set_auth($user, $passwd), 'set_auth'); cmp_ok($node->status, '==', -1, 'status'); # test master functionality -#diag "not testing shutdown\n"; +SKIP: { -my $msg; +skip "can't find estmaster at $estmaster_uri", ($tests - 9) if (! eval { $node->master( action => 'nodelist' ) } ); + +diag "using $estmaster_uri"; +diag("node->master shutdown not tested"); -#diag "not testing backup\n"; +diag("node->master backup not tested"); ok(my @users = $node->master( action => 'userlist' ), 'userlist'); @@ -50,6 +64,7 @@ misc => 'test user', }; +my $msg; ok($msg = $node->master( action => 'useradd', %{ $user }, @@ -107,11 +122,6 @@ } 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"); @@ -139,6 +149,7 @@ $doc->add_attr('@uri', 'test' . $_); ok( $node->put_doc($doc), "put_doc test$_"); #diag $doc->dump_draft; + cmp_ok( $node->doc_num, '==', ($_ + 1), "node->doc_num " . ($_ + 1)); } ok(! $node->uri_to_id( 'does-not-exists' ), "non-existant uri_to_id"); @@ -160,6 +171,9 @@ ok( ! $node->edit_doc( $doc ), "edit_doc of removed doc"); +my $cache; +ok($cache = $node->cacheusage, "cacheusage: $cache"); + my $delete_num = 5; for ( 1 .. $delete_num ) { @@ -167,8 +181,6 @@ cmp_ok( $node->doc_num, '==', $doc_num - $_, "node->doc_num " . ($doc_num - $_)); } -ok($msg = $node->master( action => 'sync' ), "sync: $msg"); - my $doc_num2 = $doc_num - $delete_num; cmp_ok($node->doc_num, '==', $doc_num2, "node->doc_num $doc_num2"); @@ -219,7 +231,7 @@ } ok(my $hints = $nres->hints, 'hints'); -diag Dumper($hints); +diag Dumper($hints) if ($debug); ok($node->_set_info, "refresh _set_info"); @@ -236,13 +248,15 @@ my $skip = int($max / 2) || die "skip is zero, can't test"; ok($cond->set_skip( $skip ), "cond set_skip($skip)"); +like($node->cond_to_query( $cond ), qr/skip=$skip/, 'cond_to_query have skip'); + ok( $nres = $node->search( $cond, 0 ), 'search'); isa_ok( $nres, 'Search::Estraier::NodeResult' ); cmp_ok($nres->doc_num, '==', $max, "nres->doc_num " . ($max - $skip)); cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2"); for my $i ( 0 .. ($nres->doc_num - 1) ) { - my $uri = 'test' . ($i + $delete_num + 1); + my $uri = 'test' . ($i + $delete_num + $skip + 1); ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i"); if ($rdoc) { cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); @@ -253,24 +267,24 @@ # user doesn't exist -ok(! $node->set_user('foobar', 1), 'set_user'); +ok($node->set_user('foobar', 1), 'set_user'); -ok(my $node2 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node"); +ok(my $node2 = new Search::Estraier::Node( "$estmaster_uri/node/$test2_node" ), "new $test2_node"); ok($node2->set_auth('admin','admin'), "set_auth $test2_node"); # croak_on_error -ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant"); +ok($node = new Search::Estraier::Node( url => "$estmaster_uri/non-existant", croak_on_error => 1 ), "new non-existant"); throws_ok { $node->name } qr/404/, 'croak on error'; # croak_on_error -ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node"); +ok($node = new Search::Estraier::Node( url => "$estmaster_uri/node/$test1_node", croak_on_error => 1, user => $user, passwd => $passwd, debug => $debug ), "new $test1_node"); ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak'); # test users -ok(! $node->admins, 'no admins'); +ok($node->admins, 'have admins'); ok(! $node->guests, 'no guests'); @@ -282,12 +296,19 @@ # now, test links my $test2_label = "$test2_node label"; -my $link_url = "http://localhost:1978/node/$test2_node"; +my $link_url = "$estmaster_uri/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"); +ok($node->set_link("$estmaster_uri/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); + +ok($msg = $node->master( + action => 'nodeclr', + name => $node->name, +), "nodeclr " . $node->name . ": $msg"); + +cmp_ok($node->doc_num, '==', 0, 'no documents'); # cleanup test nodes foreach my $node_name ( $test1_node , $test2_node ) { @@ -302,7 +323,7 @@ my $node_label = "test $$ label"; ok($node = new Search::Estraier::Node( - url => "http://localhost:1978/node/$node_name", + url => "$estmaster_uri/node/$node_name", create => 1, label => $node_label, croak_on_error => 1 @@ -312,14 +333,14 @@ cmp_ok($node->label, 'eq', $node_label, "node label: $node_label"); ok($node = new Search::Estraier::Node( - url => "http://localhost:1978/node/$node_name", + url => "$estmaster_uri/node/$node_name", create => 1, label => $node_label, croak_on_error => 0 ), "new create existing"); ok($node = new Search::Estraier::Node( - url => "http://localhost:1978/node/$node_name", + url => "$estmaster_uri/node/$node_name", create => 1, label => $node_label, croak_on_error => 1 @@ -333,7 +354,7 @@ # and again, this time without node ok($node = new Search::Estraier::Node( - url => "http://localhost:1978/node/$node_name", + url => "$estmaster_uri/node/$node_name", create => 1, label => $node_label, croak_on_error => 0 @@ -348,4 +369,8 @@ name => $node_name, ), "nodedel $node_name: $msg"); +ok($msg = $node->master( action => 'sync' ), "sync: $msg"); + +} # SKIP + diag "over";