From dfcb7dc157b6ce55dc8486ce32c1f9078655e217 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 13 Oct 2011 11:57:32 -0600 Subject: [PATCH] Move issue_21. tests into basics.t and remove issue_21.t. Remove other unused sample files. --- t/pt-table-checksum/basics.t | 37 +++++++- t/pt-table-checksum/issue_1182.t | 59 ------------ t/pt-table-checksum/issue_21.t | 92 ------------------- .../samples/basic_replicate_output | 2 - .../samples/char-chunk-ascii-oversize.txt | 9 -- t/pt-table-checksum/samples/issue_21.sql | 8 +- 6 files changed, 41 insertions(+), 166 deletions(-) delete mode 100644 t/pt-table-checksum/issue_1182.t delete mode 100644 t/pt-table-checksum/issue_21.t delete mode 100644 t/pt-table-checksum/samples/basic_replicate_output delete mode 100644 t/pt-table-checksum/samples/char-chunk-ascii-oversize.txt diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index eb947bbe..656b5126 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -31,7 +31,7 @@ elsif ( !@{$master_dbh->selectall_arrayref('show databases like "sakila"')} ) { plan skip_all => 'sakila database is not loaded'; } else { - plan tests => 7; + plan tests => 8; } # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic @@ -139,6 +139,41 @@ is( # Restore the row on the slave, else other tests will fail. $slave_dbh->do("update sakila.city set city='$row->[0]', last_update='$row->[1]' where city_id=1"); +# ############################################################################# +# --[no]empty-replicate-table +# Issue 21: --empty-replicate-table doesn't empty if previous runs leave info +# ############################################################################# + +$sb->wipe_clean($master_dbh); +$sb->load_file('master', 't/pt-table-checksum/samples/issue_21.sql'); + +# Run once to populate the repl table. +pt_table_checksum::main(@args, qw(--quiet --quiet -t test.issue_21), + qw(--chunk-time 0 --chunk-size 2)); + +# Insert two fake rows into the repl table. The first row tests that +# --empty-replicate-table deletes all rows for each checksummed table, +# and the second row tests that if a table isn't checksummed, then its +# rows aren't deleted. +$master_dbh->do("INSERT INTO percona.checksums VALUES ('test', 'issue_21', 999, 0.00, 'idx', '0', '0', '0', 0, '0', 0, NOW())"); +$master_dbh->do("INSERT INTO percona.checksums VALUES ('test', 'other_tbl', 1, 0.00, 'idx', '0', '0', '0', 0, '0', 0, NOW())"); + +pt_table_checksum::main(@args, qw(--quiet --quiet -t test.issue_21), + qw(--chunk-time 0 --chunk-size 2)); + +$row = $master_dbh->selectall_arrayref("SELECT tbl, chunk FROM percona.checksums WHERE db='test' ORDER BY tbl, chunk"); +is_deeply( + $row, + [ + [qw(issue_21 1)], + [qw(issue_21 2)], + [qw(issue_21 3)], + # fake row for chunk 999 is gone + [qw(other_tbl 1)], # this row is still here + ], + "--emptry-replicate-table on by default" +) or print STDERR Dumper($row); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-table-checksum/issue_1182.t b/t/pt-table-checksum/issue_1182.t deleted file mode 100644 index 2f1ee9b7..00000000 --- a/t/pt-table-checksum/issue_1182.t +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env perl - -BEGIN { - die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" - unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; - unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; -}; - -use strict; -use warnings FATAL => 'all'; -use English qw(-no_match_vars); -use Test::More; - -use PerconaTest; -use Sandbox; -require "$trunk/bin/pt-table-checksum"; - -my $dp = new DSNParser(opts=>$dsn_opts); -my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); - -if ( !$dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; -} -elsif ( !@{$dbh->selectcol_arrayref('SHOW DATABASES LIKE "sakila"')} ) { - plan skip_all => 'sakila database is not loaded'; -} -else { - plan tests => 1; -} - -my $output; -my $cnf = '/tmp/12345/my.sandbox.cnf'; -my $cmd = "$trunk/bin/pt-table-checksum -F $cnf -t sakila.film --chunk-size 100"; - -# ############################################################################# -# Issue 1182: mk-table-checksum not respecting chunk size -# ############################################################################# - -# Unfortunately we don't have a good method for testing that the tool -# uses the correct chunks. That's tested directly in TableChunker.t. -# So here we make sure that --chunk-range doesn't affect anything; it -# should chunk and checksum identically to not using --chunk-range. - -diag(`rm -rf /tmp/mk-checksum-test-output-?.txt`); - -`$cmd >/tmp/mk-table-checksum-test-output-1.txt`; -`$cmd --chunk-range openclosed >/tmp/mk-table-checksum-test-output-2.txt`; - -is( - `diff /tmp/mk-table-checksum-test-output-1.txt /tmp/mk-table-checksum-test-output-2.txt`, - "", - "--chunk-range does not alter chunks or checksums" -); - -# ############################################################################# -# Done. -# ############################################################################# -exit; diff --git a/t/pt-table-checksum/issue_21.t b/t/pt-table-checksum/issue_21.t deleted file mode 100644 index b7e108d3..00000000 --- a/t/pt-table-checksum/issue_21.t +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env perl - -BEGIN { - die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" - unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; - unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; -}; - -use strict; -use warnings FATAL => 'all'; -use English qw(-no_match_vars); -use Test::More; - -use PerconaTest; -use Sandbox; -require "$trunk/bin/pt-table-checksum"; - -my $dp = new DSNParser(opts=>$dsn_opts); -my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); - -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; -} -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; -} -else { - plan tests => 5; -} - -my $output; -my $ret_val; -my $cnf='/tmp/12345/my.sandbox.cnf'; -my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1"; - -$sb->wipe_clean($master_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); - -# ############################################################################# -# Issue 21: --empty-replicate-table doesn't empty if previous runs leave info -# ############################################################################# - -# This test requires that the test db has only the table created by -# issue_21.sql. If there are other tables, the first test below -# will fail because samples/basic_replicate_output will differ. -$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql'); -$sb->load_file('master', 't/pt-table-checksum/samples/issue_21.sql'); - -# Run --replication once to populate test.checksum. -$ret_val = system("$cmd -d test --replicate test.checksum | diff $trunk/t/pt-table-checksum/samples/basic_replicate_output -"); -# Might as well test this while we're at it. -cmp_ok($ret_val >> 8, '==', 0, 'Basic --replicate works'); - -# Insert a bogus row into test.checksum. -diag(`/tmp/12345/use -e "INSERT INTO test.checksum VALUES ('foo', 'bar', 0, 'a', 'b', 0, 'c', 0, NOW())"`); - -# Run --replicate again which should completely clear test.checksum, -# including our bogus row. -`$cmd --replicate test.checksum -d test --empty-replicate-table >/dev/null`; - -# Make sure bogus row is actually gone. -$output = `/tmp/12345/use -e "SELECT db FROM test.checksum WHERE db = 'foo'"`; -unlike($output, qr/foo/, '--empty-replicate-table completely empties the table (fixes issue 21)'); - -# While we're at it, let's test what the doc says about --empty-replicate-table: -# "Ignored if L<"--replicate"> is not specified." -diag(`/tmp/12345/use -e "INSERT INTO test.checksum VALUES ('foo', 'bar', 0, 'a', 'b', 0, 'c', 0, NOW())"`); -`$cmd P=12346 --empty-replicate-table >/dev/null`; - -# Now make sure bogus row is still present. -$output = `/tmp/12345/use -e "SELECT db FROM test.checksum WHERE db = 'foo';"`; -like($output, qr/foo/, '--empty-replicate-table is ignored if --replicate is not specified'); - -diag(`/tmp/12345/use -e "DELETE FROM test.checksum WHERE db = 'foo'"`); - -# Screw up the data on the slave and make sure --replicate-check works -$slave_dbh->do("update test.checksum set this_crc='' where test.checksum.tbl = 'issue_21'"); - -# Can't use $cmd here; see http://code.google.com/p/maatkit/issues/detail?id=802 -$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --replicate test.checksum --replicate-check 1 2>&1`; -like($output, qr/issue_21/, '--replicate-check works'); - -cmp_ok($CHILD_ERROR>>8, '==', 1, 'Exit status is correct with --replicate-check failure'); - -# ############################################################################# -# Done. -# ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -exit; diff --git a/t/pt-table-checksum/samples/basic_replicate_output b/t/pt-table-checksum/samples/basic_replicate_output deleted file mode 100644 index 25e44ba2..00000000 --- a/t/pt-table-checksum/samples/basic_replicate_output +++ /dev/null @@ -1,2 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test issue_21 0 127.0.0.1 InnoDB 5 b88b4eff 0 NULL NULL NULL diff --git a/t/pt-table-checksum/samples/char-chunk-ascii-oversize.txt b/t/pt-table-checksum/samples/char-chunk-ascii-oversize.txt deleted file mode 100644 index 27342b67..00000000 --- a/t/pt-table-checksum/samples/char-chunk-ascii-oversize.txt +++ /dev/null @@ -1,9 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test ascii 0 127.1 MyISAM 1 25e3643f 0 0 NULL NULL -test ascii 1 127.1 MyISAM 2 1eb24fbb 0 0 NULL NULL -test ascii 2 127.1 MyISAM 0 NULL 0 0 NULL NULL -test ascii 3 127.1 MyISAM 2 fb3ab74d 0 0 NULL NULL -test ascii 4 127.1 MyISAM 51 7c2180e8 0 0 NULL NULL -test ascii 5 127.1 MyISAM 50 b65cecbd 0 0 NULL NULL -test ascii 6 127.1 MyISAM 31 77958122 0 0 NULL NULL -test ascii 7 127.1 MyISAM 5 3c0ef0c2 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/issue_21.sql b/t/pt-table-checksum/samples/issue_21.sql index 1c4283e5..82cf6661 100644 --- a/t/pt-table-checksum/samples/issue_21.sql +++ b/t/pt-table-checksum/samples/issue_21.sql @@ -1,7 +1,9 @@ +DROP DATABASE IF EXISTS test; +CREATE DATABASE test; USE test; -DROP TABLE IF EXISTS issue_21; CREATE TABLE issue_21 ( a INT, - b CHAR(1) + b CHAR(1), + UNIQUE INDEX (a) ) ENGINE=InnoDB; -INSERT INTO issue_21 VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'); +INSERT INTO issue_21 VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'f');