From 4dd057d99d75a64b27c37d68a435c6466d18f20b Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 9 Dec 2020 19:07:16 +0200 Subject: [PATCH] MXS-3158 Add test case Test that monitor does not alter event charset or collation. --- system-test/mariadbmonitor/CMakeLists.txt | 3 +- .../mysqlmon_fail_switch_events.cpp | 76 ++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/system-test/mariadbmonitor/CMakeLists.txt b/system-test/mariadbmonitor/CMakeLists.txt index 3744dee26..c82e4a6ef 100644 --- a/system-test/mariadbmonitor/CMakeLists.txt +++ b/system-test/mariadbmonitor/CMakeLists.txt @@ -80,7 +80,8 @@ add_test_executable_ex(NAME mysqlmon_switchover_stress SOURCE mysqlmon_switchove add_test_executable_ex(NAME mysqlmon_external_master SOURCE mysqlmon_external_master.cpp CONFIG mysqlmon_external_master.cnf VMS repl_backend LABELS mysqlmon) -# Check failover, switchover and rejoin with scheduled server events, uses config of mysqlmon_rejoin_good +# Check failover, switchover and rejoin with scheduled server events +# Also, MXS-3158 add_test_executable_ex(NAME mysqlmon_fail_switch_events SOURCE mysqlmon_fail_switch_events.cpp CONFIG mysqlmon_rejoin_good.cnf VMS repl_backend LABELS mysqlmon) diff --git a/system-test/mariadbmonitor/mysqlmon_fail_switch_events.cpp b/system-test/mariadbmonitor/mysqlmon_fail_switch_events.cpp index 348be3bc6..8c10d7586 100644 --- a/system-test/mariadbmonitor/mysqlmon_fail_switch_events.cpp +++ b/system-test/mariadbmonitor/mysqlmon_fail_switch_events.cpp @@ -14,6 +14,7 @@ #include #include "failover_common.cpp" #include +#include using std::string; @@ -28,6 +29,10 @@ const char EV_STATE_SLAVE_DISABLED[] = "SLAVESIDE_DISABLED"; const char WRONG_MASTER_FMT[] = "%s is not master as expected. Current master id: %i."; +void expect_event_charset_collation(TestConnections& test, const string& event_name, + const string& client_charset, const string& collation_connection, + const string& database_collation); + int read_incremented_field(TestConnections& test) { int rval = -1; @@ -307,7 +312,7 @@ int main(int argc, char** argv) if (test.ok()) { - // Check that all other nodes are slaves. + // Check that all other nodes are slaves. for (int i = 1; i < N; i++) { string server_name = server_names[i]; @@ -316,6 +321,42 @@ int main(int argc, char** argv) } } + if (test.ok()) + { + // MXS-3158 Check that monitor preserves the character set and collation of an even when altering it. + test.tprintf("Checking event handling with non-default charset and collation."); + + const char def_charset[] = "latin1"; + const char def_collation[] = "latin1_swedish_ci"; + + expect_event_charset_collation(test, EVENT_NAME, def_charset, def_collation, def_collation); + if (test.ok()) + { + // Alter event charset to utf8. + const char new_charset[] = "utf8mb4"; + const char new_collation[] = "utf8mb4_estonian_ci"; + auto conn = test.repl->nodes[0]; + test.try_query(conn, "SET NAMES %s COLLATE %s; ALTER EVENT %s ENABLE;", + new_charset, new_collation, EVENT_NAME); + check_event_status(test, server1_ind, EVENT_NAME, EV_STATE_ENABLED); + expect_event_charset_collation(test, EVENT_NAME, new_charset, new_collation, def_collation); + + if (test.ok()) + { + switchover(test, server2_name); + if (test.ok()) + { + check_event_status(test, server2_ind, EVENT_NAME, EV_STATE_ENABLED); + expect_event_charset_collation(test, EVENT_NAME, new_charset, new_collation, + def_collation); + } + + // Switchover back. + switchover(test, server1_name); + } + } + } + try_delete_event(test); if (test.global_result != 0) { @@ -323,3 +364,36 @@ int main(int argc, char** argv) } return test.global_result; } + +void expect_event_charset_collation(TestConnections& test, const string& event_name, + const string& client_charset, const string& collation_connection, + const string& database_collation) +{ + auto conn = test.maxscales->rwsplit(); + conn.connect(); + string query = string_printf("select CHARACTER_SET_CLIENT, COLLATION_CONNECTION, DATABASE_COLLATION " + "from information_schema.EVENTS where EVENT_NAME = '%s';", + event_name.c_str()); + Row row = conn.row(query); + if (!row.empty()) + { + string& found_charset = row[0]; + string& found_collation = row[1]; + string& found_dbcoll = row[2]; + + test.tprintf("Event '%s': CHARACTER_SET_CLIENT is '%s', COLLATION_CONNECTION is '%s', " + "DATABASE_COLLATION is '%s'", + EVENT_NAME, found_charset.c_str(), found_collation.c_str(), found_dbcoll.c_str()); + const char error_fmt[] = "Wrong %s. Found %s, expected %s."; + test.expect(found_charset == client_charset, error_fmt, "CHARACTER_SET_CLIENT", + found_charset.c_str(), client_charset.c_str()); + test.expect(found_collation == collation_connection, error_fmt, "COLLATION_CONNECTION", + found_collation.c_str(), collation_connection.c_str()); + test.expect(found_dbcoll == database_collation, error_fmt, "DATABASE_COLLATION", + found_dbcoll.c_str(), database_collation.c_str()); + } + else + { + test.expect(false, "Query '%s' failed.", query.c_str()); + } +}