MXS-1113 Add basic test

Add test case for text and binary protocol prepared statements in
schemarouter.
This commit is contained in:
Marko 2018-07-24 10:21:00 +03:00
parent 11d57a264c
commit 3817960658
3 changed files with 150 additions and 0 deletions

View File

@ -1044,6 +1044,11 @@ add_test_executable(mxs1961_standalone_rejoin.cpp mxs1961_standalone_rejoin mxs1
# https://jira.mariadb.org/browse/MXS-1985
add_test_executable(mxs1985_kill_hang.cpp mxs1985_kill_hang replication LABELS REPL_BACKEND)
# MXS-1113: Support of prepared statement for schemarouter
# https://jira.mariadb.org/browse/MXS-1113
add_test_executable(mxs1113_schemarouter_ps.cpp mxs1113_schemarouter_ps mxs1113_schemarouter_ps LABELS schemarouter BREAKS_REPL)
configure_file(templates.h.in templates.h @ONLY)
include(CTest)

View File

@ -0,0 +1,59 @@
[maxscale]
threads=###threads###
log_warning=1
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3,server4
user=maxskysql
password=skysql
[Sharding router]
type=service
router=schemarouter
servers=server1,server2,server3,server4
user=maxskysql
password=skysql
auth_all_servers=1
ignore_databases_regex=.*
[Sharding Listener]
type=listener
service=Sharding router
protocol=MySQLClient
port=4006
[CLI]
type=service
router=cli
[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
socket=default
[server1]
type=server
address=###node_server_IP_1###
port=###node_server_port_1###
protocol=MySQLBackend
[server2]
type=server
address=###node_server_IP_2###
port=###node_server_port_2###
protocol=MySQLBackend
[server3]
type=server
address=###node_server_IP_3###
port=###node_server_port_3###
protocol=MySQLBackend
[server4]
type=server
address=###node_server_IP_4###
port=###node_server_port_4###
protocol=MySQLBackend

View File

@ -0,0 +1,86 @@
/**
* MXS-1113: Prepared statement test for schemarouter
*
* https://jira.mariadb.org/browse/MXS-1113
*/
#include "testconnections.h"
void test_text_protocol(TestConnections& test, MYSQL* conn)
{
for (int i = 0; i < test.repl->N; i++)
{
test.try_query(conn, "PREPARE stmt%d FROM 'SELECT * FROM shard_db.table%d WHERE fl=3;';", i, i);
test.try_query(conn, "SET @x = 3;");
test.try_query(conn, "EXECUTE stmt%d", i);
}
for (int i = 0; i < test.repl->N; i++)
{
test.try_query(conn, "DEALLOCATE PREPARE stmt%d", i);
}
}
void test_binary_protocol(TestConnections& test, MYSQL* conn)
{
const char* query = "SELECT x1, fl FROM shard_db.table2";
MYSQL_BIND bind[2] = {};
uint32_t id;
uint32_t id2;
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = &id;
bind[1].buffer_type = MYSQL_TYPE_LONG;
bind[1].buffer = &id2;
MYSQL_STMT* stmt = mysql_stmt_init(conn);
test.add_result(mysql_stmt_prepare(stmt, query, strlen(query)), "Failed to prepare");
test.add_result(mysql_stmt_execute(stmt), "Failed to execute");
test.add_result(mysql_stmt_bind_result(stmt, bind), "Failed to bind result");
test.add_result(mysql_stmt_fetch(stmt), "Failed to fetch result");
mysql_stmt_close(stmt);
}
int main(int argc, char *argv[])
{
TestConnections test(argc, argv);
test.set_timeout(30);
test.repl->execute_query_all_nodes("STOP SLAVE");
test.repl->execute_query_all_nodes("DROP DATABASE IF EXISTS shard_db");
test.repl->execute_query_all_nodes("CREATE DATABASE shard_db");
MYSQL* conn;
for (int i = 0; i < test.repl->N; i++)
{
conn = open_conn_db(test.repl->port[i], test.repl->IP[i], "shard_db",
test.repl->user_name, test.repl->password, test.ssl);
execute_query(conn, "CREATE TABLE table%d (x1 int, fl int)", i);
execute_query(conn, "INSERT INTO table%d VALUES(%d, %d)", i, i, i);
mysql_close(conn);
}
test.maxscales->connect_maxscale(0);
conn = test.maxscales->conn_rwsplit[0];
test.tprintf("Running text protocol test");
test_text_protocol(test, conn);
test.maxscales->disconnect();
test.maxscales->connect_maxscale(0);
conn = test.maxscales->conn_rwsplit[0];
test.tprintf("Running binary protocol test");
test_binary_protocol(test, conn);
test.stop_timeout();
test.maxscales->close_maxscale_connections(0);
test.repl->execute_query_all_nodes("DROP DATABASE IF EXISTS shard_db");
test.repl->execute_query_all_nodes("START SLAVE");
sleep(1);
test.repl->fix_replication();
return test.global_result;
}