From b5045878709e378fa5f267db83c120645253bfc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 1 Jun 2017 23:28:19 +0300 Subject: [PATCH] Make avrorouter testing faster The slave part of the binlogrouter replication can be ignored for avrorouter tests. This will speed up the testing by skipping the unnecessary restarting and configuration of slave servers. --- maxscale-system-test/avro.cpp | 70 ++++++++++-------------- maxscale-system-test/testconnections.cpp | 38 +++++++++++++ maxscale-system-test/testconnections.h | 5 ++ 3 files changed, 71 insertions(+), 42 deletions(-) diff --git a/maxscale-system-test/avro.cpp b/maxscale-system-test/avro.cpp index 7dbd365b2..fa80f5019 100644 --- a/maxscale-system-test/avro.cpp +++ b/maxscale-system-test/avro.cpp @@ -25,45 +25,33 @@ using std::endl; int main(int argc, char *argv[]) { - TestConnections * Test = new TestConnections(argc, argv); - Test->set_timeout(600); - Test->stop_maxscale(); - Test->ssh_maxscale(true, (char *) "rm -rf /var/lib/maxscale/avro"); + TestConnections test(argc, argv); + test.set_timeout(600); + test.ssh_maxscale(true, (char *) "rm -rf /var/lib/maxscale/avro"); - Test->repl->connect(); - execute_query(Test->repl->nodes[0], "DROP TABLE IF EXISTS t1"); - Test->repl->close_connections(); - sleep(5); + /** Start master to binlogrouter replication */ + if (!test.replicate_from_master()) + { + return 1; + } + test.set_timeout(120); + test.repl->connect(); - Test->start_binlog(); + create_t1(test.repl->nodes[0]); + insert_into_t1(test.repl->nodes[0], 3); + execute_query(test.repl->nodes[0], "FLUSH LOGS"); - Test->set_timeout(120); - - Test->stop_maxscale(); - - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/avro"); - - Test->set_timeout(120); - - Test->start_maxscale(); - - Test->set_timeout(60); - - Test->repl->connect(); - create_t1(Test->repl->nodes[0]); - insert_into_t1(Test->repl->nodes[0], 3); - execute_query(Test->repl->nodes[0], "FLUSH LOGS"); - - Test->repl->close_connections(); - - Test->set_timeout(120); + test.repl->close_connections(); + /** Give avrorouter some time to process the events */ + test.stop_timeout(); sleep(10); + test.set_timeout(120); - char * avro_check = Test->ssh_maxscale_output(true, - "maxavrocheck -vv /var/lib/maxscale/avro/test.t1.000001.avro | grep \"{\""); - char * output = Test->ssh_maxscale_output(true, "maxavrocheck -d /var/lib/maxscale/avro/test.t1.000001.avro"); + char * avro_check = test.ssh_maxscale_output(true, + "maxavrocheck -vv /var/lib/maxscale/avro/test.t1.000001.avro | grep \"{\""); + char * output = test.ssh_maxscale_output(true, "maxavrocheck -d /var/lib/maxscale/avro/test.t1.000001.avro"); std::istringstream iss; iss.str(output); @@ -74,13 +62,13 @@ int main(int argc, char *argv[]) for (std::string line; std::getline(iss, line);) { long long int x1, fl; - Test->set_timeout(20); + test.set_timeout(20); get_x_fl_from_json((char*)line.c_str(), &x1, &fl); if (x1 != x1_exp || fl != fl_exp) { - Test->add_result(1, "Output:x1 %lld, fl %lld, Expected: x1 %d, fl %d", - x1, fl, x1_exp, fl_exp); + test.add_result(1, "Output:x1 %lld, fl %lld, Expected: x1 %d, fl %d", + x1, fl, x1_exp, fl_exp); break; } @@ -89,19 +77,17 @@ int main(int argc, char *argv[]) x1_exp = 0; x = x * 16; fl_exp++; - Test->tprintf("fl = %d", fl_exp); + test.tprintf("fl = %d", fl_exp); } } if (fl_exp != 3) { - Test->add_result(1, "not enough lines in avrocheck output\n"); + test.add_result(1, "not enough lines in avrocheck output"); } - Test->set_timeout(120); + execute_query(test.repl->nodes[0], "DROP TABLE test.t1;RESET MASTER"); + test.repl->fix_replication(); - int rval = Test->global_result; - delete Test; - return rval; + return test.global_result; } - diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index a151c1c41..9d6a2e446 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -954,6 +954,44 @@ int TestConnections::start_binlog() return global_result; } +bool TestConnections::replicate_from_master() +{ + bool rval = true; + + /** Stop the binlogrouter */ + MYSQL* conn = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); + + if (execute_query(conn, "stop slave")) + { + rval = false; + } + mysql_close(conn); + + /** Clean up MaxScale directories */ + prepare_binlog(); + ssh_maxscale(true, "service maxscale restart"); + + char log_file[256] = ""; + char log_pos[256] = "4"; + + repl->execute_query_all_nodes("STOP SLAVE"); + repl->connect(); + execute_query(repl->nodes[0], "RESET MASTER"); + + conn = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); + + if (find_field(repl->nodes[0], "show master status", "File", log_file) || + repl->set_slave(conn, repl->IP[0], repl->port[0], log_file, log_pos) || + execute_query(conn, "start slave")) + { + rval = false; + } + + mysql_close(conn); + + return rval; +} + int TestConnections::start_mm() { int i; diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index b5e171859..a79c01a93 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -442,6 +442,11 @@ public: */ int start_binlog(); + /** + * @brief Start binlogrouter replication from master + */ + bool replicate_from_master(); + /** * @brief prepare_binlog clean up binlog directory, set proper access rights to it * @return 0