~percona-toolkit-dev/percona-toolkit/2.1

« back to all changes in this revision

Viewing changes to t/pt-table-sync/traces.t

  • Committer: Daniel Nichter
  • Date: 2012-06-10 17:22:26 UTC
  • mfrom: (94.2.184 stabilize-test-suite)
  • Revision ID: daniel@percona.com-20120610172226-o6hlagf8trz1cktx
MergeĀ ~percona-toolkit-dev/percona-toolkit/stabilize-test-suite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env perl
2
2
 
 
3
# This test's purpose: determine whether the SQL that pt-table-sync executes has
 
4
# distinct marker comments in it to identify the DML statements for DBAs to
 
5
# recognize. This is important for diagnosing what's in your binary log.
 
6
 
3
7
BEGIN {
4
8
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
9
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
21
25
my $slave_dbh  = $sb->get_dbh_for('slave1');
22
26
 
23
27
my $mysqlbinlog = `which mysqlbinlog`;
24
 
chomp $mysqlbinlog if $mysqlbinlog;
 
28
if ( $mysqlbinlog ) {
 
29
   chomp $mysqlbinlog;
 
30
}
 
31
elsif ( -x "$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog" ) {
 
32
   $mysqlbinlog = "$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog";
 
33
}
25
34
 
26
35
if ( !$master_dbh ) {
27
36
   plan skip_all => 'Cannot connect to sandbox master';
33
42
   plan skip_all => 'Cannot find mysqlbinlog';
34
43
}
35
44
else {
36
 
   plan tests => 1;
 
45
   plan tests => 2;
37
46
}
38
47
 
39
 
my $output;
40
 
my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox', qw(--sync-to-master --execute -t onlythisdb.t));
41
 
 
42
 
diag(`$trunk/sandbox/test-env reset`);
 
48
# We execute the test by changing a table so pt-table-sync will find something
 
49
# to modify.  Then we examine the binary log to find the SQL in it, and check
 
50
# that.
43
51
$sb->load_file('master', "t/pt-table-sync/samples/issue_533.sql");
44
 
sleep 1;
45
 
 
46
 
$slave_dbh->do('insert into onlythisdb.t values (5)');
47
 
 
 
52
my $pos = $master_dbh->selectrow_hashref('show master status');
 
53
diag("Master position: $pos->{file} / $pos->{position}");
 
54
 
 
55
my @args = ('h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=t1', 't=t2', '--execute');
48
56
output(
49
57
   sub { pt_table_sync::main(@args) },
50
58
);
51
59
 
52
 
my $binlog = $master_dbh->selectrow_arrayref('show master logs');
53
 
 
54
 
$output = `$mysqlbinlog /tmp/12345/data/$binlog->[0] | grep 'percona-toolkit'`;
55
 
$output =~ s/pid:\d+/pid:0/ if $output;
56
 
$output =~ s/host:\S+?\*/host:-*/ if $output;
57
 
is(
 
60
# The statement really ought to look like this:
 
61
# "DELETE FROM `test`.`t2` WHERE `i`='5' LIMIT 1 /*percona-toolkit
 
62
# src_db:test src_tbl:t1 src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox
 
63
# dst_db:test dst_tbl:t2 dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox
 
64
# lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0
 
65
# user:$ENV{USER} host:-*/
 
66
my $output = `$mysqlbinlog /tmp/12345/data/$pos->{file} --start-position=$pos->{position} | grep 'percona-toolkit'`;
 
67
like(
58
68
   $output,
59
 
"DELETE FROM `onlythisdb`.`t` WHERE `i`='5' LIMIT 1 /*percona-toolkit src_db:onlythisdb src_tbl:t src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox dst_db:onlythisdb dst_tbl:t dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0 user:$ENV{USER} host:-*/
60
 
",
 
69
   qr/DELETE FROM.*test`.`t2.*percona-toolkit src_db:test.*user:$ENV{USER}/,
61
70
   "Trace message appended to change SQL"
62
71
);
63
72
 
65
74
# Done.
66
75
# #############################################################################
67
76
$sb->wipe_clean($master_dbh);
 
77
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
68
78
exit;