|
| 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