~vadim-tk/percona-server/percona-5.5.15-galera

« back to all changes in this revision

Viewing changes to tests/rename_test.pl

  • Committer: root
  • Date: 2011-09-10 16:37:18 UTC
  • Revision ID: root@r815.office.percona.com-20110910163718-ydh4zj8hcdgoyavb
Porting Galera to 5.5.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
# Copyright (C) 2000, 2001 MySQL AB
 
4
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; version 2 of the License.
 
8
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
#
 
19
# This is a test with uses processes to insert, select and drop tables.
 
20
#
 
21
 
 
22
$opt_loop_count=100000; # Change this to make test harder/easier
 
23
 
 
24
##################### Standard benchmark inits ##############################
 
25
 
 
26
use DBI;
 
27
use Getopt::Long;
 
28
use Benchmark;
 
29
 
 
30
package main;
 
31
 
 
32
$opt_skip_create=$opt_skip_delete=$opt_skip_flush=0;
 
33
$opt_host=""; $opt_db="test";
 
34
 
 
35
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-delete",
 
36
"skip-flush") || die "Aborted";
 
37
 
 
38
print "Testing 5 multiple connections to a server with 1 insert, 1 rename\n";
 
39
print "1 select and 1 flush thread\n";
 
40
 
 
41
$firsttable  = "bench_f1";
 
42
 
 
43
####
 
44
####  Start timing and start test
 
45
####
 
46
 
 
47
$start_time=new Benchmark;
 
48
if (!$opt_skip_create)
 
49
{
 
50
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
51
                      $opt_user, $opt_password,
 
52
                    { PrintError => 0}) || die $DBI::errstr;
 
53
  $dbh->do("drop table if exists $firsttable, ${firsttable}_1, ${firsttable}_2");
 
54
 
 
55
  print "Creating table $firsttable in database $opt_db\n";
 
56
  $dbh->do("create table $firsttable (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
 
57
  $dbh->disconnect; $dbh=0;     # Close handler
 
58
}
 
59
$|= 1;                          # Autoflush
 
60
 
 
61
####
 
62
#### Start the tests
 
63
####
 
64
 
 
65
test_insert() if (($pid=fork()) == 0); $work{$pid}="insert";
 
66
test_rename(1) if (($pid=fork()) == 0); $work{$pid}="rename 1";
 
67
test_rename(2) if (($pid=fork()) == 0); $work{$pid}="rename 2";
 
68
test_select() if (($pid=fork()) == 0); $work{$pid}="select";
 
69
if (!$opt_skip_flush)
 
70
{
 
71
  test_flush() if (($pid=fork()) == 0); $work{$pid}="flush";
 
72
}
 
73
$errors=0;
 
74
while (($pid=wait()) != -1)
 
75
{
 
76
  $ret=$?/256;
 
77
  print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
 
78
  $errors++ if ($ret != 0);
 
79
}
 
80
 
 
81
if (!$opt_skip_delete && !$errors)
 
82
{
 
83
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
84
                      $opt_user, $opt_password,
 
85
                    { PrintError => 0}) || die $DBI::errstr;
 
86
  $dbh->do("drop table $firsttable");
 
87
  $dbh->disconnect; $dbh=0;     # Close handler
 
88
}
 
89
print ($errors ? "Test failed\n" :"Test ok\n");
 
90
 
 
91
$end_time=new Benchmark;
 
92
print "Total time: " .
 
93
  timestr(timediff($end_time, $start_time),"noc") . "\n";
 
94
 
 
95
exit(0);
 
96
 
 
97
#
 
98
# Insert records in the table.  Delete table when test is finished
 
99
#
 
100
 
 
101
sub test_insert
 
102
{
 
103
  my ($dbh,$i,$error);
 
104
 
 
105
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
106
                      $opt_user, $opt_password,
 
107
                    { PrintError => 0}) || die $DBI::errstr;
 
108
  for ($i=0 ; $i < $opt_loop_count; $i++)
 
109
  {
 
110
    if (!$dbh->do("insert into $firsttable values ($i,'This is entry $i','')"))
 
111
    {
 
112
      $error=$dbh->errstr;
 
113
      $dbh->do("drop table ${firsttable}"); # End other threads
 
114
      die "Warning; Got error on insert: " . $error . "\n";
 
115
    }
 
116
  }
 
