Rewrite temporary table test
Use stack allocated test class and use const char pointers for const functions. Simplify the test and improve error messages.
This commit is contained in:
@ -6,7 +6,7 @@ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static char** sql = NULL;
|
||||
static size_t sql_size = 0;
|
||||
|
||||
int execute_select_query_and_check(MYSQL *conn, char *sql, unsigned long long int rows)
|
||||
int execute_select_query_and_check(MYSQL *conn, const char *sql, unsigned long long int rows)
|
||||
{
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
|
@ -11,7 +11,7 @@
|
||||
* @param rows Expected number of rows
|
||||
* @return 0 in case of success
|
||||
*/
|
||||
int execute_select_query_and_check(MYSQL *conn, char *sql, unsigned long long int rows);
|
||||
int execute_select_query_and_check(MYSQL *conn, const char *sql, unsigned long long int rows);
|
||||
|
||||
/**
|
||||
* @brief create_t1 Create t1 table, fileds: (x1 int, fl int)
|
||||
|
@ -1,16 +1,16 @@
|
||||
/**
|
||||
* @file temporal_tables.cpp Check temporal tables commands functionality (relates to bug 430)
|
||||
* Check temporary tables commands functionality (relates to bug 430)
|
||||
*
|
||||
* - create t1 table and put some data into it
|
||||
* - create tempral table t1
|
||||
* - create temporary table t1
|
||||
* - insert different data into t1
|
||||
* - check that SELECT FROM t1 gives data from tempral table
|
||||
* - create other connections using all Maxscale services and check that SELECT via these connections gives data from main t1, not temporal
|
||||
* - dropping tempral t1
|
||||
* - check that SELECT FROM t1 gives data from temporary table
|
||||
* - create other connections using all MaxScale services and check that SELECT
|
||||
* via these connections gives data from main t1, not temporary
|
||||
* - dropping temporary t1
|
||||
* - check that data from main t1 is not affected
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "testconnections.h"
|
||||
#include "sql_t1.h"
|
||||
|
||||
@ -18,82 +18,45 @@ using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TestConnections test(argc, argv);
|
||||
test.connect_maxscale();
|
||||
|
||||
TestConnections * Test = new TestConnections(argc, argv);
|
||||
test.tprintf("Create a table and insert two rows into it");
|
||||
test.set_timeout(30);
|
||||
|
||||
Test->repl->connect();
|
||||
execute_query(test.conn_rwsplit, "USE test");
|
||||
create_t1(test.conn_rwsplit);
|
||||
execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(0, 1)");
|
||||
execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(1, 1)");
|
||||
|
||||
MYSQL * conn;
|
||||
char sql[100];
|
||||
test.tprintf("Create temporary table and insert one row");
|
||||
test.set_timeout(30);
|
||||
|
||||
Test->set_timeout(40);
|
||||
conn = Test->open_rwsplit_connection();
|
||||
execute_query(test.conn_rwsplit, "create temporary table t1 as (SELECT * FROM t1 WHERE fl=3)");
|
||||
execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(0, 1)");
|
||||
|
||||
Test->tprintf("Cleaning up DB\n");
|
||||
execute_query(conn, (char *) "DROP DATABASE IF EXISTS test");
|
||||
execute_query(conn, (char *) "CREATE DATABASE test");
|
||||
execute_query(conn, (char *) "USE test");
|
||||
test.tprintf("Check that the temporary table has one row");
|
||||
test.set_timeout(90);
|
||||
|
||||
Test->tprintf("creating table t1\n");
|
||||
Test->set_timeout(40);
|
||||
create_t1(conn);
|
||||
test.add_result(execute_select_query_and_check(test.conn_rwsplit, "SELECT * FROM t1", 1),
|
||||
"Current connection should show one row");
|
||||
test.add_result(execute_select_query_and_check(test.conn_master, "SELECT * FROM t1", 2),
|
||||
"New connection should show two rows");
|
||||
test.add_result(execute_select_query_and_check(test.conn_slave, "SELECT * FROM t1", 2),
|
||||
"New connection should show two rows");
|
||||
|
||||
Test->tprintf("Inserting two rows into t1\n");
|
||||
Test->set_timeout(40);
|
||||
execute_query(conn, "INSERT INTO t1 (x1, fl) VALUES(0, 1);");
|
||||
execute_query(conn, "INSERT INTO t1 (x1, fl) VALUES(1, 1);");
|
||||
printf("Drop temporary table and check that the real table has two rows");
|
||||
test.set_timeout(90);
|
||||
|
||||
Test->tprintf("Creating temporal table t1\n");
|
||||
execute_query(conn, "create temporary table t1 as (SELECT * FROM t1 WHERE fl=3);");
|
||||
execute_query(test.conn_rwsplit, "DROP TABLE t1");
|
||||
test.add_result(execute_select_query_and_check(test.conn_rwsplit, "SELECT * FROM t1", 2),
|
||||
"check failed");
|
||||
test.add_result(execute_select_query_and_check(test.conn_master, "SELECT * FROM t1", 2),
|
||||
"check failed");
|
||||
test.add_result(execute_select_query_and_check(test.conn_slave, "SELECT * FROM t1", 2),
|
||||
"check failed");
|
||||
|
||||
Test->tprintf("Inserting one row into temporal table\n");
|
||||
execute_query(conn, "INSERT INTO t1 (x1, fl) VALUES(0, 1);");
|
||||
test.close_maxscale_connections();
|
||||
|
||||
Test->tprintf("Checking t1 temporal table\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(conn, (char *) "SELECT * FROM t1;", 1), "check failed\n");
|
||||
|
||||
|
||||
Test->tprintf("Connecting to all MaxScale routers and checking main t1 table (not temporal)\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(Test->connect_maxscale(), "Connectiong to Maxscale failed\n");
|
||||
Test->tprintf("Checking t1 table using RWSplit router\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(Test->conn_rwsplit, (char *) "SELECT * FROM t1;", 2),
|
||||
"check failed\n");
|
||||
Test->tprintf("Checking t1 table using ReadConn router in master mode\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(Test->conn_master, (char *) "SELECT * FROM t1;", 2),
|
||||
"check failed\n");
|
||||
Test->tprintf("Checking t1 table using ReadConn router in slave mode\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(Test->conn_slave, (char *) "SELECT * FROM t1;", 2),
|
||||
"check failed\n");
|
||||
Test->close_maxscale_connections();
|
||||
|
||||
|
||||
printf("Dropping temparal table and check main table again\n");
|
||||
execute_query(conn, "DROP TABLE t1;");
|
||||
|
||||
printf("Connecting to all MaxScale routers and checking main t1 table (not temporal)\n");
|
||||
Test->add_result(Test->connect_maxscale(), "Connectiong to Maxscale failed\n");
|
||||
Test->tprintf("Checking t1 table using RWSplit router\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(Test->conn_rwsplit, (char *) "SELECT * FROM t1;", 2),
|
||||
"check failed\n");
|
||||
Test->tprintf("Checking t1 table using ReadConn router in master mode\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(Test->conn_master, (char *) "SELECT * FROM t1;", 2),
|
||||
"check failed\n");
|
||||
Test->tprintf("Checking t1 table using ReadConn router in slave mode\n");
|
||||
Test->set_timeout(240);
|
||||
Test->add_result(execute_select_query_and_check(Test->conn_slave, (char *) "SELECT * FROM t1;", 2),
|
||||
"check failed\n");
|
||||
Test->close_maxscale_connections();
|
||||
|
||||
mysql_close(conn);
|
||||
|
||||
int rval = Test->global_result;
|
||||
delete Test;
|
||||
return rval;
|
||||
return test.global_result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user