3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 92; |
use Test::More tests => 136; |
7 |
use Test::Exception; |
use Test::Exception; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
12 |
my $debug = 0; |
my $debug = 0; |
13 |
|
|
14 |
# name of node for test |
# name of node for test |
15 |
my $test_node = 'Search-Estraier'; |
my $test1_node = '_test1_' . $$; |
16 |
|
my $test2_node = '_test2_' . $$; |
17 |
|
|
18 |
ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new'); |
ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new'); |
19 |
isa_ok($node, 'Search::Estraier::Node'); |
isa_ok($node, 'Search::Estraier::Node'); |
20 |
|
|
21 |
ok($node->set_url('http://localhost:1978/node/searchestraier'), 'set_url'); |
ok($node->set_url("http://localhost:1978/node/$test1_node"), "set_url $test1_node"); |
22 |
|
|
23 |
ok($node->set_proxy('', 8080), 'set_proxy'); |
ok($node->set_proxy('', 8080), 'set_proxy'); |
24 |
throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN'; |
throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN'; |
30 |
|
|
31 |
cmp_ok($node->status, '==', -1, 'status'); |
cmp_ok($node->status, '==', -1, 'status'); |
32 |
|
|
33 |
my @res = ( -1, 200 ); |
# test master functionality |
34 |
|
|
35 |
my $nodelist; |
#diag "not testing shutdown\n"; |
36 |
foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) { |
|
37 |
cmp_ok( |
my $msg; |
38 |
$node->shuttle_url( $url, 'text/plain', undef, \$nodelist) |
|
39 |
,'==', shift @res, 'nodelist'); |
ok($msg = $node->master( action => 'sync' ), "sync: $msg"); |
40 |
|
|
41 |
|
#diag "not testing backup\n"; |
42 |
|
|
43 |
|
ok(my @users = $node->master( action => 'userlist' ), 'userlist'); |
44 |
|
|
45 |
|
#diag "users: ", Dumper( \@users ); |
46 |
|
diag "found ", $#users + 1, " users"; |
47 |
|
|
48 |
|
my $user = { |
49 |
|
name => '_test_' . $$, |
50 |
|
flags => 'b', |
51 |
|
fname => 'Search::Estraier', |
52 |
|
misc => 'test user', |
53 |
|
}; |
54 |
|
|
55 |
|
ok($msg = $node->master( |
56 |
|
action => 'useradd', |
57 |
|
%{ $user }, |
58 |
|
passwd => 'test1234', |
59 |
|
), "useradd: $msg"); |
60 |
|
|
61 |
|
ok(my @users2 = $node->master( action => 'userlist' ), 'userlist'); |
62 |
|
cmp_ok($#users2, '==', $#users + 1, 'added user'); |
63 |
|
|
64 |
|
while (my $row = shift @users2) { |
65 |
|
next unless ($row->{name} eq $user); |
66 |
|
map { |
67 |
|
cmp_ok($user->{$_}, 'eq', $row->{$_}, "$_"); |
68 |
|
} keys %{ $user }; |
69 |
|
} |
70 |
|
|
71 |
|
ok($msg = $node->master( |
72 |
|
action => 'userdel', |
73 |
|
name => $user->{name}, |
74 |
|
), "userdel: $msg"); |
75 |
|
|
76 |
|
ok(@users2 = $node->master( action => 'userlist' ), 'userlist'); |
77 |
|
cmp_ok($#users2, '==', $#users, 'removed user'); |
78 |
|
|
79 |
|
ok(my @nodes = $node->master( action => 'nodelist' ), 'nodelist' ); |
80 |
|
#diag "nodelist: ", Dumper( \@nodes ); |
81 |
|
diag "found ", $#nodes + 1, " nodes"; |
82 |
|
|
83 |
|
if ($#nodes > 42) { |
84 |
|
diag <<'_END_OF_WARNING_'; |
85 |
|
|
86 |
|
This tests create three nodes in your Hyper Estraier. |
87 |
|
|
88 |
|
Since you have more than 43 modes, and Hyper Estraier needs more than |
89 |
|
1024 file descriptors for more than 46 nodes, expect tests to fail. |
90 |
|
|
91 |
|
If tests do fail, you can try to add |
92 |
|
|
93 |
|
ulimit -n 2048 |
94 |
|
|
95 |
|
before staring estmaster, which will increase number of available nodes |
96 |
|
to 96 before estmaster runs out of file descriptors. |
97 |
|
|
98 |
|
_END_OF_WARNING_ |
99 |
|
} |
100 |
|
|
101 |
|
my $temp_node = "_test_temp_$$"; |
102 |
|
|
103 |
|
foreach my $node_name ( $test1_node , $test2_node, $temp_node ) { |
104 |
|
ok($msg = $node->master( |
105 |
|
action => 'nodeadd', |
106 |
|
name => $node_name, |
107 |
|
label => "$node_name label", |
108 |
|
), "nodeadd $node_name: $msg"); |
109 |
} |
} |
110 |
|
|
111 |
|
ok($msg = $node->master( |
112 |
|
action => 'nodeclr', |
113 |
|
name => $temp_node, |
114 |
|
), "nodeclr $temp_node: $msg"); |
115 |
|
|
116 |
|
ok($msg = $node->master( |
117 |
|
action => 'nodedel', |
118 |
|
name => $temp_node, |
119 |
|
), "nodedel $temp_node: $msg"); |
120 |
|
|
121 |
|
#diag "not testing logrtt\n"; |
122 |
|
|
123 |
|
# test document creation |
124 |
|
|
125 |
my $draft = <<'_END_OF_DRAFT_'; |
my $draft = <<'_END_OF_DRAFT_'; |
126 |
@uri=data001 |
@uri=data001 |
127 |
@title=Material Girl |
@title=Material Girl |
146 |
my $id; |
my $id; |
147 |
ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); |
ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); |
148 |
|
|
149 |
for ( 1 .. 5 ) { |
my $data_max = 5; |
150 |
|
|
151 |
|
for ( 1 .. $data_max ) { |
152 |
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
153 |
} |
} |
154 |
|
|
171 |
|
|
172 |
cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query'); |
cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query'); |
173 |
|
|
174 |
ok( my $nrec = $node->search( $cond, 0 ), 'search'); |
ok( my $nres = $node->search( $cond, 0 ), 'search'); |
175 |
|
|
176 |
|
isa_ok( $nres, 'Search::Estraier::NodeResult' ); |
177 |
|
|
178 |
|
cmp_ok($nres->doc_num, '==', $max, "doc_num = $max"); |
179 |
|
|
180 |
isa_ok( $nrec, 'Search::Estraier::NodeResult' ); |
cmp_ok($nres->hits, '==', $data_max, "hits"); |
181 |
|
|
182 |
cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max"); |
for my $i ( 0 .. ($nres->hits - 1) ) { |
183 |
|
my $uri = 'test' . ($i + $data_max + 1); |
184 |
|
|
185 |
for ( 6 .. 10 ) { |
if ($i < $nres->doc_num) { |
186 |
my $uri = 'test' . $_; |
ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i"); |
187 |
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri"); |
|
188 |
|
cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); |
189 |
|
ok( my $k = $rdoc->keywords( $id ), "rdoc keywords"); |
190 |
|
} |
191 |
|
|
192 |
|
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id"); |
193 |
ok( $node->get_doc( $id ), "get_doc $id"); |
ok( $node->get_doc( $id ), "get_doc $id"); |
194 |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
195 |
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"); |
196 |
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"); |
197 |
ok( my $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); |
ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); |
198 |
ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri"); |
ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri"); |
199 |
#diag Dumper($k, $k2); |
#diag Dumper($k, $k2); |
200 |
ok( eq_hash( $k, $k2 ), "keywords"); |
ok( eq_hash( $k1, $k2 ), "keywords"); |
201 |
} |
} |
202 |
|
|
203 |
|
ok(my $hints = $nres->hints, 'hints'); |
204 |
|
diag Dumper($hints); |
205 |
|
|
206 |
|
ok($node->_set_info, "refresh _set_info"); |
207 |
|
|
208 |
my $v; |
my $v; |
209 |
ok($v = $node->name, "name: $v"); |
ok($v = $node->name, "name: $v"); |
210 |
ok($v = $node->label, "label: $v"); |
ok($v = $node->label, "label: $v"); |
211 |
ok($v = $node->doc_num, "doc_num: $v"); |
ok($v = $node->doc_num, "doc_num: $v"); |
212 |
ok($v = $node->word_num, "word_num: $v"); |
ok(defined($v = $node->word_num), "word_num: $v"); |
213 |
ok($v = $node->size, "size: $v"); |
ok($v = $node->size, "size: $v"); |
214 |
|
|
215 |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
217 |
# user doesn't exist |
# user doesn't exist |
218 |
ok(! $node->set_user('foobar', 1), 'set_user'); |
ok(! $node->set_user('foobar', 1), 'set_user'); |
219 |
|
|
220 |
ok($node->set_link('test','test', 42), 'set_link test 42'); |
ok(my $node2 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node"); |
221 |
ok($node->set_link('test','test', 0), 'set_link delete'); |
ok($node2->set_auth('admin','admin'), "set_auth $test2_node"); |
222 |
|
|
223 |
|
# croak_on_error |
224 |
|
|
225 |
|
ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant"); |
226 |
|
throws_ok { $node->name } qr/404/, 'croak on error'; |
227 |
|
|
228 |
|
# croak_on_error |
229 |
|
ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node"); |
230 |
|
|
231 |
|
ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak'); |
232 |
|
|
233 |
|
|
234 |
|
# test users |
235 |
|
ok(! $node->admins, 'no admins'); |
236 |
|
ok(! $node->guests, 'no guests'); |
237 |
|
|
238 |
|
|
239 |
|
# test search without results |
240 |
|
ok($cond = new Search::Estraier::Condition, 'new cond'); |
241 |
|
ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase'); |
242 |
|
|
243 |
|
ok($nres = $node->search( $cond, 0 ), 'search'); |
244 |
|
|
245 |
|
# now, test links |
246 |
|
my $test2_label = "$test2_node label"; |
247 |
|
my $link_url = "http://localhost:1978/node/$test2_node"; |
248 |
|
ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42"); |
249 |
|
ok(my $links = $node->links, 'links'); |
250 |
|
cmp_ok($#{$links}, '==', 0, 'one link'); |
251 |
|
like($links->[0], qr/^$link_url/, 'link correct'); |
252 |
|
ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); |
253 |
|
|
254 |
|
# cleanup test nodes |
255 |
|
foreach my $node_name ( $test1_node , $test2_node ) { |
256 |
|
ok($msg = $node->master( |
257 |
|
action => 'nodedel', |
258 |
|
name => $node_name, |
259 |
|
), "nodedel $node_name: $msg"); |
260 |
|
} |
261 |
|
|
262 |
|
# test create |
263 |
|
my $node_name = '_test_create_' . $$; |
264 |
|
my $node_label = "test $$ label"; |
265 |
|
|
266 |
|
ok($node = new Search::Estraier::Node( |
267 |
|
url => "http://localhost:1978/node/$node_name", |
268 |
|
create => 1, |
269 |
|
label => $node_label, |
270 |
|
croak_on_error => 1 |
271 |
|
), "new non-existant with create"); |
272 |
|
|
273 |
|
cmp_ok($node->name, 'eq', $node_name, "node $node_name exists"); |
274 |
|
cmp_ok($node->label, 'eq', $node_label, "node label: $node_label"); |
275 |
|
|
276 |
|
ok($msg = $node->master( |
277 |
|
action => 'nodedel', |
278 |
|
name => $node_name, |
279 |
|
), "nodedel $node_name: $msg"); |
280 |
|
|
281 |
diag "over"; |
diag "over"; |