Sunday, October 6, 2013

Try RQG...

Lets now look at how one can try their hands on RQG:

First get your hands on source from RQG, you would need bazzar installed on your machine, then do:
bzr branch lp:randgen

Once you have the source you need to install dependent modules like DBD::Mysql and this others listed here.

As you may know by now the tool is written in Perl and there are a some wrapper scripts in RQG home directory. I will talk about a few useful ones we will see how they work.

server.pl, gendata.pl, gensql.pl, gentest.pl, runall.pl, combinations.pl, util/simplify-grammar.pl, util/simplify-crash.pl

Every one of the scripts has its how to use information using the --help option, but lets see a few of them in action now:

server.pl
Used to start a server instance, needs the location of mysql complied source or binary location.

perl server.pl --basedir=$MYSQL_SOURCE
# 2013-10-26T14:31:59 Using Log::Log4perl
# 2013-10-26T14:31:59 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
# 2013-10-26T14:31:59 Please see http://forge.mysql.com/wiki/Category:RandomQueryGenerator for more information on this test framework.
# 2013-10-26T14:31:59 Starting
# 2013-10-26T14:31:59 # server.pl \
# 2013-10-26T14:31:59 # --basedir=/home/mysql-5.6/
# 2013-10-26T14:31:59 master_port : 19300 slave_port : 19302 ports : 19300 19302 MTR_BUILD_THREAD : 930


gendata.pl
This script is used to generate data used for our queries, i.e. create tables, create indexs, alter table etc..

perl gendata.pl --spec=conf/examples/example.zz --dsn=dbi:mysql:host=127.0.0.1:port=13000:user=root:database=test
# 2013-10-26T13:58:18 Using Log::Log4perl
# 2013-10-26T13:58:18 # Creating MySQL table: test.table0_int_autoinc; engine: ; rows: 0 .
# 2013-10-26T13:58:26 # Creating MySQL table: test.table0_key_pk_parts_2_int_autoinc; engine: ; rows: 0 .

where,
           dsn is the MySQL server connection details.

gensql.pl
This script now shows the magic of generating queries, the input is a DML based grammar, and we see and example below for 3 queries

perl gensql.pl --grammar=conf/examples/example.yy --dsn=dbi:mysql:host=127.0.0.1:port=13000:user=root:database=test --queries=3
# 2013-10-26T14:00:49 Using Log::Log4perl
# 2013-10-26T14:00:49 Caching schema metadata for dbi:mysql:host=127.0.0.1:port=13000:user=root:database=test
INSERT INTO `table100_key_pk_parts_2_int_autoinc` ( `col_set_utf8_key_default_null` ) VALUES ( 3 );
INSERT INTO `table1_key_pk_parts_2_int_autoinc` ( `col_set_latin1` ) VALUES ( 3 );
DELETE FROM `table0_key_pk_parts_2_int_autoinc` WHERE `col_enum_latin1_key_default_null` < 7 LIMIT 9;

gentest.pl
This script which combines some of the functionality gensql scripts, additional it allows various options to be provided to work with the queries generated, note this scripts required tables to be already created tables in the dsn.

perl gentest.pl --grammar=conf/examples/example.yy --dsn=dbi:mysql:host=127.0.0.1:port=19300:user=root:database=test --queries=3 

runall.pl
This is a wrapper script which starts a server, creates table and executes the queries specified by the respective grammar file.

perl runall.pl --basedir=$MYSQL_SOURCE --gendata=conf/examples/example.zz --grammar=conf/examples/example.yy --queries=1 --threads=1
...
# 2013-10-26T14:57:19 # Creating MySQL table: test.table0_int_autoinc; engine: ; rows: 0 .
# 2013-10-26T14:57:27 # Creating MySQL table: test.table0_key_pk_parts_2_int_autoinc; engine: ; rows: 0 .
# 2013-10-26T14:57:45 # Creating MySQL table: test.table1_int_autoinc; engine: ; rows: 1 .
....
# 2013-10-26T14:59:28 Kill GenTest::ErrorFilter(2900)
# 2013-10-26T14:59:28 Test completed successfully.
# 2013-10-26T14:59:28 gentest.pl exited with exit status STATUS_OK (0)
2013-10-26T14:59:28 [2826] runall.pl will exit with exit status STATUS_OK (0)



No comments: