~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#!/usr/bin/perl
2
3
# This is a test with stores big records in a blob.
4
# Note that for the default test the mysql server should have been
5
# started with at least 'mysqld -O max_allowed_packet=30M' and you should have
6
# at least 256M memory in your computer.
7
8
use DBI;
9
use Getopt::Long;
10
11
$opt_host="";
12
$opt_user=$opt_password="";
13
$opt_db="test";
14
$opt_rows=20;			# Test of blobs up to ($rows-1)*100000+1 bytes
15
$opt_compress=0;
16
$opt_table="test_big_record";
17
$opt_loop_count=100000; # Change this to make test harder/easier
18
19
GetOptions("host=s","db=s","user=s", "password=s", "table=s", "rows=i",
20
	   "compress", "loop-count=i") || die "Aborted";
21
22
print "Connection to database $test_db\n";
23
24
$extra_options="";
25
$extra_options.=":mysql_compression=1" if ($opt_compress);
26
27
$dbh = DBI->connect("DBI:mysql:$opt_db:$host$extra_options",$opt_user,$opt_password) || die "Can't connect: $DBI::errstr\n";
28
29
$dbh->do("drop table if exists $opt_table");
30
31
print "Creating table $opt_table\n";
32
33
($dbh->do("\
34
CREATE TABLE $opt_table (
35
  auto int(5) unsigned NOT NULL DEFAULT '0' auto_increment,
36
  test longblob,
37
  PRIMARY KEY (auto))"))  or die $DBI::errstr;
38
39
print "Inserting $opt_rows records\n";
40
41
$|=1;	# Flush output to stdout to be able to monitor process
42
43
for ($i=0 ; $i < $opt_rows ; $i++)
44
{
45
  $tmp= chr(65+($i % 16)) x ($i*100000+1);
46
  $tmp= $dbh->quote($tmp);
47
  $dbh->do("insert into $opt_table (test) values ($tmp)") or die $DBI::errstr;
48
  print ".";
49
}
50
51
print "\nReading records\n";
52
53
$sth=$dbh->prepare("select * from $opt_table", { "mysql_use_result" => 1}) or die $dbh->errstr;
54
55
$sth->execute() or die $sth->errstr;
56
57
$i=0;
58
while (($row = $sth->fetchrow_arrayref))
59
{
60
  die "Record $i had wrong data in blob" if ($row->[1] ne (chr(65+($i % 16)) x ($i*100000+1)));
61
  $i++;
62
}
63
64
die "Didn't get all rows from server" if ($i != $opt_rows);
65
66
#
67
# Test by insert/updating/deleting random rows for a while
68
#
69
70
print "Testing insert/update/delete\n";
71
72
$max_row_id= $rows;
73
for ($i= 0 ; $i < $opt_loop_count ; $i++)
74
{
75
  $length= int(rand 65535);
76
  $tmp= chr(65+($i % 16)) x $length;
77
  $tmp= $dbh->quote($tmp);
78
  $dbh->do("insert into $opt_table (test) values ($tmp)") or die $DBI::errstr;
79
  $max_row_id++;
80
  $length=int(rand 65535);
81
  $tmp= chr(65+($i % 16)) x $length;
82
  $tmp= $dbh->quote($tmp);
83
  $id= int(rand $max_row_id);
84
  $dbh->do("update $opt_table set test= $tmp where auto= $id") or die $DBI::errstr;
85
  if (($i % 2) == 1)
86
  {
87
    $id= int(rand $max_row_id);
88
    $dbh->do("delete from $opt_table where auto= $id") or die $DBI::errstr;
89
  }
90
  print "." if ($i % ($opt_loop_count/100) == 1);
91
}
92
93
# $dbh->do("drop table $opt_table") or die $DBI::errstr;
94
95
print "\nTest ok\n";
96
exit 0;