4
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
12
use Test::More tests => 4;
18
my $p = new SlowLogParser;
19
my $w = new SlowLogWriter;
22
my ( $filename, $expected ) = @_;
24
# Parse and rewrite the original file.
25
my $tmp_file = '/tmp/SlowLogWriter-test.txt';
26
open my $rewritten_fh, '>', $tmp_file
27
or die "Cannot write to $tmp_file: $OS_ERROR";
28
open my $fh, "<", "$trunk/$filename"
29
or die "Cannot open $trunk/$filename: $OS_ERROR";
31
next_event => sub { return <$fh>; },
32
tell => sub { return tell $fh; },
34
while ( my $e = $p->parse_event(%args) ) {
35
$w->write($rewritten_fh, $e);
40
# Compare the contents of the two files.
41
my $retval = system("diff $tmp_file $trunk/$expected");
43
$retval = $retval >> 8;
48
my ( $event, $expected_output ) = @_;
49
my $tmp_file = '/tmp/SlowLogWriter-output.txt';
50
open my $fh, '>', $tmp_file or die "Cannot open $tmp_file: $OS_ERROR";
51
$w->write($fh, $event);
53
my $retval = system("diff $tmp_file $trunk/$expected_output");
55
$retval = $retval >> 8;
59
# Check that I can write a slow log in the default slow log format.
61
__no_diff('t/lib/samples/slowlogs/slow001.txt', 't/lib/samples/slowlogs/slow001-rewritten.txt'),
62
'slow001.txt rewritten'
65
# Test writing a Percona-patched slow log with Thread_id and hi-res Query_time.
67
__no_diff('t/lib/samples/slowlogs/slow032.txt', 't/lib/samples/slowlogs/slow032-rewritten.txt'),
68
'slow032.txt rewritten'
75
arg => 'select * from foo',
79
't/lib/samples/slowlogs/slowlogwriter001.txt',
81
'Writes Client attrib from tcpdump',
87
Query_time => '1.123456',
88
Lock_time => '0.000001',
89
arg => 'select * from foo',
91
't/lib/samples/slowlogs/slowlogwriter002.txt',
93
'Writes microsecond times'
96
# #############################################################################
98
# #############################################################################
99
diag(`rm -rf SlowLogWriter-test.txt >/dev/null 2>&1`);