2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 51; |
use Test::More tests => 93; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
use File::Temp qw/ :mktemp /; |
use File::Temp qw/ :mktemp /; |
8 |
use blib; |
use blib; |
19 |
|
|
20 |
my %param; |
my %param; |
21 |
|
|
22 |
throws_ok { SWISH::Split->open(%param) } qr/slice_name/, "slice_name"; |
throws_ok { SWISH::Split->open_index(%param) } qr/slice_name/, "slice_name"; |
23 |
|
|
24 |
sub slice_hash { |
sub slice_hash { |
25 |
return $_[0]; |
return $_[0]; |
26 |
}; |
}; |
27 |
|
|
28 |
$param{'slice_name'} = \&slice_hash; |
$param{'slice_name'} = \&slice_hash; |
29 |
throws_ok { SWISH::Split->open(%param) } qr/slices/, "need slices"; |
throws_ok { SWISH::Split->open_index(%param) } qr/slices/, "need slices"; |
30 |
|
|
31 |
$param{'slices'} = 3; |
$param{'slices'} = 3; |
32 |
throws_ok { SWISH::Split->open(%param) } qr/index/, "need index"; |
throws_ok { SWISH::Split->open_index(%param) } qr/index/, "need index"; |
33 |
|
|
34 |
ok($param{'index'} = mktemp("/tmp/swishXXXXX"), "index name"); |
ok($param{'index'} = mktemp("/tmp/swishXXXXX"), "index name"); |
35 |
|
|
38 |
ok(open(F, "> $param{'index'}"), "touch"); |
ok(open(F, "> $param{'index'}"), "touch"); |
39 |
close(F); |
close(F); |
40 |
|
|
41 |
throws_ok { SWISH::Split->open(%param) } qr/dir/, "need dir"; |
throws_ok { SWISH::Split->open_index(%param) } qr/dir/, "need dir"; |
42 |
|
|
43 |
ok(unlink($param{'index'}), "rm"); |
ok(unlink($param{'index'}), "rm"); |
44 |
|
|
48 |
PropertyNames foo |
PropertyNames foo |
49 |
}; |
}; |
50 |
|
|
51 |
ok(my $i=SWISH::Split->open(%param), "open"); |
$param{'debug'} = 1 if (@ARGV); |
52 |
|
|
53 |
cmp_ok(my $s = $i->in_slice("swishpath"), '==', 1, "open"); |
ok(my $i=SWISH::Split->open_index(%param), "open_index"); |
54 |
|
|
55 |
|
cmp_ok(my $s = $i->in_slice("swishpath"), '==', 1, "open_index"); |
56 |
|
|
57 |
ok(my $config = $i->make_config($s), "make_config"); |
ok(my $config = $i->make_config($s), "make_config"); |
58 |
diag "swish config: $config"; |
diag "swish config: $config"; |
103 |
|
|
104 |
ok(my $result = $results->NextResult, "get result"); |
ok(my $result = $results->NextResult, "get result"); |
105 |
|
|
106 |
cmp_ok($result->Property('swishdocpath'), '==', $path, "correct swishdocpath") if ($path); |
SKIP: { |
107 |
cmp_ok($result->Property('swishdocsize'), '==', $size, "correct swishdocsize") if (defined($size)); |
skip "no results found, skipping property test", 3 unless ($result); |
108 |
cmp_ok($result->Property($prop), '==', $val, "correct data") if (defined($prop) && defined($val)); |
|
109 |
|
cmp_ok($result->Property('swishdocpath'), '==', $path, "correct swishdocpath") if ($path); |
110 |
|
cmp_ok($result->Property('swishdocsize'), '==', $size, "correct swishdocsize") if (defined($size)); |
111 |
|
cmp_ok($result->Property($prop), '==', $val, "correct data") if (defined($prop) && defined($val)); |
112 |
|
} |
113 |
} |
} |
114 |
|
|
115 |
swish_search($test_index, "foo=(bar)", 1, "testpath", length($xml), "foo", "bar"); |
swish_search($test_index, "foo=(bar)", 1, "testpath", length($xml), "foo", "bar"); |
118 |
|
|
119 |
# now, test slice handling |
# now, test slice handling |
120 |
|
|
121 |
ok(my $slice = $i->create_slice('testpath'), "create_slice"); |
ok($s = $i->create_slice('testpath'), "create_slice $s"); |
122 |
|
|
123 |
ok($i->put_slice('testpath', $xml), "put_slice"); |
ok($s = $i->put_slice('testpath', $xml), "put_slice $s"); |
124 |
|
|
125 |
ok($i->close_slice($slice), "close_slice"); |
ok($i->close_slice($s), "close_slice $s"); |
126 |
|
|
127 |
swish_search($param{'index'}."/$slice", "foo=(bar)", 1, "testpath", length($xml)+1, "foo", "bar"); |
swish_search($param{'index'}."/$s", "foo=(bar)", 1, "testpath", length($xml)+1, "foo", "bar"); |
128 |
|
|
129 |
diag "slice handling o.k."; |
diag "slice $s handling o.k."; |
130 |
|
|
131 |
ok($i->add('testpath',{ foo => 'bar' }),"add foo"); |
my %slice_files; |
132 |
|
ok($s = $i->add('testpath',{ foo => 'bar' }),"add foo [slice $s]"); |
133 |
|
$slice_files{$s}++; |
134 |
|
|
135 |
foreach (1..$param{'slices'} * 3) { |
foreach (1..$param{'slices'} * 10) { |
136 |
ok($i->add('testpath'.$_,{ 'foo' => 'bar'.$_ }), "add $_"); |
ok($s = $i->add('testpath'.$_,{ 'foo' => sprintf("bar%04d", $_) }), "add $_ [slice $s]"); |
137 |
|
$slice_files{$s}++; |
138 |
} |
} |
139 |
|
|
140 |
cmp_ok($i->done, '==', 3, "finish"); |
cmp_ok($i->done, '==', 3, "finish"); |
141 |
|
|
142 |
|
foreach (1..$param{'slices'}) { |
143 |
|
swish_search( $param{'index'}."/$_", "foo=(bar*)", $slice_files{$_}, "testpath", undef, "foo", "bar"); |
144 |
|
} |
145 |
|
|
146 |
#diag "$out"; |
#diag "$out"; |