From 3817960658c2764214d520c1a8e4632518ab0c81 Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 24 Jul 2018 10:21:00 +0300 Subject: [PATCH] MXS-1113 Add basic test Add test case for text and binary protocol prepared statements in schemarouter. --- maxscale-system-test/CMakeLists.txt | 5 ++ ...scale.cnf.template.mxs1113_schemarouter_ps | 59 +++++++++++++ .../mxs1113_schemarouter_ps.cpp | 86 +++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100755 maxscale-system-test/cnf/maxscale.cnf.template.mxs1113_schemarouter_ps create mode 100644 maxscale-system-test/mxs1113_schemarouter_ps.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index eb128dcd6..a8a5e03b3 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -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) diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs1113_schemarouter_ps b/maxscale-system-test/cnf/maxscale.cnf.template.mxs1113_schemarouter_ps new file mode 100755 index 000000000..1543da66b --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs1113_schemarouter_ps @@ -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 diff --git a/maxscale-system-test/mxs1113_schemarouter_ps.cpp b/maxscale-system-test/mxs1113_schemarouter_ps.cpp new file mode 100644 index 000000000..9c5709368 --- /dev/null +++ b/maxscale-system-test/mxs1113_schemarouter_ps.cpp @@ -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; +}