Skip to content

Commit 129b2bf

Browse files
authored
Merge pull request #279 from riptano/CPP-787/test
test: Integration tests for DBaaS using SNI single endpoint proxy
2 parents 12abd5e + 71855dd commit 129b2bf

17 files changed

Lines changed: 659 additions & 81 deletions

build.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ build:
3535
build/cassandra-unit-tests --gtest_output=xml:cassandra-unit-test-results.xml
3636
build/dse-unit-tests --gtest_output=xml:dse-unit-test-results.xml
3737
38+
if [ -f build/cassandra-integration-tests ]; then
39+
build/cassandra-integration-tests --category=cassandra --keep-clusters --verbose --gtest_filter=DbaasTests* --gtest_output=xml:dbaas-integration-test-results.xml
40+
fi
41+
3842
install_driver
3943
test_installed_driver 'dse'
4044
4145
- xunit:
42-
- "*unit-test-results.xml"
46+
- "*test-results.xml"
4347
package:
4448
allow_empty: true
4549
include: # list of files and glob paths to include in the artifact, relative to the current working directory

cpp-driver/.build.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ else
3535
fi
3636

3737
get_driver_version() {
38-
local header_file=$1
39-
local driver_prefix=$2
38+
local header_file=${1}
39+
local driver_prefix=${2}
4040
local driver_version=$(grep "#define[ \t]\+${driver_prefix}_VERSION_\(MAJOR\|MINOR\|PATCH\|SUFFIX\)" ${header_file} | awk '
4141
BEGIN { major="?"; minor="?"; patch="?" }
4242
/_VERSION_MAJOR/ { major=$3 }
@@ -65,23 +65,33 @@ install_dependencies() {
6565
}
6666

6767
build_driver() {
68-
local driver_prefix=$1
68+
local driver_prefix=${1}
6969

7070
# Ensure build directory is cleaned (static nodes are not cleaned)
7171
[[ -d build ]] && rm -rf build
7272
mkdir build
7373

7474
(
7575
cd build
76-
cmake -DCMAKE_BUILD_TYPE=Release -D${driver_prefix}_BUILD_SHARED=On -D${driver_prefix}_BUILD_STATIC=On -D${driver_prefix}_BUILD_EXAMPLES=On -D${driver_prefix}_BUILD_UNIT_TESTS=On ..
76+
BUILD_INTEGRATION_TESTS=Off
77+
if [ "${RELEASE}" = "bionic64" ]; then
78+
BUILD_INTEGRATION_TESTS=On
79+
fi
80+
cmake -DCMAKE_BUILD_TYPE=Release \
81+
-D${driver_prefix}_BUILD_SHARED=On \
82+
-D${driver_prefix}_BUILD_STATIC=On \
83+
-D${driver_prefix}_BUILD_EXAMPLES=On \
84+
-D${driver_prefix}_BUILD_UNIT_TESTS=On \
85+
-D${driver_prefix}_BUILD_INTEGRATION_TESTS=${BUILD_INTEGRATION_TESTS} \
86+
..
7787
[[ -x $(which clang-format) ]] && make format-check
7888
make -j${PROCS}
7989
)
8090
}
8191

8292
check_driver_exports() {(
8393
set +e #Disable fail fast for this subshell
84-
local driver_library=$1
94+
local driver_library=${1}
8595
if [ -f ${driver_library} ]; then
8696
declare -a MISSING_FUNCTIONS
8797
for function in "${@:2}"; do

cpp-driver/build.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ build:
3333
3434
build/cassandra-unit-tests --gtest_output=xml:cassandra-unit-test-results.xml
3535
36+
if [ -f build/cassandra-integration-tests ]; then
37+
build/cassandra-integration-tests --category=cassandra --keep-clusters --verbose --gtest_filter=DbaasTests* --gtest_output=xml:dbaas-integration-test-results.xml
38+
fi
39+
3640
install_driver
3741
test_installed_driver 'cassandra'
3842
3943
- xunit:
40-
- "*unit-test-results.xml"
44+
- "*test-results.xml"
4145
package:
4246
allow_empty: true
4347
include: # list of files and glob paths to include in the artifact, relative to the current working directory

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ std::string test::driver::internals::Utils::host(CassFuture* future) {
7979
return "";
8080
}
8181

82+
std::string test::driver::internals::Utils::server_name(CassFuture* future) {
83+
if (future) {
84+
Future* cass_future = static_cast<Future*>(future);
85+
if (cass_future->type() == Future::FUTURE_TYPE_RESPONSE) {
86+
return static_cast<ResponseFuture*>(cass_future)->address().server_name().c_str();
87+
}
88+
}
89+
return "";
90+
}
91+
8292
int64_t test::driver::internals::Utils::murmur3_hash(const std::string& value) {
8393
return MurmurHash3_x64_128(value.data(), value.size(), 0);
8494
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class Utils {
7373
*/
7474
static std::string host(CassFuture* future);
7575

76+
/**
77+
* Get the server name of the future
78+
*
79+
* @param future Future to retrieve server name from
80+
* @return Server name
81+
*/
82+
static std::string server_name(CassFuture* future);
83+
7684
/**
7785
* Get the Murmur3 hash for a given value
7886
*

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

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Integration::Integration()
5252
, is_with_vnodes_(false)
5353
, is_randomized_contact_points_(false)
5454
, is_schema_metadata_(false)
55+
, is_ccm_requested_(true)
5556
, is_ccm_start_requested_(true)
5657
, is_ccm_start_node_individually_(false)
5758
, is_session_requested_(true)
@@ -138,47 +139,49 @@ void Integration::SetUp() {
138139
data_center_nodes.push_back(number_dc1_nodes_);
139140
data_center_nodes.push_back(number_dc2_nodes_);
140141

141-
try {
142-
// Create and start the CCM cluster (if not already created)
143-
ccm_ = new CCM::Bridge(
144-
server_version_, Options::use_git(), Options::branch_tag(), Options::use_install_dir(),
145-
Options::install_dir(), Options::is_dse(), dse_workload_, Options::cluster_prefix(),
146-
Options::dse_credentials(), Options::dse_username(), Options::dse_password(),
147-
Options::deployment_type(), Options::authentication_type(), Options::host(),
148-
Options::port(), Options::username(), Options::password(), Options::public_key(),
149-
Options::private_key(), Options::is_verbose_ccm());
150-
if (ccm_->create_cluster(data_center_nodes, is_with_vnodes_, is_password_authenticator_,
151-
is_ssl_, is_client_authentication_)) {
152-
if (is_ccm_start_requested_) {
153-
if (is_ccm_start_node_individually_) {
154-
for (unsigned short node = 1; node <= (number_dc1_nodes_ + number_dc2_nodes_); ++node) {
142+
if (is_ccm_requested_) {
143+
try {
144+
// Create and start the CCM cluster (if not already created)
145+
ccm_ = new CCM::Bridge(
146+
server_version_, Options::use_git(), Options::branch_tag(), Options::use_install_dir(),
147+
Options::install_dir(), Options::is_dse(), dse_workload_, Options::cluster_prefix(),
148+
Options::dse_credentials(), Options::dse_username(), Options::dse_password(),
149+
Options::deployment_type(), Options::authentication_type(), Options::host(),
150+
Options::port(), Options::username(), Options::password(), Options::public_key(),
151+
Options::private_key(), Options::is_verbose_ccm());
152+
if (ccm_->create_cluster(data_center_nodes, is_with_vnodes_, is_password_authenticator_,
153+
is_ssl_, is_client_authentication_)) {
154+
if (is_ccm_start_requested_) {
155+
if (is_ccm_start_node_individually_) {
156+
for (unsigned short node = 1; node <= (number_dc1_nodes_ + number_dc2_nodes_); ++node) {
157+
if (is_password_authenticator_) {
158+
ccm_->start_node(node, "-Dcassandra.superuser_setup_delay_ms=0");
159+
} else {
160+
ccm_->start_node(node);
161+
}
162+
}
163+
} else {
155164
if (is_password_authenticator_) {
156-
ccm_->start_node(node, "-Dcassandra.superuser_setup_delay_ms=0");
165+
ccm_->start_cluster("-Dcassandra.superuser_setup_delay_ms=0");
157166
} else {
158-
ccm_->start_node(node);
167+
ccm_->start_cluster();
159168
}
160169
}
161-
} else {
162-
if (is_password_authenticator_) {
163-
ccm_->start_cluster("-Dcassandra.superuser_setup_delay_ms=0");
164-
} else {
165-
ccm_->start_cluster();
166-
}
167170
}
168171
}
169-
}
170172

171-
// Generate the default contact points
172-
contact_points_ =
173-
generate_contact_points(ccm_->get_ip_prefix(), number_dc1_nodes_ + number_dc2_nodes_);
173+
// Generate the default contact points
174+
contact_points_ =
175+
generate_contact_points(ccm_->get_ip_prefix(), number_dc1_nodes_ + number_dc2_nodes_);
174176

175-
// Determine if the session connection should be established
176-
if (is_session_requested_ && is_ccm_start_requested_) {
177-
connect();
177+
// Determine if the session connection should be established
178+
if (is_session_requested_ && is_ccm_start_requested_) {
179+
connect();
180+
}
181+
} catch (CCM::BridgeException be) {
182+
// Issue creating the CCM bridge instance (force failure)
183+
FAIL() << be.what();
178184
}
179-
} catch (CCM::BridgeException be) {
180-
// Issue creating the CCM bridge instance (force failure)
181-
FAIL() << be.what();
182185
}
183186
}
184187

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ class Integration : public testing::Test {
252252
* (DEFAULT: false)
253253
*/
254254
bool is_schema_metadata_;
255+
/**
256+
* Setting to determine if CCM instance should be created. True if CCM instance
257+
* should be created; false otherwise.
258+
* (DEFAULT: true)
259+
*/
260+
bool is_ccm_requested_;
255261
/**
256262
* Setting to determine if CCM cluster should be started. True if CCM cluster
257263
* should be started; false otherwise.

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
#include "bridge.hpp"
2020
#include "options.hpp"
21+
#include "ssl.hpp"
2122
#include "win_debug.hpp"
2223

2324
#include "cassandra.h"
2425
#include "test_utils.hpp"
2526

2627
#include <ostream>
2728

29+
using datastax::internal::core::SslContextFactory;
30+
2831
/**
2932
* Bootstrap listener for handling start and end of the integration tests.
3033
*/
@@ -65,6 +68,10 @@ class BootstrapListener : public testing::EmptyTestEventListener {
6568
}
6669
}
6770

71+
void OnTestStart(const testing::TestInfo& test_information) { SslContextFactory::init(); }
72+
73+
void OnTestEnd(const testing::TestInfo& test_information) { SslContextFactory::cleanup(); }
74+
6875
private:
6976
/**
7077
* Current category
@@ -106,11 +113,7 @@ std::string generate_filter(TestCategory category, const std::string& base_filte
106113
int main(int argc, char* argv[]) {
107114
// Initialize the Google testing framework
108115
testing::InitGoogleTest(&argc, argv);
109-
110-
// Add a bootstrap mechanism for program start and finish
111-
BootstrapListener* listener = NULL;
112116
testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners();
113-
listeners.Append(listener = new BootstrapListener());
114117

115118
#if defined(_WIN32) && defined(_DEBUG)
116119
// Add the memory leak checking to the listener callbacks
@@ -121,6 +124,10 @@ int main(int argc, char* argv[]) {
121124
#endif
122125
#endif
123126

127+
// Add a bootstrap mechanism for program start and finish
128+
BootstrapListener* listener = NULL;
129+
listeners.Append(listener = new BootstrapListener());
130+
124131
// Initialize the options for the integration test
125132
if (Options::initialize(argc, argv)) {
126133
// Run the integration tests from each applicable category

cpp-driver/gtests/src/integration/objects/future.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class Future : public Object<CassFuture, cass_future_free> {
9797
*/
9898
const std::string host() { return internals::Utils::host(get()); }
9999

100+
/**
101+
* Get the server name of the future
102+
*
103+
* @return Server name
104+
*/
105+
const std::string server_name() { return internals::Utils::server_name(get()); }
106+
100107
/**
101108
* Get the result from the future
102109
*

cpp-driver/gtests/src/integration/objects/result.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class Result : public Object<const CassResult, cass_result_free> {
113113
*/
114114
const std::string host() { return future_.host(); }
115115

116+
/**
117+
* Get the server name of the future
118+
*
119+
* @return Server name
120+
*/
121+
const std::string server_name() { return future_.server_name(); }
122+
116123
/**
117124
* Get the number of columns from the result
118125
*

0 commit comments

Comments
 (0)