/[Search-Estraier]/trunk/t/5_Node.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 137 by dpavlin, Tue May 9 14:05:57 2006 UTC revision 150 by dpavlin, Mon May 15 22:26:08 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 132;  use Test::More tests => 252;
7  use Test::Exception;  use Test::Exception;
8  use Data::Dumper;  use Data::Dumper;
9    
10  BEGIN { use_ok('Search::Estraier') };  BEGIN { use_ok('Search::Estraier') };
11    
12  my $debug = 0;  my $debug = shift @ARGV;
13    
14  # name of node for test  # name of node for test
15  my $test1_node = '_test1_' . $$;  my $test1_node = '_test1_' . $$;
# Line 36  cmp_ok($node->status, '==', -1, 'status' Line 36  cmp_ok($node->status, '==', -1, 'status'
36    
37  my $msg;  my $msg;
38    
 ok($msg = $node->master( action => 'sync' ), "sync: $msg");  
   
39  #diag "not testing backup\n";  #diag "not testing backup\n";
40    
41  ok(my @users = $node->master( action => 'userlist' ), 'userlist');  ok(my @users = $node->master( action => 'userlist' ), 'userlist');
# Line 85  if ($#nodes > 42) { Line 83  if ($#nodes > 42) {
83    
84  This tests create three nodes in your Hyper Estraier.  This tests create three nodes in your Hyper Estraier.
85    
86  Since you have more than 43 modes, and Hyper Estraier seems to be limited to  Since you have more than 43 modes, and Hyper Estraier needs more than
87  maximum of 46 nodes on each estmaster process, expect tests to fail.  1024 file descriptors for more than 46 nodes, expect tests to fail.
88    
89    If tests do fail, you can try to add
90    
91    ulimit -n 2048
92    
93    before staring estmaster, which will increase number of available nodes
94    to 96 before estmaster runs out of file descriptors.
95    
96  _END_OF_WARNING_  _END_OF_WARNING_
97  }  }
# Line 116  ok($msg = $node->master( Line 121  ok($msg = $node->master(
121  # test document creation  # test document creation
122    
123  my $draft = <<'_END_OF_DRAFT_';  my $draft = <<'_END_OF_DRAFT_';
124  @uri=data001  @uri=data0
125  @title=Material Girl  @title=Material Girl
126    
127  Living in a material world  Living in a material world
# Line 130  ok(my $doc = new Search::Estraier::Docum Line 135  ok(my $doc = new Search::Estraier::Docum
135    
136  ok( $node->put_doc($doc), "put_doc data001");  ok( $node->put_doc($doc), "put_doc data001");
137    
138  for ( 1 .. 10 ) {  for ( 1 .. 17 ) {
139          $doc->add_attr('@uri', 'test' . $_);          $doc->add_attr('@uri', 'test' . $_);
140          ok( $node->put_doc($doc), "put_doc test$_");          ok( $node->put_doc($doc), "put_doc test$_");
141          #diag $doc->dump_draft;          #diag $doc->dump_draft;
142  }  }
143    
144  my $id;  ok(! $node->uri_to_id( 'does-not-exists' ), "non-existant uri_to_id");
 ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");  
   
 my $data_max = 5;  
145    
146  for ( 1 .. $data_max ) {  my $id;
147          ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");  ok($id = $node->uri_to_id( 'data0' ), "uri_to_id(data0)");
 }  
