1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# Copyright (C) 2010 Sun Microsystems, Inc. All rights reserved. Use
# is subject to license terms.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
package TestReplServer;
use base qw(Test::Unit::TestCase);
use lib 'lib';
use Cwd;
use GenTest;
use GenTest::Server::ReplMySQLd;
use GenTest::Executor;
use Data::Dumper;
sub new {
my $self = shift()->SUPER::new(@_);
# your state for fixture here
return $self;
}
sub set_up {
}
@pids;
sub tear_down {
if (windows) {
## Need to ,kill leftover processes if there are some
foreach my $p (@pids) {
Win32::Process::KillProcess($p,-1);
}
system("rmdir /s /q unit\\tmp1");
system("rmdir /s /q unit\\tmp2");
} else {
## Need to ,kill leftover processes if there are some
kill 9 => @pids;
system("rm -rf unit/tmp1");
system("rm -rf unit/tmp2");
}
}
sub test_create_server {
my $self = shift;
my $portbase = 30 + ($ENV{TEST_PORTBASE}?int($ENV{TEST_PORTBASE}):22120);
my $master_vardir= cwd()."/unit/tmp1";
my $slave_vardir= cwd()."/unit/tmp2";
$self->assert(defined $ENV{RQG_MYSQL_BASE},"RQG_MYSQL_BASE not defined");
my $server = GenTest::Server::ReplMySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
master_vardir => $master_vardir,
slave_vardir => $slave_vardir,
mode => 'statement',
master_port => $portbase);
$self->assert_not_null($server);
$self->assert(-f $master_vardir."/data/mysql/db.MYD","No ".$master_vardir."/data/mysql/db.MYD");
$self->assert(-f $slave_vardir."/data/mysql/db.MYD","No ".$slave_vardir."/data/mysql/db.MYD");
$server->startServer;
push @pids,$server->master->serverpid;
push @pids,$server->slave->serverpid;
$server->master->dbh->do("CREATE TABLE test.t (i integer)");
$server->master->dbh->do("INSERT INTO test.t VALUES(42)");
$server->waitForSlaveSync();
my $result = $server->slave->dbh->selectrow_array("SELECT * FROM test.t");
$self->assert_num_equals(42, $result);
$server->stopServer;
sayFile($server->master->logfile);
sayFile($server->slave->logfile);
}
1;
|