MXS-2785: Add rewrite test

The test checks that database rewriting works.
This commit is contained in:
Markus Mäkelä 2019-12-09 14:11:26 +02:00
parent 1ef130a870
commit b32546e839
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 96 additions and 0 deletions

View File

@ -341,6 +341,9 @@ add_test_executable(mxs2456_trx_replay_cap.cpp mxs2456_trx_replay_cap mxs2456_tr
# MXS-2512: Enable transaction replay for additional rollback errors.
add_test_executable(mxs2512_trx_replay_rollback.cpp mxs2512_trx_replay_rollback mxs2512_trx_replay_rollback LABELS readwritesplit REPL_BACKEND)
# MXS-2785: Binlogfilter database rewrite test
add_test_executable(mxs2785_binlogfilter_rewrite.cpp mxs2785_binlogfilter_rewrite mxs2785_binlogfilter_rewrite LABELS binlogfilter REPL_BACKEND)
############################################
# END: Tests that require GTID #
############################################

View File

@ -0,0 +1,34 @@
[maxscale]
threads=###threads###
log_info=1
###server###
[MySQL-Monitor]
type=monitor
module=mysqlmon
servers=###server_line###
user=maxskysql
password=skysql
monitor_interval=2000
[blf]
type=filter
module=binlogfilter
rewrite_src=test_[a-z0-9]*
rewrite_dest=$0_rewritten
[Read-Connection-Router]
type=service
router=readconnroute
router_options=master
servers=###server_line###
user=maxskysql
password=skysql
filters=blf
[Read-Connection-Listener]
type=listener
service=Read-Connection-Router
protocol=MySQLClient
port=4008

View File

@ -0,0 +1,59 @@
#include "testconnections.h"
#include <sstream>
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
auto slave = test.repl->get_connection(1);
slave.connect();
slave.query("STOP SLAVE");
std::ostringstream ss;
ss << "CHANGE MASTER TO MASTER_HOST='" << test.maxscales->ip(0) << "', MASTER_PORT=4008, MASTER_USE_GTID=slave_pos";
slave.query(ss.str());
auto master = test.repl->get_connection(0);
master.connect();
// Since the servers are configured to use ROW based replication, we only
// use DDL statement to test. This makes sure they result in query events.
master.query("CREATE DATABASE test_db1");
master.query("CREATE TABLE test_db1.t1(id int)");
master.query("USE test_db1");
master.query("CREATE TABLE t2(id int)");
master.query("CREATE DATABASE test_db2");
master.query("CREATE TABLE test_db2.t1(id int)");
master.query("USE test_db2");
master.query("CREATE TABLE t2(id int)");
master.query("CREATE DATABASE some_db");
master.query("CREATE TABLE some_db.t1(id int)");
master.query("USE some_db");
master.query("CREATE TABLE t2(id int)");
slave.query("START SLAVE");
slave.query("SELECT MASTER_GTID_WAIT('" + master.field("SELECT @@last_gtid") + "', 120)");
// The filter does s/test_[a-z0-9_]*/$1_rewritten/g
test.expect(slave.query("SELECT * FROM test_db1_rewritten.t1 LIMIT 1"),
"Query to test_db1_rewritten.t1 should work: %s", slave.error());
test.expect(slave.query("SELECT * FROM test_db1_rewritten.t2 LIMIT 1"),
"Query to test_db1_rewritten.t2 should work: %s", slave.error());
test.expect(slave.query("SELECT * FROM test_db2_rewritten.t1 LIMIT 1"),
"Query to test_db2_rewritten.t1 should work: %s", slave.error());
test.expect(slave.query("SELECT * FROM test_db2_rewritten.t2 LIMIT 1"),
"Query to test_db2_rewritten.t2 should work: %s", slave.error());
test.expect(slave.query("SELECT * FROM some_db.t1 LIMIT 1"),
"Query to some_db.t1 should work: %s", slave.error());
test.expect(slave.query("SELECT * FROM some_db.t2 LIMIT 1"),
"Query to some_db.t2 should work: %s", slave.error());
master.query("DROP DATABASE test_db1");
master.query("DROP DATABASE test_db2");
master.query("DROP DATABASE some_db");
slave.query("SELECT MASTER_GTID_WAIT('" + master.field("SELECT @@last_gtid") + "', 120)");
return test.global_result;
}