Skip to content

Commit a183009

Browse files
authored
CPP-860 - Remove driver_utils in favor of testing (#335)
1 parent a5951d8 commit a183009

16 files changed

Lines changed: 176 additions & 272 deletions

cpp-driver/cmake/modules/Gtest.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ macro(GtestUnitTests project_name extra_files extra_includes excluded_test_files
246246
# and source files required to shared that code.
247247
set(INTEGRATION_TESTS_SOURCE_DIR ${CASS_ROOT_DIR}/tests/src/integration)
248248
set(INTEGRATION_TESTS_CCM_SOURCE_DIR ${INTEGRATION_TESTS_SOURCE_DIR}/ccm)
249-
set(INTEGRATION_TESTS_SOURCE_FILES ${INTEGRATION_TESTS_SOURCE_DIR}/test_utils.cpp
250-
${INTEGRATION_TESTS_SOURCE_DIR}/driver_utils.cpp)
249+
set(INTEGRATION_TESTS_SOURCE_FILES ${INTEGRATION_TESTS_SOURCE_DIR}/test_utils.cpp)
251250
set(INTEGRATION_TESTS_CCM_SOURCE_FILES "${INTEGRATION_TESTS_CCM_SOURCE_DIR}/tsocket.cpp")
252251
file(GLOB UNIT_TESTS_INCLUDE_FILES ${UNIT_TESTS_SOURCE_DIR}/*.hpp )
253252
file(GLOB UNIT_TESTS_SOURCE_FILES ${UNIT_TESTS_SOURCE_DIR}/*.cpp)

cpp-driver/src/testing.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ String get_host_from_future(CassFuture* future) {
4141
return response_future->address().hostname_or_address();
4242
}
4343

44+
StringVec get_attempted_hosts_from_future(CassFuture* future) {
45+
if (future->type() != Future::FUTURE_TYPE_RESPONSE) {
46+
return StringVec();
47+
}
48+
StringVec attempted_hosts;
49+
ResponseFuture* response_future = static_cast<ResponseFuture*>(future->from());
50+
51+
AddressVec attempted_addresses = response_future->attempted_addresses();
52+
for (AddressVec::iterator it = attempted_addresses.begin(); it != attempted_addresses.end();
53+
++it) {
54+
attempted_hosts.push_back(it->to_string());
55+
}
56+
std::sort(attempted_hosts.begin(), attempted_hosts.end());
57+
return attempted_hosts;
58+
}
59+
4460
unsigned get_connect_timeout_from_cluster(CassCluster* cluster) {
4561
return cluster->config().connect_timeout_ms();
4662
}
@@ -94,4 +110,15 @@ const CassRetryPolicy* get_retry_policy(const CassStatement* statement) {
94110
return CassRetryPolicy::to(statement->from()->retry_policy().get());
95111
}
96112

113+
String get_server_name(CassFuture* future) {
114+
if (future->type() != Future::FUTURE_TYPE_RESPONSE) {
115+
return "";
116+
}
117+
return static_cast<ResponseFuture*>(future->from())->address().server_name();
118+
}
119+
120+
void set_record_attempted_hosts(CassStatement* statement, bool enable) {
121+
static_cast<Statement*>(statement->from())->set_record_attempted_addresses(enable);
122+
}
123+
97124
}}} // namespace datastax::internal::testing

cpp-driver/src/testing.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "cassandra.h"
2121
#include "string.hpp"
22+
#include "string_ref.hpp"
2223
#include "vector.hpp"
2324

2425
#include <stdint.h>
@@ -27,16 +28,14 @@ namespace datastax { namespace internal { namespace testing {
2728

2829
CASS_EXPORT String get_host_from_future(CassFuture* future);
2930

31+
CASS_EXPORT StringVec get_attempted_hosts_from_future(CassFuture* future);
32+
3033
CASS_EXPORT unsigned get_connect_timeout_from_cluster(CassCluster* cluster);
3134

3235
CASS_EXPORT int get_port_from_cluster(CassCluster* cluster);
3336

3437
CASS_EXPORT String get_contact_points_from_cluster(CassCluster* cluster);
3538

36-
CASS_EXPORT int64_t create_murmur3_hash_from_string(const String& value);
37-
38-
CASS_EXPORT uint64_t get_time_since_epoch_in_ms();
39-
4039
CASS_EXPORT uint64_t get_host_latency_average(CassSession* session, String ip_address, int port);
4140

4241
CASS_EXPORT CassConsistency get_consistency(const CassStatement* statement);
@@ -47,6 +46,10 @@ CASS_EXPORT uint64_t get_request_timeout_ms(const CassStatement* statement);
4746

4847
CASS_EXPORT const CassRetryPolicy* get_retry_policy(const CassStatement* statement);
4948

49+
CASS_EXPORT String get_server_name(CassFuture* future);
50+
51+
CASS_EXPORT void set_record_attempted_hosts(CassStatement* statement, bool enable);
52+
5053
}}} // namespace datastax::internal::testing
5154

5255
#endif

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

Lines changed: 0 additions & 106 deletions
This file was deleted.

cpp-driver/tests/src/integration/driver_utils.hpp

Lines changed: 0 additions & 119 deletions
This file was deleted.

cpp-driver/tests/src/integration/integration.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "integration.hpp"
1818
#include "options.hpp"
1919

20+
#include "driver_info.hpp"
21+
#include "get_time.hpp"
22+
#include "murmur3.hpp"
23+
2024
#include <algorithm>
2125
#include <cstdarg>
2226
#include <iostream>
@@ -33,6 +37,9 @@
3337
// Initialize static variables
3438
bool Integration::skipped_message_displayed_ = false;
3539

40+
using namespace datastax::internal;
41+
using namespace ::testing;
42+
3643
Integration::Integration()
3744
: ccm_(NULL)
3845
, session_()
@@ -73,7 +80,7 @@ Integration::Integration()
7380
}
7481

7582
// Get the name of the test and the case/suite it belongs to
76-
const testing::TestInfo* test_information = testing::UnitTest::GetInstance()->current_test_info();
83+
const TestInfo* test_information = UnitTest::GetInstance()->current_test_info();
7784
test_name_ = test_information->name();
7885

7986
// Determine if this is a typed test (e.g. ends in a number)
@@ -496,3 +503,15 @@ bool Integration::wait_for_logger(size_t expected_count) {
496503
}
497504
return logger_.count() >= expected_count;
498505
}
506+
507+
int64_t Integration::murmur3_hash(const std::string& value) {
508+
return MurmurHash3_x64_128(value.data(), value.size(), 0);
509+
}
510+
511+
uint64_t Integration::time_since_epoch_in_ms() { return get_time_since_epoch_ms(); }
512+
513+
uint64_t Integration::time_since_epoch_us() { return get_time_since_epoch_us(); }
514+
515+
std::string Integration::driver_name() { return datastax::internal::driver_name(); }
516+
517+
std::string Integration::driver_version() { return datastax::internal::driver_version(); }

0 commit comments

Comments
 (0)