MXS-1929: Add basic filter creation/destruction test

The test creates and destroys a regexfilter at runtime and checks that the
filter remains in use for as long as the connection is open.
This commit is contained in:
Markus Mäkelä
2018-08-08 00:01:59 +03:00
parent 25bc385db2
commit 30fe7d2931
4 changed files with 106 additions and 0 deletions

View File

@ -1024,6 +1024,10 @@ add_test_executable(mxs1926_killed_server.cpp mxs1926_killed_server mxs1926_kill
# https://jira.mariadb.org/browse/MXS-1929
add_test_executable(mxs1929_service_runtime.cpp mxs1929_service_runtime mxs1929_service_runtime LABELS REPL_BACKEND)
# MXS-1929: Runtime filter creation/destruction
# https://jira.mariadb.org/browse/MXS-1929
add_test_executable(mxs1929_filter_runtime.cpp mxs1929_filter_runtime mxs1929_filter_runtime LABELS REPL_BACKEND)
# MXS-1932: Hidden files are not ignored
# https://jira.mariadb.org/browse/MXS-1932
add_test_executable(mxs1932_hidden_cnf.cpp mxs1932_hidden_cnf replication LABELS REPL_BACKEND)

View File

@ -0,0 +1,13 @@
[maxscale]
threads=###threads###
log_info=1
[CLI]
type=service
router=cli
[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
socket=default

View File

@ -0,0 +1,70 @@
/**
* MXS-1929: Runtime filter creation
*/
#include "testconnections.h"
#include <iostream>
using namespace std;
void create_all(TestConnections& test)
{
test.check_maxctrl("create server server1 " + string(test.repl->ip(0)) + " " + to_string(test.repl->port[0]));
test.check_maxctrl("create server server2 " + string(test.repl->ip(1)) + " " + to_string(test.repl->port[1]));
test.check_maxctrl("create server server3 " + string(test.repl->ip(2)) + " " + to_string(test.repl->port[2]));
test.check_maxctrl("create service svc1 readwritesplit user=skysql password=skysql --servers server1 server2 server3");
test.check_maxctrl("create listener svc1 listener1 4006");
test.check_maxctrl("create monitor mon1 mariadbmon --monitor-user skysql --monitor-password skysql --servers server1 server2 server3");
}
void destroy_all(TestConnections& test)
{
test.check_maxctrl("unlink monitor mon1 server1 server2 server3");
test.check_maxctrl("unlink service svc1 server1 server2 server3");
test.check_maxctrl("destroy listener svc1 listener1");
test.check_maxctrl("destroy service svc1");
test.check_maxctrl("destroy monitor mon1");
test.check_maxctrl("destroy server server1");
test.check_maxctrl("destroy server server2");
test.check_maxctrl("destroy server server3");
}
void basic(TestConnections& test)
{
test.check_maxctrl("create filter test1 regexfilter \"match=SELECT 1\" \"replace=SELECT 2\"");
test.check_maxctrl("alter service filters svc1 test1");
Connection c = test.maxscales->rwsplit();
c.connect();
test.assert(c.check("SELECT 1", "2"), "The regex filter did not replace the query");
auto res = test.maxctrl("destroy filter test1");
test.assert(res.first != 0, "Destruction should fail when filter is in use");
test.check_maxctrl("alter service filters svc1");
test.check_maxctrl("destroy filter test1");
test.assert(c.check("SELECT 1", "2"), "The filter should not yet be destroyed");
c.disconnect();
c.connect();
test.assert(c.check("SELECT 1", "1"), "The filter should be destroyed");
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
test.tprintf("Creating servers, monitors and services");
create_all(test);
test.tprintf("Basic test");
basic(test);
test.tprintf("Destroying servers, monitors and services");
destroy_all(test);
return test.global_result;
}

View File

@ -519,6 +519,25 @@ public:
*/
void process_template(int m, const char *src, const char *dest = "/etc/maxscale.cnf");
/**
* Execute a MaxCtrl command
*
* @param cmd Command to execute, without the `maxctrl` part
* @param m MaxScale node to execute the command on
* @param sudo Run the command as root
*
* @return The exit code and output of MaxCtrl
*/
std::pair<int, std::string> maxctrl(std::string cmd, int m = 0, bool sudo = true)
{
return maxscales->ssh_output("maxctrl " + cmd, m, sudo);
}
void check_maxctrl(std::string cmd, int m = 0, bool sudo = true)
{
auto result = maxctrl(cmd, m, sudo);
assert(result.first == 0, "Command '%s' should work: %s", cmd.c_str(), result.second.c_str());
}
void check_current_operations(int m, int value);
void check_current_connections(int m, int value);