MaxScale/maxscale-system-test/mxs1295_sp_call.cpp
Markus Mäkelä 481ad080ef MXS-1295: Add test case
The test case checks that the strict_sp_calls parameter works as expected.
2017-09-20 11:18:16 +03:00

45 lines
1.3 KiB
C++

/**
* Test for MXS-1295: https://jira.mariadb.org/browse/MXS-1295
*/
#include "testconnections.h"
const char sp_sql[] =
"DROP PROCEDURE IF EXISTS multi;"
"CREATE PROCEDURE multi()"
"BEGIN"
" SELECT @@server_id;"
"END";
int get_server_id(MYSQL* conn)
{
char value[200] = "";
find_field(conn, "SELECT @@server_id", "@@server_id", value);
return atoi(value);
}
int main(int argc, char *argv[])
{
TestConnections test(argc, argv);
test.connect_maxscale();
test.repl->connect();
test.tprintf("Create the stored procedure and check that it works");
test.try_query(test.repl->nodes[0], sp_sql);
test.try_query(test.repl->nodes[0], "CALL multi()");
test.tprintf("Check that queries after a CALL command get routed to the master");
int master = get_server_id(test.repl->nodes[0]);
int slave = get_server_id(test.repl->nodes[1]);
int result = get_server_id(test.conn_rwsplit);
test.add_result(result != slave, "The query should be routed to a slave(%d): %d", slave, result);
test.try_query(test.conn_rwsplit, "USE test");
test.try_query(test.conn_rwsplit, "CALL multi()");
result = get_server_id(test.conn_rwsplit);
test.add_result(result != master, "The query should be routed to the master(%d): %d", master, result);
return test.global_result;
}