line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Driver::TokyoTyrant; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
760
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw(CHI::t::Driver); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1211
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1182
|
use POSIX qw/SIGTERM WNOHANG :sys_wait_h/; |
|
1
|
|
|
|
|
9522
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
3275
|
use File::Slurp; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use File::Temp qw/ :POSIX /; |
11
|
|
|
|
|
|
|
use File::Spec; |
12
|
|
|
|
|
|
|
use Config; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$File::Temp::KEEP_ALL = 1; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub testing_driver_class { 'CHI::Driver::TokyoTyrant' } |
18
|
|
|
|
|
|
|
sub supports_get_namespaces { 1 } |
19
|
|
|
|
|
|
|
sub supports_clear { 1 } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $ttserver; |
22
|
|
|
|
|
|
|
my $pid_file; |
23
|
|
|
|
|
|
|
my $port = 21000; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub required_modules { |
26
|
|
|
|
|
|
|
return { TokyoTyrant => undef, 'File::Temp' => undef, POSIX => 'SIGTERM WNOHANG :sys_wait_h', |
27
|
|
|
|
|
|
|
'File::Slurp' => undef, 'File::Spec' => undef, Config => undef, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub start_server : Test(startup) { |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$pid_file = tmpnam(); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $bin = _find_bin(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
die "Cannot find ttserver" unless $bin; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $started = 0; |
45
|
|
|
|
|
|
|
foreach my $i (0 .. 3) { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $use_port = $port + $i; |
48
|
|
|
|
|
|
|
system("$bin -dmn -pid $pid_file -port $use_port -log /tmp/ttlog"); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if ($? == -1 || ! $? & 127) { |
51
|
|
|
|
|
|
|
$started = 1; |
52
|
|
|
|
|
|
|
$port = $use_port; |
53
|
|
|
|
|
|
|
last; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
die "cannot execute ttserver" unless $started; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $ttserver_pid = read_file($pid_file) || die "Cannot read pid file $pid_file: $!"; |
60
|
|
|
|
|
|
|
die "ttserver execution failed" unless $ttserver_pid; |
61
|
|
|
|
|
|
|
$self->{ttserver_pid} = $ttserver_pid; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub stop_server : Test(shutdown) { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return unless defined $self->{ttserver_pid}; |
72
|
|
|
|
|
|
|
my $sig ||= SIGTERM; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
kill $sig, $self->{ttserver_pid}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
delete $self->{ttserver_pid}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
unlink $pid_file; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub SKIP_CLASS { |
84
|
|
|
|
|
|
|
my $class = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $bin = _find_bin(); |
88
|
|
|
|
|
|
|
return "cannot find ttserver" unless $bin; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return 0; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new_cache_options { |
96
|
|
|
|
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return ( $self->SUPER::new_cache_options(), port => $port ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _find_bin { |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my @paths = File::Spec->path(); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $searched_binary = 'ttserver'; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if ($Config{_exe}) { |
109
|
|
|
|
|
|
|
$searched_binary .= $Config{_exe}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
for my $path (@paths) { |
113
|
|
|
|
|
|
|
my $bin = File::Spec->catfile($path, $searched_binary); |
114
|
|
|
|
|
|
|
return $bin if -x $bin; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |