|
| 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 PerconaTest; |
| 15 | +use Sandbox; |
| 16 | +require "$trunk/bin/pt-table-sync"; |
| 17 | + |
| 18 | +my $dp = new DSNParser(opts=>$dsn_opts); |
| 19 | +my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); |
| 20 | +my $source_dbh = $sb->get_dbh_for('source'); |
| 21 | +my $replica1_dbh = $sb->get_dbh_for('replica1'); |
| 22 | + |
| 23 | +if ( !$source_dbh ) { |
| 24 | + plan skip_all => 'Cannot connect to sandbox source'; |
| 25 | +} |
| 26 | +elsif ( !$replica1_dbh ) { |
| 27 | + plan skip_all => 'Cannot connect to sandbox replica1'; |
| 28 | +} |
| 29 | +else { |
| 30 | + plan tests => 5; |
| 31 | +} |
| 32 | + |
| 33 | +my ($output, @rows); |
| 34 | + |
| 35 | +# ############################################################################# |
| 36 | +# Test generated REPLACE statements. |
| 37 | +# ############################################################################# |
| 38 | +$sb->load_file('source', "t/pt-table-sync/samples/pt-2378.sql"); |
| 39 | +$sb->wait_for_replicas(); |
| 40 | +$replica1_dbh->do("update `test`.`test_table` set `some_string` = 'c' where `id` = 1"); |
| 41 | + |
| 42 | +$output = remove_traces(output( |
| 43 | + sub { pt_table_sync::main('--sync-to-source', |
| 44 | + 'h=127.0.0.1,P=12346,u=msandbox,p=msandbox', |
| 45 | + qw(-t test.test_table --print --execute)) |
| 46 | + }, |
| 47 | +)); |
| 48 | +chomp($output); |
| 49 | +is( |
| 50 | + $output, |
| 51 | + "REPLACE INTO `test`.`test_table`(`id`, `value1`, `value2`, `some_string`) VALUES ('1', 315.25999999999942, 2.6919444444444447, 'a');", |
| 52 | + "Floating point numbers are generated with sufficient precision in REPLACE statements" |
| 53 | +); |
| 54 | + |
| 55 | +$sb->wait_for_replicas(); |
| 56 | +my $query = 'SELECT * FROM `test`.`test_table` WHERE `value1` = 315.2599999999994 AND `value2` = 2.6919444444444447'; |
| 57 | +@rows = $replica1_dbh->selectrow_array($query); |
| 58 | +is_deeply( |
| 59 | + \@rows, |
| 60 | + [1, 315.2599999999994, 2.6919444444444447, 'a'], |
| 61 | + 'Floating point values are set correctly in round trip' |
| 62 | +); |
| 63 | + |
| 64 | +# ############################################################################# |
| 65 | +# Test generated UPDATE statements. |
| 66 | +# ############################################################################# |
| 67 | +$sb->load_file('source', "t/pt-table-sync/samples/pt-2378.sql"); |
| 68 | +$sb->wait_for_replicas(); |
| 69 | +$replica1_dbh->do("update `test`.`test_table` set `some_string` = 'c' where `id` = 1"); |
| 70 | + |
| 71 | +$output = remove_traces(output( |
| 72 | + sub { pt_table_sync::main(qw(--print --execute), |
| 73 | + "h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=test_table", |
| 74 | + "h=127.0.0.1,P=12345,u=msandbox,p=msandbox,D=test,t=test_table"); |
| 75 | + } |
| 76 | +)); |
| 77 | +chomp($output); |
| 78 | +is( |
| 79 | + $output, |
| 80 | + "UPDATE `test`.`test_table` SET `value1`=315.25999999999942, `value2`=2.6919444444444447, `some_string`='c' WHERE `id`='1' LIMIT 1;", |
| 81 | + "Floating point numbers are generated with sufficient precision in UPDATE statements" |
| 82 | +); |
| 83 | + |
| 84 | +@rows = $source_dbh->selectrow_array($query); |
| 85 | +is_deeply( |
| 86 | + \@rows, |
| 87 | + [1, 315.2599999999994, 2.6919444444444447, 'c'], |
| 88 | + 'Floating point values are set correctly in round trip' |
| 89 | +); |
| 90 | + |
| 91 | +# ############################################################################# |
| 92 | +# Done. |
| 93 | +# ############################################################################# |
| 94 | +$sb->wipe_clean($source_dbh); |
| 95 | +ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); |
| 96 | +exit; |
0 commit comments