~drizzle-trunk/drizzle/development

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# 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 TestMySQLServer;

use base qw(Test::Unit::TestCase);
use lib 'lib','lib/DBServer';
use Cwd;
use GenTest;
use DBServer::MySQL::MySQLd;
use GenTest::Executor;
use GenTest::Reporter;
use GenTest::Reporter::Backtrace;

use Data::Dumper;

sub new {
    my $self = shift()->SUPER::new(@_);
    # your state for fixture here
    return $self;
}

sub set_up {
}

my @pids;

sub tear_down {
    if (osWindows) {
        ## Need to ,kill leftover processes if there are some
        foreach my $p (@pids) {
            Win32::Process::KillProcess($p,-1);
        }
        system("rmdir /s /q unit\\tmp");
    } else {
        ## Need to ,kill leftover processes if there are some
        kill 9 => @pids;
        # system("rm -rf unit/tmp");
    }
}

sub test_create_server {
    my $self = shift;

    my $vardir= cwd()."/unit/tmp";

    my $portbase = 20 + ($ENV{TEST_PORTBASE}?int($ENV{TEST_PORTBASE}):22120);

    $self->assert(defined $ENV{RQG_MYSQL_BASE},"RQG_MYSQL_BASE not defined");

    my $server = DBServer::MySQL::MySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
                                              vardir => $vardir,
                                              port => $portbase);
    $self->assert_not_null($server);

    my ($major, $minor, $build) = $server->versionNumbers;

    say("Major: $major, Minor: $minor, Build: $build");
    
    $self->assert(-f $vardir."/data/mysql/db.MYD","No ".$vardir."/data/mysql/db.MYD");
    
    $server->startServer;
    push @pids,$server->serverpid;
    
    my $dsn = $server->dsn("mysql");
    $self->assert_not_null($dsn);
    
    my $executor = GenTest::Executor->newFromDSN($dsn);
    $self->assert_not_null($executor);
    $executor->init();
    
    my $result = $executor->execute("show tables");
    $self->assert_not_null($result);
    $self->assert_equals($result->status, 0);
    
    say(join(',',map{$_->[0]} @{$result->data}));
    
    $self->assert(-f $vardir."/mysql.pid") if not osWindows();
    $self->assert(-f $vardir."/mysql.err");

    $server->stopServer;

    sayFile($server->logfile);

    $server = DBServer::MySQL::MySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
                                           vardir => $vardir,
                                           port => $portbase,
                                           start_dirty => 1);
    
    $self->assert_not_null($server);

    $server->startServer;
    push @pids,$server->serverpid;
    $server->stopServer;

    sayFile($server->logfile);
}

sub test_crash_and_core {
    if (not osWindows()) { ## crash is not yet implemented for windows
        my $self = shift;

        my $vardir= cwd()."/unit/tmp";
        
        my $portbase = 60 + ($ENV{TEST_PORTBASE}?int($ENV{TEST_PORTBASE}):22120);
        
        $self->assert(defined $ENV{RQG_MYSQL_BASE},"RQG_MYSQL_BASE not defined");
        
        my $server = DBServer::MySQL::MySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
                                                  vardir => $vardir,
                                                  port => $portbase);
        $self->assert_not_null($server);
        
        $self->assert(-f $vardir."/data/mysql/db.MYD","No ".$vardir."/data/mysql/db.MYD");
        
        $server->startServer;
        push @pids,$server->serverpid;
        
        my $dsn = $server->dsn("mysql");
        $self->assert_not_null($dsn);
        
        my $executor = GenTest::Executor->newFromDSN($dsn);
        $self->assert_not_null($executor);
        $executor->init();
    
        my $result = $executor->execute("show tables");
        $self->assert_not_null($result);
        $self->assert_equals($result->status, 0);
        
        say(join(',',map{$_->[0]} @{$result->data}));
        
        $self->assert(-f $vardir."/mysql.pid") if not osWindows();
        $self->assert(-f $vardir."/mysql.err");
        
        my $backtrace = GenTest::Reporter::Backtrace->new(dsn => $server->dsn);
        
        sleep(1);
        
        $server->crash;
        
        sleep(1);

        sayFile($server->logfile);

        say("Core: ". $server->corefile);

        $backtrace->report();
    }
        
}

1;