Skip to content

Commit bacce8e

Browse files
authored
CPP-797/CPP-800 Node discovery should use host_id and add mapping for affected node (#272)
1 parent f60178d commit bacce8e

45 files changed

Lines changed: 696 additions & 349 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp-driver/gtests/src/integration/driver_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ unsigned int test::driver::internals::Utils::connect_timeout(CassCluster* cluste
5050

5151
std::string test::driver::internals::Utils::contact_points(CassCluster* cluster) {
5252
std::string contact_points;
53-
const ContactPointList& contact_points_list = cluster->config().contact_points();
54-
for (ContactPointList::const_iterator it = contact_points_list.begin();
55-
it != contact_points_list.end(); ++it) {
53+
const AddressVec& contact_points_list = cluster->config().contact_points();
54+
for (AddressVec::const_iterator it = contact_points_list.begin(); it != contact_points_list.end();
55+
++it) {
5656
if (contact_points.size() > 0) {
5757
contact_points.push_back(',');
5858
}
59-
contact_points.append((*it).c_str());
59+
contact_points.append((*it).hostname_or_address().c_str());
6060
}
6161
return contact_points;
6262
}
@@ -73,7 +73,7 @@ std::string test::driver::internals::Utils::host(CassFuture* future) {
7373
if (future) {
7474
Future* cass_future = static_cast<Future*>(future);
7575
if (cass_future->type() == Future::FUTURE_TYPE_RESPONSE) {
76-
return static_cast<ResponseFuture*>(cass_future)->address().to_string().c_str();
76+
return static_cast<ResponseFuture*>(cass_future)->address().hostname_or_address().c_str();
7777
}
7878
}
7979
return "";

cpp-driver/gtests/src/unit/tests/test_address.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,41 @@ TEST(AddressUnitTest, ToInetIPv6) {
9797
EXPECT_EQ(expected, actual);
9898
}
9999

100+
TEST(AddressUnitTest, ToString) {
101+
// Only hostname/address
102+
EXPECT_EQ(Address("127.0.0.1", 9042).hostname_or_address(), "127.0.0.1");
103+
EXPECT_EQ(Address("::1", 9042).hostname_or_address(), "::1");
104+
EXPECT_EQ(Address("0:0:0:0:0:0:0:1", 9042).hostname_or_address(), "::1"); // IPv6 normalization
105+
EXPECT_EQ(Address("0:0:0:0:0:0:0:0", 9042).hostname_or_address(), "::"); // IPv6 normalization
106+
EXPECT_EQ(Address("datastax.com", 9042).hostname_or_address(), "datastax.com");
107+
108+
// w/o port
109+
EXPECT_EQ(Address("127.0.0.1", 9042).to_string(), "127.0.0.1");
110+
EXPECT_EQ(Address("::1", 9042).to_string(), "::1");
111+
EXPECT_EQ(Address("datastax.com", 9042).to_string(), "datastax.com");
112+
113+
// w/ port
114+
EXPECT_EQ(Address("127.0.0.1", 9042).to_string(true), "127.0.0.1:9042");
115+
EXPECT_EQ(Address("::1", 9042).to_string(true), "[::1]:9042");
116+
EXPECT_EQ(Address("datastax.com", 9042).to_string(true), "datastax.com:9042");
117+
118+
// w/ servername
119+
EXPECT_EQ(Address("127.0.0.1", 9042, "d1f1884b-6e05-4b3f-9e88-8a93904bb0e5").to_string(),
120+
"127.0.0.1 (d1f1884b-6e05-4b3f-9e88-8a93904bb0e5)");
121+
EXPECT_EQ(Address("::1", 9042, "d1f1884b-6e05-4b3f-9e88-8a93904bb0e5").to_string(),
122+
"::1 (d1f1884b-6e05-4b3f-9e88-8a93904bb0e5)");
123+
EXPECT_EQ(Address("datastax.com", 9042, "d1f1884b-6e05-4b3f-9e88-8a93904bb0e5").to_string(),
124+
"datastax.com (d1f1884b-6e05-4b3f-9e88-8a93904bb0e5)");
125+
126+
// w/ servername and port
127+
EXPECT_EQ(Address("127.0.0.1", 9042, "d1f1884b-6e05-4b3f-9e88-8a93904bb0e5").to_string(true),
128+
"127.0.0.1:9042 (d1f1884b-6e05-4b3f-9e88-8a93904bb0e5)");
129+
EXPECT_EQ(Address("::1", 9042, "d1f1884b-6e05-4b3f-9e88-8a93904bb0e5").to_string(true),
130+
"[::1]:9042 (d1f1884b-6e05-4b3f-9e88-8a93904bb0e5)");
131+
EXPECT_EQ(Address("datastax.com", 9042, "d1f1884b-6e05-4b3f-9e88-8a93904bb0e5").to_string(true),
132+
"datastax.com:9042 (d1f1884b-6e05-4b3f-9e88-8a93904bb0e5)");
133+
}
134+
100135
TEST(AddressUnitTest, Hash) {
101136
AddressSet set;
102137

cpp-driver/gtests/src/unit/tests/test_cluster.cpp

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ TEST_F(ClusterUnitTest, Simple) {
329329
mockssandra::SimpleCluster cluster(simple(), 3);
330330
ASSERT_EQ(cluster.start_all(), 0);
331331

332-
ContactPointList contact_points;
333-
contact_points.push_back("127.0.0.1");
334-
contact_points.push_back("127.0.0.2");
335-
contact_points.push_back("127.0.0.3");
332+
AddressVec contact_points;
333+
contact_points.push_back(Address("127.0.0.1", 9042));
334+
contact_points.push_back(Address("127.0.0.2", 9042));
335+
contact_points.push_back(Address("127.0.0.3", 9042));
336336

337337
Future::Ptr connect_future(new Future());
338338
ClusterConnector::Ptr connector(
@@ -363,13 +363,13 @@ TEST_F(ClusterUnitTest, SimpleWithCriticalFailures) {
363363
.then(mockssandra::Action::Builder().plaintext_auth())
364364
.auth_success();
365365

366-
ContactPointList contact_points;
367-
contact_points.push_back("127.0.0.1"); // Good
368-
contact_points.push_back("127.0.0.2"); // Invalid auth
366+
AddressVec contact_points;
367+
contact_points.push_back(Address("127.0.0.1", 9042)); // Good
368+
contact_points.push_back(Address("127.0.0.2", 9042)); // Invalid auth
369369
add_logging_critera("Unable to connect to host 127.0.0.2 because of the "
370370
"following error: Received error response 'Invalid "
371371
"credentials'");
372-
contact_points.push_back("127.0.0.3"); // Invalid protocol
372+
contact_points.push_back(Address("127.0.0.3", 9042)); // Invalid protocol
373373
add_logging_critera("Unable to connect to host 127.0.0.3 because of the "
374374
"following error: Received error response 'Invalid or "
375375
"unsupported protocol version'");
@@ -399,8 +399,8 @@ TEST_F(ClusterUnitTest, Resolve) {
399399
mockssandra::SimpleCluster cluster(simple(), 3);
400400
ASSERT_EQ(cluster.start_all(), 0);
401401

402-
ContactPointList contact_points;
403-
contact_points.push_back("localhost");
402+
AddressVec contact_points;
403+
contact_points.push_back(Address("localhost", 9042));
404404

405405
Future::Ptr connect_future(new Future());
406406
ClusterConnector::Ptr connector(
@@ -416,8 +416,8 @@ TEST_F(ClusterUnitTest, Auth) {
416416
mockssandra::SimpleCluster cluster(auth());
417417
ASSERT_EQ(cluster.start_all(), 0);
418418

419-
ContactPointList contact_points;
420-
contact_points.push_back("127.0.0.1");
419+
AddressVec contact_points;
420+
contact_points.push_back(Address("127.0.0.1", 9042));
421421

422422
Future::Ptr connect_future(new Future());
423423
ClusterConnector::Ptr connector(
@@ -440,8 +440,8 @@ TEST_F(ClusterUnitTest, Ssl) {
440440
settings.control_connection_settings.connection_settings = use_ssl(&cluster);
441441
ASSERT_EQ(cluster.start_all(), 0);
442442

443-
ContactPointList contact_points;
444-
contact_points.push_back("127.0.0.1");
443+
AddressVec contact_points;
444+
contact_points.push_back(Address("127.0.0.1", 9042));
445445

446446
Future::Ptr connect_future(new Future());
447447
ClusterConnector::Ptr connector(
@@ -461,10 +461,10 @@ TEST_F(ClusterUnitTest, Cancel) {
461461
Vector<Future::Ptr> connect_futures;
462462
Vector<ClusterConnector::Ptr> connectors;
463463

464-
ContactPointList contact_points;
465-
contact_points.push_back("localhost");
466-
contact_points.push_back("google.com");
467-
contact_points.push_back("doesnotexist.dne");
464+
AddressVec contact_points;
465+
contact_points.push_back(Address("localhost", 9042));
466+
contact_points.push_back(Address("google.com", 9042));
467+
contact_points.push_back(Address("doesnotexist.dne", 9042));
468468

469469
for (size_t i = 0; i < 10; ++i) {
470470
Future::Ptr connect_future(new Future());
@@ -507,8 +507,8 @@ TEST_F(ClusterUnitTest, ReconnectToDiscoveredHosts) {
507507
outage_plan.start_node(1);
508508
outage_plan.stop_node(3);
509509

510-
ContactPointList contact_points;
511-
contact_points.push_back("127.0.0.1");
510+
AddressVec contact_points;
511+
contact_points.push_back(Address("127.0.0.1", 9042));
512512

513513
Future::Ptr close_future(new Future());
514514
Future::Ptr connect_future(new Future());
@@ -550,8 +550,8 @@ TEST_F(ClusterUnitTest, ReconnectUpdateHosts) {
550550
outage_plan.stop_node(3);
551551
outage_plan.stop_node(1);
552552

553-
ContactPointList contact_points;
554-
contact_points.push_back("127.0.0.1");
553+
AddressVec contact_points;
554+
contact_points.push_back(Address("127.0.0.1", 9042));
555555

556556
Future::Ptr close_future(new Future());
557557
Future::Ptr connect_future(new Future());
@@ -590,8 +590,8 @@ TEST_F(ClusterUnitTest, CloseDuringReconnect) {
590590
mockssandra::SimpleCluster mock_cluster(simple());
591591
mock_cluster.start_all();
592592

593-
ContactPointList contact_points;
594-
contact_points.push_back("127.0.0.1");
593+
AddressVec contact_points;
594+
contact_points.push_back(Address("127.0.0.1", 9042));
595595

596596
Future::Ptr close_future(new Future());
597597
Future::Ptr connect_future(new Future());
@@ -623,8 +623,8 @@ TEST_F(ClusterUnitTest, NotifyDownUp) {
623623
mockssandra::SimpleCluster mock_cluster(simple(), 3);
624624
mock_cluster.start_all();
625625

626-
ContactPointList contact_points;
627-
contact_points.push_back("127.0.0.1");
626+
AddressVec contact_points;
627+
contact_points.push_back(Address("127.0.0.1", 9042));
628628

629629
Future::Ptr close_future(new Future());
630630
Future::Ptr connect_future(new Future());
@@ -666,8 +666,8 @@ TEST_F(ClusterUnitTest, ProtocolNegotiation) {
666666
mockssandra::SimpleCluster cluster(builder.build());
667667
ASSERT_EQ(cluster.start_all(), 0);
668668

669-
ContactPointList contact_points;
670-
contact_points.push_back("127.0.0.1");
669+
AddressVec contact_points;
670+
contact_points.push_back(Address("127.0.0.1", 9042));
671671

672672
Future::Ptr connect_future(new Future());
673673
ClusterConnector::Ptr connector(
@@ -688,8 +688,8 @@ TEST_F(ClusterUnitTest, NoSupportedProtocols) {
688688
mockssandra::SimpleCluster cluster(builder.build());
689689
ASSERT_EQ(cluster.start_all(), 0);
690690

691-
ContactPointList contact_points;
692-
contact_points.push_back("127.0.0.1");
691+
AddressVec contact_points;
692+
contact_points.push_back(Address("127.0.0.1", 9042));
693693

694694
Future::Ptr connect_future(new Future());
695695
ClusterConnector::Ptr connector(
@@ -707,10 +707,10 @@ TEST_F(ClusterUnitTest, FindValidHost) {
707707
mockssandra::SimpleCluster cluster(simple(), 3);
708708
ASSERT_EQ(cluster.start_all(), 0);
709709

710-
ContactPointList contact_points;
711-
contact_points.push_back("127.99.99.1"); // Invalid
712-
contact_points.push_back("127.99.99.2"); // Invalid
713-
contact_points.push_back("127.0.0.1");
710+
AddressVec contact_points;
711+
contact_points.push_back(Address("127.99.99.1", 9042)); // Invalid
712+
contact_points.push_back(Address("127.99.99.2", 9042)); // Invalid
713+
contact_points.push_back(Address("127.0.0.1", 9042));
714714

715715
Future::Ptr connect_future(new Future());
716716
ClusterConnector::Ptr connector(
@@ -730,10 +730,10 @@ TEST_F(ClusterUnitTest, NoHostsAvailable) {
730730
// Don't start the cluster
731731

732732
// Try multiple hosts
733-
ContactPointList contact_points;
734-
contact_points.push_back("127.0.0.1");
735-
contact_points.push_back("127.0.0.2");
736-
contact_points.push_back("127.0.0.3");
733+
AddressVec contact_points;
734+
contact_points.push_back(Address("127.0.0.1", 9042));
735+
contact_points.push_back(Address("127.0.0.2", 9042));
736+
contact_points.push_back(Address("127.0.0.3", 9042));
737737

738738
Future::Ptr connect_future(new Future());
739739
ClusterConnector::Ptr connector(
@@ -751,8 +751,8 @@ TEST_F(ClusterUnitTest, InvalidAuth) {
751751
mockssandra::SimpleCluster cluster(auth());
752752
ASSERT_EQ(cluster.start_all(), 0);
753753

754-
ContactPointList contact_points;
755-
contact_points.push_back("127.0.0.1");
754+
AddressVec contact_points;
755+
contact_points.push_back(Address("127.0.0.1", 9042));
756756

757757
Future::Ptr connect_future(new Future());
758758
ClusterConnector::Ptr connector(
@@ -775,8 +775,8 @@ TEST_F(ClusterUnitTest, InvalidSsl) {
775775
use_ssl(&cluster);
776776
ASSERT_EQ(cluster.start_all(), 0);
777777

778-
ContactPointList contact_points;
779-
contact_points.push_back("127.0.0.1");
778+
AddressVec contact_points;
779+
contact_points.push_back(Address("127.0.0.1", 9042));
780780

781781
Future::Ptr connect_future(new Future());
782782
ClusterConnector::Ptr connector(
@@ -803,8 +803,8 @@ TEST_F(ClusterUnitTest, DCAwareRecoverOnRemoteHost) {
803803
Address local_address("127.0.0.1", 9042);
804804
Address remote_address("127.0.0.2", 9042);
805805

806-
ContactPointList contact_points;
807-
contact_points.push_back(local_address.to_string());
806+
AddressVec contact_points;
807+
contact_points.push_back(local_address);
808808

809809
Future::Ptr close_future(new Future());
810810
Future::Ptr connect_future(new Future());
@@ -858,8 +858,8 @@ TEST_F(ClusterUnitTest, InvalidDC) {
858858
mockssandra::SimpleCluster cluster(simple());
859859
ASSERT_EQ(cluster.start_all(), 0);
860860

861-
ContactPointList contact_points;
862-
contact_points.push_back("127.0.0.1");
861+
AddressVec contact_points;
862+
contact_points.push_back(Address("127.0.0.1", 9042));
863863

864864
Future::Ptr connect_future(new Future());
865865
ClusterConnector::Ptr connector(
@@ -886,8 +886,8 @@ TEST_F(ClusterUnitTest, DisableEventsOnStartup) {
886886
mockssandra::SimpleCluster cluster(simple(), 2);
887887
ASSERT_EQ(cluster.start_all(), 0);
888888

889-
ContactPointList contact_points;
890-
contact_points.push_back("127.0.0.1");
889+
AddressVec contact_points;
890+
contact_points.push_back(Address("127.0.0.1", 9042));
891891

892892
Future::Ptr connect_future(new Future());
893893
ClusterConnector::Ptr connector(
@@ -929,8 +929,8 @@ TEST_F(ClusterUnitTest, ReconnectionPolicy) {
929929
outage_plan.stop_node(1);
930930
outage_plan.start_node(1);
931931

932-
ContactPointList contact_points;
933-
contact_points.push_back("127.0.0.1");
932+
AddressVec contact_points;
933+
contact_points.push_back(Address("127.0.0.1", 9042));
934934

935935
Future::Ptr close_future(new Future());
936936
Future::Ptr connect_future(new Future());

cpp-driver/gtests/src/unit/tests/test_session.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SessionUnitTest : public EventLoopTest {
7373
for (size_t i = 1; i <= num_nodes; ++i) {
7474
OStringStream ss;
7575
ss << "127.0.0." << i;
76-
config.contact_points().push_back(ss.str());
76+
config.contact_points().push_back(Address(ss.str(), 9042));
7777
}
7878
if (ssl_context) {
7979
config.set_ssl_context(ssl_context);
@@ -216,7 +216,7 @@ TEST_F(SessionUnitTest, InvalidKeyspace) {
216216
ASSERT_EQ(cluster.start_all(), 0);
217217

218218
Config config;
219-
config.contact_points().push_back("127.0.0.1");
219+
config.contact_points().push_back(Address("127.0.0.1", 9042));
220220
Session session;
221221

222222
Future::Ptr connect_future(session.connect(config, "invalid"));
@@ -231,7 +231,7 @@ TEST_F(SessionUnitTest, InvalidDataCenter) {
231231
ASSERT_EQ(cluster.start_all(), 0);
232232

233233
Config config;
234-
config.contact_points().push_back("127.0.0.1");
234+
config.contact_points().push_back(Address("127.0.0.1", 9042));
235235
config.set_load_balancing_policy(new DCAwarePolicy("invalid_data_center", 0, false));
236236
Session session;
237237

@@ -248,7 +248,7 @@ TEST_F(SessionUnitTest, InvalidLocalAddress) {
248248

249249
Config config;
250250
config.set_local_address(Address("1.1.1.1", PORT)); // Invalid
251-
config.contact_points().push_back("127.0.0.1");
251+
config.contact_points().push_back(Address("127.0.0.1", 9042));
252252
config.set_load_balancing_policy(new DCAwarePolicy("invalid_data_center", 0, false));
253253
Session session;
254254

@@ -436,7 +436,7 @@ TEST_F(SessionUnitTest, HostListener) {
436436

437437
Config config;
438438
config.set_constant_reconnect(100); // Reconnect immediately
439-
config.contact_points().push_back("127.0.0.2");
439+
config.contact_points().push_back(Address("127.0.0.2", 9042));
440440
config.set_host_listener(listener);
441441

442442
Session session;
@@ -494,7 +494,7 @@ TEST_F(SessionUnitTest, HostListenerDCAwareLocal) {
494494

495495
Config config;
496496
config.set_constant_reconnect(100); // Reconnect immediately
497-
config.contact_points().push_back("127.0.0.1");
497+
config.contact_points().push_back(Address("127.0.0.1", 9042));
498498
config.set_host_listener(listener);
499499

500500
Session session;
@@ -531,7 +531,7 @@ TEST_F(SessionUnitTest, HostListenerDCAwareRemote) {
531531

532532
Config config;
533533
config.set_constant_reconnect(100); // Reconnect immediately
534-
config.contact_points().push_back("127.0.0.1");
534+
config.contact_points().push_back(Address("127.0.0.1", 9042));
535535
config.set_load_balancing_policy(new DCAwarePolicy("dc1", 1, false));
536536
config.set_host_listener(listener);
537537

@@ -573,7 +573,7 @@ TEST_F(SessionUnitTest, HostListenerNodeDown) {
573573

574574
Config config;
575575
config.set_constant_reconnect(100); // Reconnect immediately
576-
config.contact_points().push_back("127.0.0.1");
576+
config.contact_points().push_back(Address("127.0.0.1", 9042));
577577
config.set_host_listener(listener);
578578

579579
Session session;

0 commit comments

Comments
 (0)