1#!/usr/bin/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;
13use Data::Dumper;
14
15# Hostnames make testing less accurate.  Tests need to see
16# that such-and-such happened on specific slave hosts, but
17# the sandbox servers are all on one host so all slaves have
18# the same hostname.
19$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
20
21use Sandbox;
22use OptionParser;
23use DSNParser;
24use Quoter;
25use PerconaTest;
26use Cxn;
27use VersionParser;
28
29use Percona::XtraDB::Cluster;
30
31my $q   = new Quoter();
32my $dp  = new DSNParser(opts=>$dsn_opts);
33my $sb  = new Sandbox(basedir => '/tmp', DSNParser => $dp);
34my $master_dbh = $sb->get_dbh_for('master');
35
36my $cluster = Percona::XtraDB::Cluster->new();
37my $db_flavor = VersionParser->new($master_dbh)->flavor();
38
39if ( $db_flavor =~ /XtraDB Cluster/ ) {
40   plan skip_all => "Non-PXC tests";
41}
42elsif ( !$master_dbh ) {
43   plan skip_all => 'Cannot connect to sandbox master';
44}
45
46my $o = new OptionParser(
47   description => 'Cxn',
48   file        => "$trunk/bin/pt-table-checksum",
49);
50$o->get_specs("$trunk/bin/pt-table-checksum");
51$o->get_opts();
52
53# In 2.1, these tests did not set innodb_lock_wait_timeout because
54# it was not a --set-vars default but rather its own option handled
55# by/in the tool.  In 2.2, the var is a --set-vars default, which
56# means it will cause a warning on 5.0 and 5.1, so we remoe the var
57# to remove the warning.
58my $set_vars = $o->set_vars();
59delete $set_vars->{innodb_lock_wait_timeout};
60delete $set_vars->{lock_wait_timeout};
61$dp->prop('set-vars', $set_vars);
62
63sub make_cxn {
64   my (%args) = @_;
65   $o->get_opts();
66   return new Cxn(
67      OptionParser => $o,
68      DSNParser    => $dp,
69      %args,
70   );
71}
72
73local @ARGV = ();
74$o->get_opts();
75
76diag("Starting master1");
77$sb->start_sandbox(type => "master", server => "master1");
78
79my ($master_cxn, $slave1_cxn, $master1_cxn)
80   = map {
81         my $cxn = make_cxn( dsn_string => $sb->dsn_for($_) );
82         $cxn->connect();
83         $cxn;
84   } qw( master slave1 master1 );
85
86for my $cxn ( $master_cxn, $slave1_cxn, $master1_cxn ) {
87   ok(
88      !$cluster->is_cluster_node($cxn),
89      "is_cluster_node works correctly for non-nodes " . $cxn->name
90   );
91}
92
93diag($sb->stop_sandbox("master1"));
94
95# #############################################################################
96# Done.
97# #############################################################################
98$master_dbh->disconnect() if $master_dbh;
99ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
100done_testing;
101exit;
102