/mk-table-checksum/t/105_chunk_size.t

http://maatkit.googlecode.com/ · Perl · 52 lines · 36 code · 10 blank · 6 comment · 4 complexity · c80df74ea210d3305fd1582130b6d117 MD5 · raw file

  1. #!/usr/bin/env perl
  2. BEGIN {
  3. die "The MAATKIT_WORKING_COPY environment variable is not set. See http://code.google.com/p/maatkit/wiki/Testing"
  4. unless $ENV{MAATKIT_WORKING_COPY} && -d $ENV{MAATKIT_WORKING_COPY};
  5. unshift @INC, "$ENV{MAATKIT_WORKING_COPY}/common";
  6. };
  7. use strict;
  8. use warnings FATAL => 'all';
  9. use English qw(-no_match_vars);
  10. use Test::More;
  11. use MaatkitTest;
  12. use Sandbox;
  13. require "$trunk/mk-table-checksum/mk-table-checksum";
  14. my $dp = new DSNParser(opts=>$dsn_opts);
  15. my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
  16. my $master_dbh = $sb->get_dbh_for('master');
  17. if ( !$master_dbh ) {
  18. plan skip_all => 'Cannot connect to sandbox master';
  19. }
  20. else {
  21. plan tests => 3;
  22. }
  23. my $output;
  24. my $cnf='/tmp/12345/my.sandbox.cnf';
  25. my $cmd = "$trunk/mk-table-checksum/mk-table-checksum -F $cnf 127.0.0.1";
  26. $sb->create_dbs($master_dbh, [qw(test)]);
  27. $sb->load_file('master', 'mk-table-checksum/t/samples/before.sql');
  28. # Ensure chunking works
  29. $output = `$cmd --function sha1 --explain --chunk-size 200 -d test -t chunk --chunk-size-limit 0`;
  30. like($output, qr/test\s+chunk\s+`film_id` > 0 AND `film_id` < '\d+'/, 'chunking works');
  31. my $num_chunks = scalar(map { 1 } $output =~ m/^test/gm);
  32. ok($num_chunks >= 5 && $num_chunks < 8, "Found $num_chunks chunks");
  33. # Ensure chunk boundaries are put into test.checksum (bug #1850243)
  34. $output = `$cmd --function sha1 -d test -t chunk --chunk-size 50 --replicate test.checksum 127.0.0.1`;
  35. $output = `/tmp/12345/use --skip-column-names -e "select boundaries from test.checksum where db='test' and tbl='chunk' and chunk=0"`;
  36. chomp $output;
  37. like ( $output, qr/`film_id` = 0/, 'chunk boundaries stored right');
  38. # #############################################################################
  39. # Done.
  40. # #############################################################################
  41. $sb->wipe_clean($master_dbh);
  42. exit;