From a23e81c438bee6cf9248a8efad322feaa57c2129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 5 Jul 2017 08:42:52 +0300 Subject: [PATCH] Add test for MXS-1310 Added test that checks how the use of implicit databases is handled in schemarouter. --- maxscale-system-test/CMakeLists.txt | 3 ++ .../maxscale.cnf.template.mxs1310_implicit_db | 48 +++++++++++++++++ maxscale-system-test/mxs1310_implicit_db.cpp | 54 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 maxscale-system-test/cnf/maxscale.cnf.template.mxs1310_implicit_db create mode 100644 maxscale-system-test/mxs1310_implicit_db.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 10c6b0096..06620f9b8 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -299,6 +299,9 @@ add_test_executable(longblob.cpp longblob longblob LABELS readwritesplit readcon # Test with extremely big blob inserting/selecting with > 16 mb data blocks add_test_executable(mxs1110_16mb.cpp mxs1110_16mb longblob_filters LABELS readwritesplit readconnroute HEAVY REPL_BACKEND) +# Schemarouter implicit database detection +add_test_executable(mxs1310_implicit_db.cpp mxs1310_implicit_db mxs1310_implicit_db LABELS schemarouter REPL_BACKEND) + # INSERT extremelly big number of rows add_test_executable(lots_of_rows.cpp lots_of_rows galera LABELS readwritesplit HEAVY GALERA_BACKEND) diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs1310_implicit_db b/maxscale-system-test/cnf/maxscale.cnf.template.mxs1310_implicit_db new file mode 100644 index 000000000..8b1252ed6 --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs1310_implicit_db @@ -0,0 +1,48 @@ +[maxscale] +threads=###threads### +log_info=1 + +[MySQL Monitor] +type=monitor +module=mysqlmon +###repl51### +servers=server1,server2 +user=maxskysql +passwd=skysql + +[Sharding router] +type=service +router=schemarouter +servers=server1,server2 +user=maxskysql +passwd=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 diff --git a/maxscale-system-test/mxs1310_implicit_db.cpp b/maxscale-system-test/mxs1310_implicit_db.cpp new file mode 100644 index 000000000..eafc3b7a2 --- /dev/null +++ b/maxscale-system-test/mxs1310_implicit_db.cpp @@ -0,0 +1,54 @@ +/** + * Test for MXS-1310. + * - Only explicit databases used -> shard containing the explicit database + * - Only implicit databases used -> shard containing current database + * - Mix of explicit and implicit databases -> shard containing current database + */ + +#include "testconnections.h" + +int main(int argc, char *argv[]) +{ + TestConnections test(argc, argv); + + // Get the @@server_id value from both shards + char server_id[2][1024]; + test.repl->connect(); + sprintf(server_id[0], "%d", test.repl->get_server_id(0)); + sprintf(server_id[1], "%d", test.repl->get_server_id(1)); + execute_query(test.repl->nodes[0], + "CREATE DATABASE db1;" + "CREATE TABLE db1.t1(id int);" + "INSERT INTO db1.t1 VALUES (@@server_id)"); + execute_query(test.repl->nodes[1], + "CREATE DATABASE db2;" + "CREATE TABLE db2.t2(id int);" + "INSERT INTO db2.t2 VALUES (@@server_id)"); + test.repl->sync_slaves(); + + test.tprintf("Run test with sharded database as active database"); + test.connect_rwsplit(); + test.try_query(test.conn_rwsplit, "USE db2"); + execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM t2", server_id[1]); + execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM db1.t1", server_id[0]); + execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, a.id FROM t2 as a JOIN db1.t1 as b", + server_id[1]); + test.close_rwsplit(); + + test.tprintf("Run test with a common database as active database"); + test.connect_rwsplit(); + test.try_query(test.conn_rwsplit, "USE db1"); + execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM t1", server_id[0]); + execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM db2.t2", server_id[1]); + execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, a.id FROM t1 as a JOIN db1.t1 as b", + server_id[0]); + test.close_rwsplit(); + + // Cleanup + execute_query(test.repl->nodes[0], "DROP DATABASE db1"); + execute_query(test.repl->nodes[1], "DROP DATABASE db2"); + + test.repl->fix_replication(); + + return test.global_result; +}