1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/usr/bin/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 tests => 5;
use TableSyncStream;
use Quoter;
use MockSth;
use RowDiff;
use ChangeHandler;
use PerconaTest;
my $q = new Quoter();
my @rows;
throws_ok(
sub { new TableSyncStream() },
qr/I need a Quoter/,
'Quoter required'
);
my $t = new TableSyncStream(
Quoter => $q,
);
my $ch = new ChangeHandler(
Quoter => $q,
right_db => 'test',
right_tbl => 'foo',
left_db => 'test',
left_tbl => 'foo',
replace => 0,
actions => [ sub { push @rows, $_[0] }, ],
queue => 0,
);
$t->prepare_to_sync(
ChangeHandler => $ch,
cols => [qw(a b c)],
buffer_in_mysql => 1,
);
is(
$t->get_sql(
where => 'foo=1',
database => 'test',
table => 'foo',
),
"SELECT SQL_BUFFER_RESULT `a`, `b`, `c` FROM `test`.`foo` WHERE foo=1",
'Got SQL with SQL_BUFFER_RESULT OK',
);
$t->prepare_to_sync(
ChangeHandler => $ch,
cols => [qw(a b c)],
);
is(
$t->get_sql(
where => 'foo=1',
database => 'test',
table => 'foo',
),
"SELECT `a`, `b`, `c` FROM `test`.`foo` WHERE foo=1",
'Got SQL OK',
);
# Changed from undef to 0 due to r4802.
is( $t->done, 0, 'Not done yet' );
my $d = new RowDiff( dbh => 1 );
$d->compare_sets(
left_sth => new MockSth(
{ a => 1, b => 2, c => 3 },
{ a => 2, b => 2, c => 3 },
{ a => 3, b => 2, c => 3 },
# { a => 4, b => 2, c => 3 },
),
right_sth => new MockSth(
# { a => 1, b => 2, c => 3 },
{ a => 2, b => 2, c => 3 },
{ a => 3, b => 2, c => 3 },
{ a => 4, b => 2, c => 3 },
),
syncer => $t,
tbl_struct => {},
);
is_deeply(
\@rows,
[
"INSERT INTO `test`.`foo`(`a`, `b`, `c`) VALUES ('1', '2', '3')",
"DELETE FROM `test`.`foo` WHERE `a`='4' AND `b`='2' AND `c`='3' LIMIT 1",
],
'rows from handler',
);
|