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 => 27;
16
require "$trunk/bin/pt-table-sync";
20
return mk_table_sync::cmp_conflict_col(@_);
23
# These constants are from mk-table-sync, defined just
24
# before sub cmp_conflict_col().
25
use constant UPDATE_LEFT => -1;
26
use constant UPDATE_RIGHT => 1;
27
use constant UPDATE_NEITHER => 0; # neither value equals/matches
28
use constant FAILED_THRESHOLD => 2; # failed to exceed threshold
30
# #############################################################################
32
# #############################################################################
34
sub { mk_table_sync::cmp_conflict_col(1, 2, 'bad') },
35
qr/Invalid comparison: bad/,
36
'Dies on invalid comparison'
39
# ###########################################################################
41
# ###########################################################################
43
_cmp('2009-12-01 12:00:00', '2009-12-01 12:00:00', 'newest'),
49
_cmp('2009-12-01 12:00:00', '2009-12-01 12:00:011', 'newest'),
55
_cmp('2009-12-01 12:00:00', '2009-12-01 12:00:011', 'oldest'),
61
_cmp('2009-12-01 13:00:00', '2009-12-01 12:00:011', 'newest'),
63
'newest datetime (reversed)'
67
_cmp('2009-12-01 13:00:00', '2009-12-01 12:00:011', 'oldest'),
69
'oldest datetime (reversed)'
73
_cmp('2009-12-01', '2009-12-02', 'newest'),
79
_cmp('2009-12-01', '2009-12-02', 'oldest'),
85
_cmp('12:00:00', '12:00:011', 'newest'),
91
_cmp('12:00:00', '12:00:011', 'oldest'),
97
_cmp('2009-12-01 12:00:00', '2009-12-01 12:05:00', 'newest', undef,
100
'newest datetime, threshold ok'
104
_cmp('2009-12-01 12:00:00', '2009-12-01 12:05:00', 'newest', undef,
107
'newest datetime, failed threshold'
111
_cmp('2009-12-01 12:00:00', '2009-12-01 12:05:00', 'oldest', undef,
114
'oldest datetime, threshold ok'
118
_cmp('2009-12-01 12:00:00', '2009-12-01 12:05:00', 'oldest', undef,
121
'oldest datetime, failed threshold'
125
_cmp('2009-12-01', '2009-12-03', 'newest', undef,
128
'newest date, threshold ok'
132
_cmp('2009-12-01', '2009-12-03', 'newest', undef,
135
'newest date, failed threshold'
138
# ###########################################################################
140
# ###########################################################################
142
_cmp(11, 11, 'greatest'),
148
_cmp(11, 10, 'greatest'),
154
_cmp(11, 10, 'least'),
160
_cmp(20, 10, 'least', undef, 10),
162
'least, threshold ok'
166
_cmp(20, 10, 'least', undef, 11),
168
'least, failed threshold'
171
# #############################################################################
173
# #############################################################################
175
_cmp('foo', 'bar', 'equals', 'foo'),
177
'equals left, update right'
181
_cmp('foo', 'bar', 'equals', 'bar'),
183
'equals right, update left'
187
_cmp('foo', 'bar', 'equals', 'banana'),
192
# #############################################################################
194
# #############################################################################
196
_cmp('foo', 'bar', 'matches', '^f..'),
198
'matches left, update right'
202
_cmp('foo', 'bar', 'matches', '.[ar]+$'),
204
'matches right, update left'
208
_cmp('foo', 'bar', 'matches', '^foo.$'),
213
# #############################################################################
215
# #############################################################################