MXS-2481 Add simple Clustrix test

This commit is contained in:
Johan Wikman 2019-05-21 10:42:17 +03:00
parent b837e24995
commit 97ad45125d
2 changed files with 105 additions and 0 deletions

View File

@ -1141,6 +1141,9 @@ set_tests_properties(bug471_big PROPERTIES TIMEOUT 3600)
add_test_executable(clustrix_mon.cpp clustrix_mon clustrix_mon LABELS CLUSTRIX_BACKEND UNSTABLE)
set_tests_properties(clustrix_mon PROPERTIES TIMEOUT 7200)
add_test_executable(clustrix_basics.cpp clustrix_basics clustrix_basics LABELS CLUSTRIX_BACKEND)
set_tests_properties(clustrix_basics PROPERTIES TIMEOUT 7200)
############################################
# END: tests for Clustrix monitor #
############################################

View File

@ -0,0 +1,102 @@
/**
* @file clustrix_mon.cpp - simple Clustrix monitor test
* Just creates Clustrix cluster and connect Maxscale to it
* It can be used as a template for clustrix tests
*
* See Clustrix_nodes.h for details about configiration
*/
#include <iostream>
#include <maxbase/string.hh>
#include <maxscale/jansson.hh>
#include "testconnections.h"
#include "maxctrl.hh"
using namespace std;
namespace
{
const set<string> bootstrap_servers =
{
"clustrix_server1",
"clustrix_server2",
"clustrix_server3",
"clustrix_server4",
};
const std::string monitor_name = "Clustrix-Monitor";
void check_for_servers(const MaxCtrl& maxctrl)
{
TestConnections& test = maxctrl.test();
auto servers = maxctrl.list_servers();
test.expect(servers.size() >= bootstrap_servers.size(),
"Expected at least %d servers.", (int)bootstrap_servers.size());
set<string> static_servers;
set<string> dynamic_servers;
string prefix = "@@" + monitor_name;
for (const auto& server : servers)
{
string name = server.name;
cout << "Looking at: " << name << endl;
if (bootstrap_servers.find(name) != bootstrap_servers.end())
{
static_servers.insert(name);
continue;
}
if (name.find(prefix) != 0)
{
test.expect(false, "The name of a dynamic Clustrix node does not start with \"%s\": %s",
prefix.c_str(), name.c_str());
}
dynamic_servers.insert(name);
}
test.expect(static_servers == bootstrap_servers,
"Did not find expected servers.\n"
"Found : %s\n"
"Expected: %s",
mxb::join(static_servers).c_str(),
mxb::join(bootstrap_servers).c_str());
test.expect(dynamic_servers.size() == 4,
"Did not find expected numbers of servers %d != 4: %s",
(int)dynamic_servers.size(),
mxb::join(dynamic_servers).c_str());
}
void run_test(TestConnections& test)
{
MaxCtrl maxctrl(&test);
check_for_servers(maxctrl);
}
}
int main(int argc, char* argv[])
{
TestConnections test(argc, argv);
try
{
run_test(test);
}
catch (const std::exception& x)
{
cout << "Exception: " << x.what() << endl;
}
return test.global_result;
}