Add test for "enforce_simple_topology"

This commit is contained in:
Esa Korhonen 2019-06-25 18:55:35 +03:00
parent 6509863373
commit 7c2d5fd6a4
3 changed files with 169 additions and 0 deletions

View File

@ -287,6 +287,9 @@ add_test_executable(mysqlmon_switchover_auto.cpp mysqlmon_switchover_auto mysqlm
# MySQL Monitor series of failovers and rejoins
add_test_executable(mysqlmon_failover_readonly.cpp mysqlmon_failover_readonly mysqlmon_failover_readonly LABELS mysqlmon REPL_BACKEND)
# MariaDB-Monitor enforce_simple_topology
add_test_executable(mysqlmon_enforce_simple.cpp mysqlmon_enforce_simple mysqlmon_enforce_simple LABELS mysqlmon REPL_BACKEND)
# MXS-1506: Delayed query retry
# https://jira.mariadb.org/browse/MXS-1506
add_test_executable(mxs1506_delayed_retry.cpp mxs1506_delayed_retry mxs1506_delayed_retry LABELS readwritesplit REPL_BACKEND)

View File

@ -0,0 +1,65 @@
[maxscale]
threads=###threads###
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers= server1, server2, server3, server4
user=maxskysql
password= skysql
monitor_interval=1000
failcount=2
enforce_simple_topology=true
replication_user=repl
replication_password=repl
backend_connect_timeout=10
backend_read_timeout=10
backend_write_timeout=10
[RW-Split-Router]
type=service
router= readwritesplit
servers=server1, server2, server3, server4
user=maxskysql
password=skysql
[RW-Split-Listener]
type=listener
service=RW-Split-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

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2019 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2023-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include "testconnections.h"
#include <iostream>
#include <maxbase/format.hh>
using std::string;
using std::cout;
int get_master_server_id(TestConnections& test)
{
MYSQL* conn = test.maxscales->open_rwsplit_connection(0);
int id = -1;
char str[1024];
if (find_field(conn, "SELECT @@server_id, @@last_insert_id;", "@@server_id", str) == 0)
{
id = atoi(str);
}
mysql_close(conn);
return id;
}
int main(int argc, char** argv)
{
Mariadb_nodes::require_gtid(true);
TestConnections::skip_maxscale_start(true);
TestConnections test(argc, argv);
if (test.repl->N < 4)
{
test.expect(false, "This test requires at least 4 backends.");
return test.global_result;
}
test.repl->connect();
auto server_ids = test.repl->get_all_server_ids();
// Stop the master and the last slave, then start MaxScale.
int master_ind = 0;
int last_slave_ind = 3;
string master_name = mxb::string_printf("server%i", master_ind + 1);
string slave_name = mxb::string_printf("server%i", last_slave_ind + 1);
test.tprintf("Stopping %s and %s.", master_name.c_str(), slave_name.c_str());
test.repl->stop_node(master_ind);
test.repl->stop_node(last_slave_ind);
test.tprintf("Starting MaxScale");
test.start_maxscale(0);
sleep(3);
test.maxscales->wait_for_monitor(3);
test.log_includes(0, "Performing automatic failover");
int new_master_id = get_master_server_id(test);
int expected_id1 = server_ids[1];
int expected_id2 = server_ids[2];
test.expect(new_master_id == expected_id1 || new_master_id == expected_id2,
"Unexpected master server id. Got %i when %i or %i was expected.",
new_master_id, expected_id1, expected_id2);
if (test.ok())
{
// Restart server4, check that it rejoins.
test.repl->start_node(last_slave_ind, (char*)"");
test.maxscales->wait_for_monitor(2);
auto states = test.maxscales->get_server_status(slave_name.c_str());
test.expect(states.count("Slave") == 1, "%s is not replicating as it should.", slave_name.c_str());
}
if (test.ok())
{
// Finally, bring back old master and swap to it.
test.repl->start_node(master_ind, (char*)"");
test.maxscales->wait_for_monitor(2);
test.tprintf("Switching back old master %s.", master_name.c_str());
string switchover = "call command mariadbmon switchover MariaDB-Monitor " + master_name;
test.maxscales->execute_maxadmin_command(0, switchover.c_str());
test.maxscales->wait_for_monitor(2);
new_master_id = get_master_server_id(test);
test.expect(new_master_id == server_ids[master_ind], "Switchover to original master failed.");
}
return test.global_result;
}