148    
149  ok($doc = $node->get_doc( $id ), 'get_doc for edit');  ok($doc = $node->get_doc( $id ), "get_doc($id) for edit");
150  $doc->add_attr('foo', 'bar');  $doc->add_attr('foo', 'bar');
151  #diag Dumper($doc);  #diag Dumper($doc);
152  ok( $node->edit_doc( $doc ), 'edit_doc');  ok( $node->edit_doc( $doc ), 'edit_doc');
153    
154  ok( $node->out_doc( $id ), "out_doc $id");  my $doc_num;
155    ok( $doc_num = $node->doc_num, "node->doc_num $doc_num");
156    
157    ok( $node->out_doc( $id ), "out_doc($id)");
158    
159    cmp_ok( $node->doc_num, '==', --$doc_num, "node->doc_num " . $doc_num);
160    
161    ok( ! $node->edit_doc( $doc ), "edit_doc of removed doc");
162    
163    my $delete_num = 5;
164    
165    for ( 1 .. $delete_num ) {
166            ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
167            cmp_ok( $node->doc_num, '==', $doc_num - $_, "node->doc_num " . ($doc_num - $_));
168    }
169    
170    ok($msg = $node->master( action => 'sync' ), "sync: $msg");
171    
172  ok( ! $node->edit_doc( $doc ), "edit removed");  my $doc_num2 = $doc_num - $delete_num;
173    cmp_ok($node->doc_num, '==', $doc_num2, "node->doc_num $doc_num2");
174    
175  my $max = 3;  my $max = int($doc_num2 / 2);
176    
177  ok(my $cond = new Search::Estraier::Condition, 'new cond');  ok(my $cond = new Search::Estraier::Condition, 'new cond');
178  ok($cond->set_phrase('girl'), 'cond set_phrase');  ok($cond->set_phrase('girl'), 'cond set_phrase');
179  ok($cond->set_max($max), "cond set_max $max");  ok($cond->set_max($max), "cond set_max($max)");
180  ok($cond->set_order('@uri ASCD'), 'cond set_order');  ok($cond->set_order('@uri ASCD'), 'cond set_order');
181  ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');  ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
182    
# Line 168  ok( my $nres = $node->search( $cond, 0 ) Line 186  ok( my $nres = $node->search( $cond, 0 )
186    
187  isa_ok( $nres, 'Search::Estraier::NodeResult' );  isa_ok( $nres, 'Search::Estraier::NodeResult' );
188    
189  cmp_ok($nres->doc_num, '==', $max, "doc_num = $max");  cmp_ok($nres->doc_num, '==', $max, "nres->doc_num $max");
190    
191  cmp_ok($nres->hits, '==', $data_max, "hits");  cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2");
192    
193    # upper limit is $nres->hits and not $nres->doc_num because we
194    # check all documents, not just results!
195  for my $i ( 0 .. ($nres->hits - 1) ) {  for my $i ( 0 .. ($nres->hits - 1) ) {
196          my $uri = 'test' . ($i + $data_max + 1);          my $num = $i + $delete_num + 1;
197            my $uri = 'test' . $num;
198    
199          if ($i < $nres->doc_num) {          if ($i < $nres->doc_num) {
200                  ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i");                  ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i");
201    
202                  cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");                  cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
203                    cmp_ok( $node->uri_to_id( $uri ), '==', $num + 1, "uri_to_id($uri)");
204    
205                  ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");                  ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");
206            } else {
207                    ok( ! $nres->get_doc( $i ), "nres->get_doc doesn't exist");
208          }          }
209    
210          ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id");          ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri)");
211          ok( $node->get_doc( $id ), "get_doc $id");          ok( $node->get_doc( $id ), "get_doc($id)");
212          ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");          ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri($uri)");
213          cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");          cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
214          cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");          cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
215          ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");          ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
# Line 207  ok($v = $node->size, "size: $v"); Line 232  ok($v = $node->size, "size: $v");
232    
233  ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");  ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
234    
235    # test skip
236    my $skip = int($max / 2) || die "skip is zero, can't test";
237    ok($cond->set_skip( $skip ), "cond set_skip($skip)");
238    
239    ok( $nres = $node->search( $cond, 0 ), 'search');
240    isa_ok( $nres, 'Search::Estraier::NodeResult' );
241    cmp_ok($nres->doc_num, '==', $max, "nres->doc_num " . ($max - $skip));
242    cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2");
243    
244    for my $i ( 0 .. ($nres->doc_num - 1) ) {
245            my $uri = 'test' . ($i + $delete_num + 1);
246            ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i");
247            if ($rdoc) {
248                    cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
249            } else {
250                    fail('no rdoc');
251            }
252    }
253    
254    
255  # user doesn't exist  # user doesn't exist
256  ok(! $node->set_user('foobar', 1), 'set_user');  ok(! $node->set_user('foobar', 1), 'set_user');
257    
# Line 252  foreach my $node_name ( $test1_node , $t Line 297  foreach my $node_name ( $test1_node , $t
297          ), "nodedel $node_name: $msg");          ), "nodedel $node_name: $msg");
298  }  }
299    
300    # test create
301    my $node_name = '_test_create_' . $$;
302    my $node_label = "test $$ label";
303    
304    ok($node = new Search::Estraier::Node(
305            url => "http://localhost:1978/node/$node_name",
306            create => 1,
307            label => $node_label,
308            croak_on_error => 1
309    ), "new create+croak");
310    
311    cmp_ok($node->name, 'eq', $node_name, "node $node_name exists");
312    cmp_ok($node->label, 'eq', $node_label, "node label: $node_label");
313    
314    ok($node = new Search::Estraier::Node(
315            url => "http://localhost:1978/node/$node_name",
316            create => 1,
317            label => $node_label,
318            croak_on_error => 0
319    ), "new create existing");
320    
321    ok($node = new Search::Estraier::Node(
322            url => "http://localhost:1978/node/$node_name",
323            create => 1,
324            label => $node_label,
325            croak_on_error => 1
326    ), "new create+croak existing");
327    
328    # cleanup
329    ok($msg = $node->master(
330            action => 'nodedel',
331            name => $node_name,
332    ), "nodedel $node_name: $msg");
333    
334    # and again, this time without node
335    ok($node = new Search::Estraier::Node(
336            url => "http://localhost:1978/node/$node_name",
337            create => 1,
338            label => $node_label,
339            croak_on_error => 0
340    ), "new create non-existing");
341    
342    cmp_ok($node->name, 'eq', $node_name, "node $node_name exists");
343    cmp_ok($node->label, 'eq', $node_label, "node label: $node_label");
344    
345    # cleanup
346    ok($msg = $node->master(
347            action => 'nodedel',
348            name => $node_name,
349    ), "nodedel $node_name: $msg");
350    
351  diag "over";  diag "over";

Legend:
Removed from v.137  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26