Skip to content

Commit fa6478d

Browse files
author
Michael Penick
committed
CPP-879 Add remote DC recovery unit test
1 parent 5336f35 commit fa6478d

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

gtests/src/unit/tests/test_session.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,46 @@ TEST_F(SessionUnitTest, DefaultConsistencyExecutionProfileNotUpdated) {
935935
close(&session);
936936
}
937937

938+
TEST_F(SessionUnitTest, RemoteDCNodeRecovery) {
939+
mockssandra::SimpleCluster cluster(simple(), 1, 1); // 1 local DC node and 1 remote DC node
940+
ASSERT_EQ(cluster.start_all(), 0);
941+
942+
ExecutionProfile profile;
943+
Config config;
944+
config.set_constant_reconnect(100); // Faster reconnect time to handle node outages
945+
config.contact_points().push_back(Address("127.0.0.1", 9042));
946+
config.set_load_balancing_policy(new DCAwarePolicy("dc1", 1));
947+
948+
Session session;
949+
connect(config, &session);
950+
951+
cluster.stop(1); // Force using the remote node
952+
953+
cluster.stop(2); // Force the remote node down and up
954+
cluster.start(2);
955+
956+
bool remote_dc_node_recovered = false;
957+
958+
// Wait for the remote DC node to become available
959+
for (int i = 0; i < 20; ++i) { // Around 2 seconds
960+
QueryRequest::Ptr request(new QueryRequest("blah", 0));
961+
request->set_consistency(CASS_CONSISTENCY_ONE); // Don't use a LOCAL consistency
962+
request->set_record_attempted_addresses(true);
963+
ResponseFuture::Ptr future = session.execute(request, NULL);
964+
EXPECT_TRUE(future->wait_for(WAIT_FOR_TIME));
965+
if (!future->error() && !future->attempted_addresses().empty() &&
966+
Address("127.0.0.2", 9042) == future->attempted_addresses()[0]) {
967+
remote_dc_node_recovered = true;
968+
break;
969+
}
970+
test::Utils::msleep(100);
971+
}
972+
973+
EXPECT_TRUE(remote_dc_node_recovered);
974+
975+
close(&session);
976+
}
977+
938978
TEST_F(SessionUnitTest, DbaasDetectionUpdateDefaultConsistency) {
939979
mockssandra::SimpleRequestHandlerBuilder builder;
940980
builder.on(mockssandra::OPCODE_OPTIONS).execute(new SupportedDbaasOptions());

0 commit comments

Comments
 (0)