1#!/usr/bin/env perl 2 3BEGIN { 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 9use strict; 10use warnings FATAL => 'all'; 11use English qw(-no_match_vars); 12use Test::More; 13 14use PerconaTest; 15require "$trunk/bin/pt-table-checksum"; 16 17my $output; 18 19# Calling the tool pt_table_checksum::main() doesn't work when we're 20# dealing with cmd line option error and --help because OptionParser 21# exits on such things which would cause this test to exit too. 22 23# ############################################################################ 24# Check default values for some options to ensure something wasn't 25# changed accidentally. A lot of tests rely on these defaults, so 26# if they change, it can have weird side-effects. 27# ############################################################################ 28$output = `$trunk/bin/pt-table-checksum h=127.1 --help`; 29 30like( 31 $output, 32 qr/^ --check-replication-filters\s+TRUE$/m, 33 "Default --check-replication-filters=TRUE" 34); 35 36like( 37 $output, 38 qr/^ --create-replicate-table\s+TRUE$/m, 39 "Default --create-replicate-table=TRUE" 40); 41 42like( 43 $output, 44 qr/^ --empty-replicate-table\s+TRUE$/m, 45 "Default --empty-replicate-table=TRUE" 46); 47 48like( 49 $output, 50 qr/^ --explain\s+0$/m, 51 "Default --explain=0" 52); 53 54like( 55 $output, 56 qr/^ --host\s+localhost$/m, 57 "Default --host=localhost" 58); 59 60#like( 61# $output, 62# qr/^ --lock-wait-timeout\s+1$/m, 63# "Default --lock-wait-timeout=1" 64#); 65 66like( 67 $output, 68 qr/^ --max-lag\s+1$/m, 69 "Default --max-lag=1" 70); 71 72like( 73 $output, 74 qr/^ --quiet\s+0$/m, 75 "Default --quiet=0" 76); 77 78like( 79 $output, 80 qr/^ --replicate-check-only\s+FALSE$/m, 81 "Default --replicate-check-only=FALSE" 82); 83 84like( 85 $output, 86 qr/^ --replicate\s+percona\.checksums$/m, 87 "Default --replicate=percona.checksums" 88); 89 90like( 91 $output, 92 qr/^ --replicate-check\s+TRUE$/m, 93 "Default --replicate-check=TRUE" 94); 95 96like( 97 $output, 98 qr/^\s+--recursion-method=a/m, 99 "--recursion-method is an array" 100); 101 102like( 103 $output, 104 qr/^\s+--recursion-method\s+processlist,hosts/m, 105 "Default --recursion-method is processlist,hosts" 106); 107 108# ############################################################################ 109# Check opts that disable other opts. 110# ############################################################################ 111$output = `$trunk/bin/pt-table-checksum h=127.1 --help --explain`; 112like( 113 $output, 114 qr/^ --empty-replicate-table\s+FALSE$/m, 115 "--explain disables --empty-replicate-table" 116); 117 118$output = `$trunk/bin/pt-table-checksum h=127.1 --help --resume`; 119like( 120 $output, 121 qr/^ --empty-replicate-table\s+FALSE$/m, 122 "--resume disables --empty-replicate-table" 123); 124 125$output = `$trunk/bin/pt-table-checksum h=127.1 --help --quiet`; 126like( 127 $output, 128 qr/^ --progress\s+\(No value\)$/m, 129 "--quiet disables --progress" 130); 131 132$output = `$trunk/bin/pt-table-checksum --help --chunk-size 500`; 133like( 134 $output, 135 qr/^ --chunk-time\s+0$/m, 136 "--chunk-size sets --chunk-time=0" 137); 138 139# ############################################################################ 140# Only 1 DSN should be allowed on the command line; no extra args. 141# ############################################################################ 142$output = `$trunk/bin/pt-table-checksum h=127.1 h=host1 h=host2`; 143like( 144 $output, 145 qr/More than one host specified; only one allowed/, 146 "Only one DSN allowed on the command line" 147); 148 149# ############################################################################ 150# --replicate table must be db-qualified. 151# ############################################################################ 152$output = `$trunk/bin/pt-table-checksum h=127.1 --replicate checksums`; 153like( 154 $output, 155 qr/--replicate table must be database-qualified/, 156 "--replicate table must be database-qualified" 157); 158 159# ############################################################################ 160# --chunk-size-limit >= 1 or 0 161# ############################################################################ 162$output = `$trunk/bin/pt-table-checksum --chunk-size-limit 0.999`; 163like( 164 $output, 165 qr/chunk-size-limit must be >= 1 or 0 to disable/, 166 "--chunk-size-limit must be >= 1 or 0" 167); 168 169# ############################################################################# 170# --max-load 171# ############################################################################# 172 173$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345 --max-load 100`; 174like( 175 $output, 176 qr/Invalid --max-load/, 177 "Validates --max-load" 178); 179 180# ############################################################################# 181# Done. 182# ############################################################################# 183done_testing; 184