Skip to content

Commit 694ad18

Browse files
author
Michael Penick
committed
Merge branch 'master' into CPP-803
2 parents 955da66 + 1796159 commit 694ad18

5 files changed

Lines changed: 39 additions & 4 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,21 @@ TEST_F(ClusterUnitTest, LocalDcFromResolver) {
10101010
EXPECT_FALSE(connect_future->error());
10111011
ASSERT_EQ("this_local_dc", connect_future->cluster()->local_dc());
10121012
}
1013+
1014+
TEST_F(ClusterUnitTest, NoContactPoints) {
1015+
// No cluster needed
1016+
1017+
AddressVec contact_points; // Empty
1018+
1019+
Future::Ptr connect_future(new Future());
1020+
ClusterConnector::Ptr connector(
1021+
new ClusterConnector(contact_points, PROTOCOL_VERSION,
1022+
bind_callback(on_connection_connected, connect_future.get())));
1023+
connector->connect(event_loop());
1024+
1025+
ASSERT_TRUE(connect_future->wait_for(WAIT_FOR_TIME))
1026+
<< "Timed out waiting for cluster to connect";
1027+
ASSERT_TRUE(connect_future->error());
1028+
EXPECT_EQ(connect_future->error()->code, CASS_ERROR_LIB_NO_HOSTS_AVAILABLE);
1029+
}
1030+

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,18 @@ TEST_F(SessionUnitTest, LocalDcNotOverriddenOnPolicyUsingExecutionProfiles) {
830830

831831
ASSERT_EQ(0u, listener->event_count());
832832
}
833+
834+
TEST_F(SessionUnitTest, NoContactPoints) {
835+
// No cluster needed
836+
837+
Config config;
838+
config.contact_points().clear();
839+
840+
Session session;
841+
Future::Ptr connect_future(session.connect(config));
842+
ASSERT_TRUE(connect_future->wait_for(WAIT_FOR_TIME))
843+
<< "Timed out waiting for session to connect";
844+
ASSERT_TRUE(connect_future->error());
845+
EXPECT_EQ(connect_future->error()->code, CASS_ERROR_LIB_NO_HOSTS_AVAILABLE);
846+
}
847+

cpp-driver/src/cloud_secure_connection_config.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ bool CloudSecureConnectionConfig::load(const String& filename, Config* config /*
237237
return false;
238238
}
239239

240+
json::MemoryStream memory_stream(contents.c_str(), contents.size());
241+
json::AutoUTFMemoryInputStream auto_utf_stream(memory_stream);
240242
json::Document document;
241-
document.Parse(contents.c_str());
243+
document.ParseStream(auto_utf_stream);
242244
if (!document.IsObject()) {
243245
LOG_ERROR(CLOUD_ERROR "Invalid configuration");
244246
return false;

cpp-driver/src/cluster_connector.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ Cluster::Ptr ClusterConnector::release_cluster() {
104104
void ClusterConnector::internal_resolve_and_connect() {
105105
inc_ref();
106106

107-
assert(!contact_points_.empty() && "Contact points should never be empty");
108-
109-
if (random_) {
107+
if (random_ && !contact_points_.empty()) {
110108
random_shuffle(contact_points_.begin(), contact_points_.end(), random_);
111109
}
112110

cpp-driver/src/json.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ class Allocator {
7373

7474
typedef datastax::rapidjson::UTF8<> UTF8;
7575
typedef datastax::rapidjson::MemoryPoolAllocator<json::Allocator> MemoryPoolAllocator;
76+
typedef datastax::rapidjson::MemoryStream MemoryStream;
7677

7778
typedef datastax::rapidjson::GenericDocument<UTF8, MemoryPoolAllocator, json::Allocator> Document;
7879
typedef datastax::rapidjson::GenericValue<UTF8, MemoryPoolAllocator> Value;
7980
typedef datastax::rapidjson::GenericStringBuffer<UTF8, json::Allocator> StringBuffer;
81+
typedef datastax::rapidjson::AutoUTFInputStream<unsigned, MemoryStream> AutoUTFMemoryInputStream;
8082

8183
template <typename OutputStream, typename SourceEncoding = UTF8, typename TargetEncoding = UTF8,
8284
typename StackAllocator = json::Allocator,

0 commit comments

Comments
 (0)