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:
Markus Mäkelä
2017-06-06 22:45:19 +03:00
parent de23297944
commit 943662d2b5
3 changed files with 40 additions and 77 deletions

View File

@ -6,7 +6,7 @@ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static char** sql = NULL; static char** sql = NULL;
static size_t sql_size = 0; 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_RES *res;
MYSQL_ROW row; MYSQL_ROW row;

View File

@ -11,7 +11,7 @@
* @param rows Expected number of rows * @param rows Expected number of rows
* @return 0 in case of success * @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) * @brief create_t1 Create t1 table, fileds: (x1 int, fl int)

View File

@ -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 t1 table and put some data into it
* - create tempral table t1 * - create temporary table t1
* - insert different data into t1 * - insert different data into t1
* - check that SELECT FROM t1 gives data from tempral table * - 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 temporal * - create other connections using all MaxScale services and check that SELECT
* - dropping tempral t1 * via these connections gives data from main t1, not temporary
* - dropping temporary t1
* - check that data from main t1 is not affected * - check that data from main t1 is not affected
*/ */
#include <iostream>
#include "testconnections.h" #include "testconnections.h"
#include "sql_t1.h" #include "sql_t1.h"
@ -18,82 +18,45 @@ using namespace std;
int main(int argc, char *argv[]) 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; test.tprintf("Create temporary table and insert one row");
char sql[100]; test.set_timeout(30);
Test->set_timeout(40); execute_query(test.conn_rwsplit, "create temporary table t1 as (SELECT * FROM t1 WHERE fl=3)");
conn = Test->open_rwsplit_connection(); execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(0, 1)");
Test->tprintf("Cleaning up DB\n"); test.tprintf("Check that the temporary table has one row");
execute_query(conn, (char *) "DROP DATABASE IF EXISTS test"); test.set_timeout(90);
execute_query(conn, (char *) "CREATE DATABASE test");
execute_query(conn, (char *) "USE test");
Test->tprintf("creating table t1\n"); test.add_result(execute_select_query_and_check(test.conn_rwsplit, "SELECT * FROM t1", 1),
Test->set_timeout(40); "Current connection should show one row");
create_t1(conn); 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"); printf("Drop temporary table and check that the real table has two rows");
Test->set_timeout(40); test.set_timeout(90);
execute_query(conn, "INSERT INTO t1 (x1, fl) VALUES(0, 1);");
execute_query(conn, "INSERT INTO t1 (x1, fl) VALUES(1, 1);");
Test->tprintf("Creating temporal table t1\n"); execute_query(test.conn_rwsplit, "DROP TABLE t1");
execute_query(conn, "create temporary table t1 as (SELECT * FROM t1 WHERE fl=3);"); 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"); test.close_maxscale_connections();
execute_query(conn, "INSERT INTO t1 (x1, fl) VALUES(0, 1);");
Test->tprintf("Checking t1 temporal table\n"); return test.global_result;
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;
} }