~hingo/percona-toolkit/pqd-mongodb-24

3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
1
#!/usr/bin/env perl
2
3
BEGIN {
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";
7
};
8
9
use strict;
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
12
use Test::More;
13
14
use Sandbox;
23 by Daniel Nichter
Change MaatkitTest to PerconaTest in all tool tests. Add stub tests for pt-align and pt-collect.
15
use PerconaTest;
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
16
# See 101_slowlog_analyses.t for why we shift.
17
shift @INC;  # our unshift (above)
23 by Daniel Nichter
Change MaatkitTest to PerconaTest in all tool tests. Add stub tests for pt-align and pt-collect.
18
shift @INC;  # PerconaTest's unshift
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
19
shift @INC;  # Sandbox
20
21
require "$trunk/bin/pt-query-digest";
22
23
my $dp  = new DSNParser(opts=>$dsn_opts);
24
my $sb  = new Sandbox(basedir => '/tmp', DSNParser => $dp);
25
my $dbh = $sb->get_dbh_for('master');
26
27
if ( !$dbh ) {
28
   plan skip_all => 'Cannot connect to sandbox master';
29
}
30
else {
94.2.51 by Daniel Nichter
Fix test counts.
31
   plan tests => 6;
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
32
}
33
34
my $output = '';
35
my $cnf    = 'h=127.1,P=12345,u=msandbox,p=msandbox';
36
my @args   = qw(--report-format=query_report --limit 10 --stat);
37
38
$sb->create_dbs($dbh, [qw(test)]);
39
$dbh->do('use test');
40
$dbh->do('create table foo (a int, b int, c int)');
41
42
is_deeply(
43
   $dbh->selectall_arrayref('select * from test.foo'),
44
   [],
45
   'No rows in table yet'
46
);
47
48
ok(
49
   no_diff(
7 by Daniel Nichter
Change mk_tool::main() to pt_tool::main() in all tests.
50
      sub { pt_query_digest::main(@args, '--execute', $cnf,
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
51
         "$trunk/t/lib/samples/slowlogs/slow018.txt") },
55 by Daniel
Fix Bash tests. Add basic pt-align tests.
52
      't/pt-query-digest/samples/slow018_execute_report_1.txt',
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
53
   ),
54
   '--execute without database'
55
);
56
57
is_deeply(
58
   $dbh->selectall_arrayref('select * from test.foo'),
59
   [],
60
   'Still no rows in table'
61
);
62
63
# Provide a default db to make --execute work.
64
$cnf .= ',D=test';
65
66
# TODO: This test is a PITA because every time the mqd output
67
# changes the -n of tail has to be adjusted.
68
94.2.1 by Daniel Nichter
Various test tweaks for stability.
69
# 
70
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
71
# We tail to get everything from "Exec orig" onward.  The lines
72
# above have the real execution time will will vary.  The last 18 lines
73
# are sufficient to see that it actually executed without errors.
74
ok(
75
   no_diff(
7 by Daniel Nichter
Change mk_tool::main() to pt_tool::main() in all tests.
76
      sub { pt_query_digest::main(@args, '--execute', $cnf,
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
77
         "$trunk/t/lib/samples/slowlogs/slow018.txt") },
78
      't/pt-query-digest/samples/slow018_execute_report_2.txt',
55 by Daniel
Fix Bash tests. Add basic pt-align tests.
79
      trf => 'tail -n 30',
94.2.1 by Daniel Nichter
Various test tweaks for stability.
80
      sed => ["-e 's/s  ##*/s/g'"],
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
81
   ),
82
   '--execute with default database'
83
);
84
85
is_deeply(
86
   $dbh->selectall_arrayref('select * from test.foo'),
87
   [[qw(1 2 3)],[qw(4 5 6)]],
88
   'Rows in table'
89
);
90
91
# #############################################################################
92
# Done.
93
# #############################################################################
94
$sb->wipe_clean($dbh);
94.2.41 by Daniel Nichter
Call Sandbox::box() in all tests that use Sandbox.
95
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
3 by Daniel Nichter
Add forked Maatkit tools in bin/ and their tests in t/.
96
exit;