~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/randgen/unit/TestMySQLServer.pm

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Sun Microsystems, Inc. All rights reserved.  Use
 
2
# is subject to license terms.
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
#
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
11
# General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
16
# USA
 
17
 
 
18
package TestMySQLServer;
 
19
 
 
20
use base qw(Test::Unit::TestCase);
 
21
use lib 'lib','lib/DBServer';
 
22
use Cwd;
 
23
use GenTest;
 
24
use DBServer::MySQL::MySQLd;
 
25
use GenTest::Executor;
 
26
use GenTest::Reporter;
 
27
use GenTest::Reporter::Backtrace;
 
28
 
 
29
use Data::Dumper;
 
30
 
 
31
sub new {
 
32
    my $self = shift()->SUPER::new(@_);
 
33
    # your state for fixture here
 
34
    return $self;
 
35
}
 
36
 
 
37
sub set_up {
 
38
}
 
39
 
 
40
my @pids;
 
41
 
 
42
sub tear_down {
 
43
    if (osWindows) {
 
44
        ## Need to ,kill leftover processes if there are some
 
45
        foreach my $p (@pids) {
 
46
            Win32::Process::KillProcess($p,-1);
 
47
        }
 
48
        system("rmdir /s /q unit\\tmp");
 
49
    } else {
 
50
        ## Need to ,kill leftover processes if there are some
 
51
        kill 9 => @pids;
 
52
        # system("rm -rf unit/tmp");
 
53
    }
 
54
}
 
55
 
 
56
sub test_create_server {
 
57
    my $self = shift;
 
58
 
 
59
    my $vardir= cwd()."/unit/tmp";
 
60
 
 
61
    my $portbase = 20 + ($ENV{TEST_PORTBASE}?int($ENV{TEST_PORTBASE}):22120);
 
62
 
 
63
    $self->assert(defined $ENV{RQG_MYSQL_BASE},"RQG_MYSQL_BASE not defined");
 
64
 
 
65
    my $server = DBServer::MySQL::MySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
 
66
                                              vardir => $vardir,
 
67
                                              port => $portbase);
 
68
    $self->assert_not_null($server);
 
69
 
 
70
    my ($major, $minor, $build) = $server->versionNumbers;
 
71
 
 
72
    say("Major: $major, Minor: $minor, Build: $build");
 
73
    
 
74
    $self->assert(-f $vardir."/data/mysql/db.MYD","No ".$vardir."/data/mysql/db.MYD");
 
75
    
 
76
    $server->startServer;
 
77
    push @pids,$server->serverpid;
 
78
    
 
79
    my $dsn = $server->dsn("mysql");
 
80
    $self->assert_not_null($dsn);
 
81
    
 
82
    my $executor = GenTest::Executor->newFromDSN($dsn);
 
83
    $self->assert_not_null($executor);
 
84
    $executor->init();
 
85
    
 
86
    my $result = $executor->execute("show tables");
 
87
    $self->assert_not_null($result);
 
88
    $self->assert_equals($result->status, 0);
 
89
    
 
90
    say(join(',',map{$_->[0]} @{$result->data}));
 
91
    
 
92
    $self->assert(-f $vardir."/mysql.pid") if not osWindows();
 
93
    $self->assert(-f $vardir."/mysql.err");
 
94
 
 
95
    $server->stopServer;
 
96
 
 
97
    sayFile($server->logfile);
 
98
 
 
99
    $server = DBServer::MySQL::MySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
 
100
                                           vardir => $vardir,
 
101
                                           port => $portbase,
 
102
                                           start_dirty => 1);
 
103
    
 
104
    $self->assert_not_null($server);
 
105
 
 
106
    $server->startServer;
 
107
    push @pids,$server->serverpid;
 
108
    $server->stopServer;
 
109
 
 
110
    sayFile($server->logfile);
 
111
}
 
112
 
 
113
sub test_crash_and_core {
 
114
    if (not osWindows()) { ## crash is not yet implemented for windows
 
115
        my $self = shift;
 
116
 
 
117
        my $vardir= cwd()."/unit/tmp";
 
118
        
 
119
        my $portbase = 60 + ($ENV{TEST_PORTBASE}?int($ENV{TEST_PORTBASE}):22120);
 
120
        
 
121
        $self->assert(defined $ENV{RQG_MYSQL_BASE},"RQG_MYSQL_BASE not defined");
 
122
        
 
123
        my $server = DBServer::MySQL::MySQLd->new(basedir => $ENV{RQG_MYSQL_BASE},
 
124
                                                  vardir => $vardir,
 
125
                                                  port => $portbase);
 
126
        $self->assert_not_null($server);
 
127
        
 
128
        $self->assert(-f $vardir."/data/mysql/db.MYD","No ".$vardir."/data/mysql/db.MYD");
 
129
        
 
130
        $server->startServer;
 
131
        push @pids,$server->serverpid;
 
132
        
 
133
        my $dsn = $server->dsn("mysql");
 
134
        $self->assert_not_null($dsn);
 
135
        
 
136
        my $executor = GenTest::Executor->newFromDSN($dsn);
 
137
        $self->assert_not_null($executor);
 
138
        $executor->init();
 
139
    
 
140
        my $result = $executor->execute("show tables");
 
141
        $self->assert_not_null($result);
 
142
        $self->assert_equals($result->status, 0);
 
143
        
 
144
        say(join(',',map{$_->[0]} @{$result->data}));
 
145
        
 
146
        $self->assert(-f $vardir."/mysql.pid") if not osWindows();
 
147
        $self->assert(-f $vardir."/mysql.err");
 
148
        
 
149
        my $backtrace = GenTest::Reporter::Backtrace->new(dsn => $server->dsn);
 
150
        
 
151
        sleep(1);
 
152
        
 
153
        $server->crash;
 
154
        
 
155
        sleep(1);
 
156
 
 
157
        sayFile($server->logfile);
 
158
 
 
159
        say("Core: ". $server->corefile);
 
160
 
 
161
        $backtrace->report();
 
162
    }
 
163
        
 
164
}
 
165
 
 
166
1;