diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 3159750f7..efdf75c92 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -344,6 +344,9 @@ add_test_executable(mxs280_select_outfile.cpp mxs280_select_outfile replication # Tries prepared stmt 'SELECT 1,1,1,1...." with different nu,ber of '1' add_test_executable(mxs314.cpp mxs314 galera LABELS MySQLProtocol LIGHT GALERA_BACKEND) +# Binary protocol prepared statement test +add_test_executable(binary_ps.cpp binary_ps replication LABELS readwritesplit LIGHT REPL_BACKEND) + # Creates and closes a lot of connections, checks that 'maxadmin list servers' shows 0 connections at the end add_test_executable(mxs321.cpp mxs321 replication LABELS maxscale REPL_BACKEND) diff --git a/maxscale-system-test/binary_ps.cpp b/maxscale-system-test/binary_ps.cpp new file mode 100644 index 000000000..f582adb9f --- /dev/null +++ b/maxscale-system-test/binary_ps.cpp @@ -0,0 +1,67 @@ +/** + * Test binary protocol prepared statement routing + */ +#include "testconnections.h" + +int main(int argc, char** argv) +{ + + TestConnections test(argc, argv); + char server_id[test.galera->N][1024]; + + test.repl->connect(); + + /** Get server_id for each node */ + for (int i = 0; i < test.repl->N; i++) + { + sprintf(server_id[i], "%d", test.repl->get_server_id(i)); + } + + test.connect_maxscale(); + + test.set_timeout(20); + + MYSQL_STMT* stmt = mysql_stmt_init(test.conn_rwsplit); + const char* write_query = "SELECT @@server_id, @@last_insert_id"; + const char* read_query = "SELECT @@server_id"; + char buffer[100] = ""; + char buffer2[100] = ""; + my_bool err = false; + my_bool isnull = false; + MYSQL_BIND bind[2] = {}; + + bind[0].buffer_length = sizeof(buffer); + bind[0].buffer = buffer; + bind[0].error = &err; + bind[0].is_null = &isnull; + bind[1].buffer_length = sizeof(buffer2); + bind[1].buffer = buffer2; + bind[1].error = &err; + bind[1].is_null = &isnull; + + // Execute a write, should return the master's server ID + test.add_result(mysql_stmt_prepare(stmt, write_query, strlen(write_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"); + test.add_result(strcmp(buffer, server_id[0]), "Expected server_id '%s', got '%s'", server_id[0], buffer); + + mysql_stmt_close(stmt); + stmt = mysql_stmt_init(test.conn_rwsplit); + + // Execute read, should return a slave server ID + test.add_result(mysql_stmt_prepare(stmt, read_query, strlen(read_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"); + test.add_result(strcmp(buffer, server_id[1]) && strcmp(buffer, server_id[2]) && strcmp(buffer, server_id[3]), + "Expected one of the slave server IDs (%s, %s or %s), not '%s'", + server_id[1], server_id[2], server_id[3], buffer); + + + mysql_stmt_close(stmt); + + test.close_maxscale_connections(); + + return test.global_result; +}