Skip to content

Commit 3ac0535

Browse files
committed
integration: introduce HostFilterTest suite
Added two test cases where we disable all nodes using execution profile filtering. In result, the driver should not open any connections the requests can be routed to.
1 parent 10432bb commit 3ac0535

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

tests/src/integration/objects/cluster.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@ class Cluster : public Object<CassCluster, cass_cluster_free> {
390390
return *this;
391391
}
392392

393+
/**
394+
* Enable blacklist filtering.
395+
*
396+
* @param hosts A comma delimited list of hosts (addresses or
397+
* names)
398+
* @return Cluster object
399+
*/
400+
Cluster& with_blacklist_filtering(const std::string& hosts) {
401+
cass_cluster_set_blacklist_filtering(get(), hosts.c_str());
402+
return *this;
403+
}
404+
393405
/**
394406
* Enable/Disable preparing all hosts when preparing a new statement.
395407
*
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
#include "integration.hpp"
3+
4+
class HostFilterTest : public Integration {
5+
public:
6+
HostFilterTest() {
7+
number_dc1_nodes_ = 2;
8+
is_session_requested_ = false;
9+
}
10+
};
11+
12+
CASSANDRA_INTEGRATION_TEST_F(HostFilterTest, DefaultProfileAllNodesBlacklisted) {
13+
CHECK_FAILURE;
14+
15+
// The log that rust-driver emits when all nodes are rejected by the HostFilter.
16+
logger_.add_critera("The host filter rejected all nodes in the cluster, "
17+
"no connections that can serve user queries have been established. "
18+
"The session cannot serve any queries!");
19+
// Reject both nodes.
20+
Cluster cluster = default_cluster().with_blacklist_filtering(Options::host_prefix() + "1," +
21+
Options::host_prefix() + "2");
22+
23+
session_ = cluster.connect();
24+
25+
// Expect an empty plan error.
26+
Result result =
27+
session_.execute(Statement("SELECT * FROM system.local WHERE key='local'"), false);
28+
29+
ASSERT_EQ(CASS_ERROR_LIB_NO_HOSTS_AVAILABLE, result.error_code());
30+
ASSERT_TRUE(contains(result.error_message(), "Load balancing policy returned an empty plan."));
31+
ASSERT_GE(logger_.count(), 1u);
32+
}
33+
34+
CASSANDRA_INTEGRATION_TEST_F(HostFilterTest, MultipleProfilesAllNodesBlacklisted) {
35+
CHECK_FAILURE;
36+
37+
// The log that rust-driver emits when all nodes are rejected by the HostFilter.
38+
logger_.add_critera("The host filter rejected all nodes in the cluster, "
39+
"no connections that can serve user queries have been established. "
40+
"The session cannot serve any queries!");
41+
42+
// Add custom execution profile that disables all nodes.
43+
// Note: profiles_ field is accessed in `default_cluster()` builder method.
44+
profiles_["blacklist_all"] =
45+
ExecutionProfile::build()
46+
.with_blacklist_filtering(Options::host_prefix() + "1," + Options::host_prefix() + "2")
47+
.with_load_balance_round_robin();
48+
// Reject both nodes on default exec profile.
49+
Cluster cluster = default_cluster().with_blacklist_filtering(Options::host_prefix() + "1," +
50+
Options::host_prefix() + "2");
51+
52+
session_ = cluster.connect();
53+
54+
// Expect an empty plan error.
55+
Result result =
56+
session_.execute(Statement("SELECT * FROM system.local WHERE key='local'"), false);
57+
58+
ASSERT_EQ(CASS_ERROR_LIB_NO_HOSTS_AVAILABLE, result.error_code());
59+
ASSERT_TRUE(contains(result.error_message(), "Load balancing policy returned an empty plan."));
60+
ASSERT_GE(logger_.count(), 1u);
61+
}

0 commit comments

Comments
 (0)