117
  sleep(1);
 
118
  $dbh->do("drop table ${firsttable}") || die "Got error on drop table: " . $dbh->errstr . "\n";
 
119
  $dbh->disconnect; $dbh=0;
 
120
  print "Test_insert: Inserted $i rows\n";
 
121
  exit(0);
 
122
}
 
123
 
 
124
 
 
125
sub test_rename
 
126
{
 
127
  my ($id) = @_;
 
128
  my ($dbh,$i,$error_counter,$sleep_time);
 
129
 
 
130
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
131
                      $opt_user, $opt_password,
 
132
                    { PrintError => 0}) || die $DBI::errstr;
 
133
  $error_counter=0;
 
134
  $sleep_time=2;
 
135
  for ($i=0 ; $i < $opt_loop_count ; $i++)
 
136
  {
 
137
    sleep($sleep_time);
 
138
    $dbh->do("create table ${firsttable}_$id (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
 
139
    if (!$dbh->do("rename table $firsttable to ${firsttable}_${id}_1, ${firsttable}_$id to ${firsttable}"))
 
140
    {
 
141
      last if ($dbh->errstr =~ /^Can\'t find/);
 
142
      die "Got error on rename: " . $dbh->errstr . "\n";
 
143
    }
 
144
    $dbh->do("drop table ${firsttable}_${id}_1") || die "Got error on drop table: " . $dbh->errstr . "\n";
 
145
  }
 
146
  $dbh->disconnect; $dbh=0;
 
147
  print "Test_drop: Did a drop $i times\n";
 
148
  exit(0);
 
149
}
 
150
 
 
151
 
 
152
#
 
153
# select records
 
154
#
 
155
 
 
156
sub test_select
 
157
{
 
158
  my ($dbh,$i,$sth,@row,$sleep_time);
 
159
 
 
160
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
161
                      $opt_user, $opt_password,
 
162
                    { PrintError => 0}) || die $DBI::errstr;
 
163
 
 
164
  $sleep_time=3;
 
165
  for ($i=0 ; $i < $opt_loop_count ; $i++)
 
166
  {
 
167
    sleep($sleep_time);
 
168
    $sth=$dbh->prepare("select sum(t.id) from $firsttable as t,$firsttable as t2") || die "Got error on select: $dbh->errstr;\n";
 
169
    if ($sth->execute)
 
170
    {
 
171
      @row = $sth->fetchrow_array();
 
172
      $sth->finish;
 
173
    }
 
174
    else
 
175
    {
 
176
      $sth->finish;
 
177
      last if (! ($dbh->errstr =~ /doesn\'t exist/));
 
178
      die "Got error on select: " . $dbh->errstr . "\n";
 
179
    }
 
180
  }
 
181
  $dbh->disconnect; $dbh=0;
 
182
  print "Test_select: ok\n";
 
183
  exit(0);
 
184
}
 
185
 
 
186
#
 
187
# flush records
 
188
#
 
189
 
 
190
sub test_flush
 
191
{
 
192
  my ($dbh,$i,$sth,@row,$error_counter,$sleep_time);
 
193
 
 
194
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
195
                      $opt_user, $opt_password,
 
196
                    { PrintError => 0}) || die $DBI::errstr;
 
197
 
 
198
  $error_counter=0;
 
199
  $sleep_time=5;
 
200
  for ($i=0 ; $i < $opt_loop_count ; $i++)
 
201
  {
 
202
    sleep($sleep_time);
 
203
    $sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on prepar: $dbh->errstr;\n";
 
204
    if ($sth->execute)
 
205
    {
 
206
      @row = $sth->fetchrow_array();
 
207
      $sth->finish;
 
208
      $sleep_time=5;
 
209
      $dbh->do("flush tables $firsttable") || die "Got error on flush table: " . $dbh->errstr . "\n";
 
210
    }
 
211
    else
 
212
    {
 
213
      last if (! ($dbh->errstr =~ /doesn\'t exist/));
 
214
      die "Got error on flush: " . $dbh->errstr . "\n";
 
215
    }
 
216
  }
 
217
  $dbh->disconnect; $dbh=0;
 
218
  print "Test_select: ok\n";
 
219
  exit(0);
 
220
}