line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Groonga; |
2
|
1
|
|
|
1
|
|
182204
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
113
|
|
4
|
1
|
|
|
1
|
|
10
|
use File::Spec (); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
5
|
use File::Temp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
1368
|
use File::Which (); |
|
1
|
|
|
|
|
1523
|
|
|
1
|
|
|
|
|
104
|
|
7
|
1
|
|
|
1
|
|
1145
|
use Test::TCP 1.10; |
|
1
|
|
|
|
|
65881
|
|
|
1
|
|
|
|
|
929
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub create { |
12
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
13
|
0
|
0
|
|
|
|
0
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
14
|
|
|
|
|
|
|
|
15
|
0
|
|
0
|
|
|
0
|
my $command_version = delete $args{default_command_version} || undef; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
0
|
my $protocol = delete $args{protocol} |
18
|
|
|
|
|
|
|
or Carp::croak("Missing params 'protocol'"); |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
0
|
$protocol =~ m/(?:gqtp|http)/ |
21
|
|
|
|
|
|
|
or Carp::croak('protocol must be gqtp or http'); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
0
|
my $preload = delete $args{preload} || undef; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
$class->_get_test_tcp( |
26
|
|
|
|
|
|
|
protocol => $protocol, |
27
|
|
|
|
|
|
|
preload => $preload, |
28
|
|
|
|
|
|
|
default_command_version => $command_version, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub gqtp { |
34
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
35
|
0
|
0
|
|
|
|
0
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
warn 'deprecated..'; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
$class->_get_test_tcp( %args, protocol => 'gqtp'); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub http { |
43
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
44
|
0
|
0
|
|
|
|
0
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
warn 'deprecated..'; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$class->_get_test_tcp( %args, protocol => 'http'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _get_test_tcp { |
52
|
0
|
|
|
0
|
|
0
|
my ($class, %args) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
0
|
|
|
0
|
my $preload = $args{preload} || undef; |
55
|
0
|
0
|
|
|
|
0
|
my $protocol = $args{protocol} or die; |
56
|
0
|
|
|
|
|
0
|
my $cmd_version = $args{default_command_version}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
### load data from dump file if you specified it. |
59
|
0
|
0
|
0
|
|
|
0
|
if ($preload and not -e $preload) { |
60
|
0
|
|
|
|
|
0
|
Carp::croak("Couldn't find file: $preload"); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
my $bin = _find_groonga_bin(); |
64
|
0
|
0
|
|
|
|
0
|
Carp::croak('groonga binary is not found') unless $bin; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
### groonga create some shard files. |
67
|
|
|
|
|
|
|
### ex. tmp/test.groonga.db, tmp/test.groonga.db.0000000, ... |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
my $db = |
70
|
|
|
|
|
|
|
File::Spec->catfile( File::Temp::tempdir( CLEANUP => 1 ), 'test.db' ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return my $server = Test::TCP->new( |
73
|
|
|
|
|
|
|
code => sub { |
74
|
0
|
|
|
0
|
|
0
|
my $port = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
`$bin --default-command-version $cmd_version -n $db < $preload` if $preload; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# -s : server mode |
79
|
|
|
|
|
|
|
# -n : create a new db |
80
|
0
|
0
|
|
|
|
0
|
my @cmd = ( |
|
|
0
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$bin, '-s', |
82
|
|
|
|
|
|
|
$cmd_version ? ('--default-command-version', $cmd_version) : (), |
83
|
|
|
|
|
|
|
'--port', $port, |
84
|
|
|
|
|
|
|
'--protocol', $protocol, |
85
|
|
|
|
|
|
|
$preload ? $db : ( '-n', $db ) |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
exec @cmd; |
89
|
0
|
|
|
|
|
0
|
die "cannot execute $bin: $!"; |
90
|
|
|
|
|
|
|
}, |
91
|
0
|
|
|
|
|
0
|
); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
1
|
|
12
|
sub _find_groonga_bin { scalar File::Which::which('groonga'); } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |