Skip to content

Commit f62553d

Browse files
committed
Merge pull request #178 from datastax/CPP-187_2.0
CPP-187 - Enhance Integration Tests for Cassandra v1.2.x (2.0)
2 parents 76120ef + 011910e commit f62553d

16 files changed

+803
-325
lines changed

test/ccm_bridge/include/cql_ccm_bridge.hpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <exception>
2121
#include <deque>
2222
#include <string.h>
23+
#include <sstream>
2324

2425
#include <boost/smart_ptr.hpp>
2526
#include <boost/noncopyable.hpp>
@@ -46,7 +47,7 @@ struct CassVersion {
4647
/**
4748
* Extra portion of version number
4849
*/
49-
char extra[64];
50+
std::string extra;
5051

5152
/**
5253
* Initializing constructor for structure
@@ -55,8 +56,58 @@ struct CassVersion {
5556
major = 0;
5657
minor = 0;
5758
patch = 0;
58-
memset(extra, '\0', sizeof(extra));
59+
extra = "";
5960
};
61+
62+
/**
63+
* Create the CassVersion from a human readable string
64+
*
65+
* @param version_string String representation to convert
66+
*/
67+
CassVersion(std::string version_string) {
68+
major = 0;
69+
minor = 0;
70+
patch = 0;
71+
extra = "";
72+
from_string(version_string);
73+
};
74+
75+
/**
76+
* Convert the version into a human readable string
77+
*/
78+
std::string to_string() {
79+
std::stringstream version_string;
80+
version_string << major << "." << minor << "." << patch;
81+
if (!extra.empty()) {
82+
version_string << "-" << patch;
83+
}
84+
return version_string.str();
85+
}
86+
87+
/**
88+
* Convert the version from human readable string to structure
89+
*
90+
* @param version_string String representation to convert
91+
*/
92+
void from_string(const std::string &version_string) {
93+
// Clean up the string for tokens
94+
std::string version(version_string);
95+
std::replace(version.begin(), version.end(), '.', ' ');
96+
std::size_t found = version.find("-");
97+
if (found != std::string::npos) {
98+
version.replace(found, 1, " ");
99+
}
100+
101+
// Convert to tokens and assign version parameters
102+
std::istringstream tokens(version);
103+
if (tokens >> major) {
104+
if (tokens >> minor) {
105+
if (tokens >> patch) {
106+
tokens >> extra;
107+
}
108+
}
109+
}
110+
}
60111
};
61112

62113
namespace cql {
@@ -81,7 +132,6 @@ class cql_ccm_bridge_t : public boost::noncopyable {
81132
void resume(int node);
82133
void kill();
83134
void kill(int node);
84-
void binary(int node, bool enable);
85135
void gossip(int node, bool enable);
86136

87137
void remove();

test/ccm_bridge/src/cql_ccm_bridge.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,21 @@ void cql_ccm_bridge_t::execute_ccm_and_print(const string& ccm_args) {
310310
}
311311

312312
CassVersion cql_ccm_bridge_t::get_cassandra_version() {
313-
//Convert the cassandra_version value into the CassVersion structure
314-
CassVersion version;
315-
sscanf(_cassandra_version.c_str(), "%hu.%hu.%hu-%s", &version.major, &version.minor, &version.patch, version.extra);
313+
CassVersion version(_cassandra_version);
316314
return version;
317315
}
318316

319317

320318
CassVersion cql_ccm_bridge_t::get_cassandra_version(int node) {
321-
//Get the version string from CCM
319+
// Get the version string from CCM
322320
std::string version_string = execute_command(boost::str(boost::format("%1% node%2% version") % CCM_COMMAND % node));
323321
size_t prefix_index = version_string.find("ReleaseVersion: ");
324322
if (prefix_index != std::string::npos) {
325323
version_string.replace(0, 16, "");
326324
}
327325

328-
//Convert the version string into the CassVersion structure
329-
CassVersion version;
330-
sscanf(version_string.c_str(), "%hu.%hu.%hu-%s", &version.major, &version.minor, &version.patch, version.extra);
326+
// Return the version of the node
327+
CassVersion version(_cassandra_version);
331328
return version;
332329
}
333330

@@ -371,14 +368,6 @@ void cql_ccm_bridge_t::kill(int node) {
371368
execute_ccm_command(boost::str(boost::format("node%1% stop --not-gently") % node));
372369
}
373370

374-
void cql_ccm_bridge_t::binary(int node, bool enable) {
375-
if (enable) {
376-
execute_ccm_command(boost::str(boost::format("node%1% nodetool enablebinary") % node));
377-
} else {
378-
execute_ccm_command(boost::str(boost::format("node%1% nodetool disablebinary") % node));
379-
}
380-
}
381-
382371
void cql_ccm_bridge_t::gossip(int node, bool enable) {
383372
if (enable) {
384373
execute_ccm_command(boost::str(boost::format("node%1% nodetool enablegossip") % node));

test/integration_tests/src/test_async.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,20 @@ struct AsyncTests : public test_utils::SingleSessionTest {
4949
std::vector<CassUuid> ids;
5050
for (size_t i = 0; i < num_concurrent_requests; ++i) {
5151
CassUuid id = test_utils::generate_time_uuid(uuid_gen);
52-
test_utils::CassStatementPtr statement(cass_statement_new_n(insert_query.data(), insert_query.size(), 3));
52+
test_utils::CassStatementPtr statement(cass_statement_new(insert_query.c_str(), 3));
53+
54+
// Determine if bound parameters can be used based on C* version
55+
if (version.major == 1) {
56+
insert_query = str(boost::format("INSERT INTO %s (id, num, str) VALUES(%s, %s, 'row%s')") % table_name % test_utils::Value<CassUuid>::to_string(id) % i % i);
57+
statement = test_utils::CassStatementPtr(cass_statement_new(insert_query.c_str(), 0));
58+
} else {
59+
BOOST_REQUIRE(cass_statement_bind_uuid(statement.get(), 0, id) == CASS_OK);
60+
BOOST_REQUIRE(cass_statement_bind_int32(statement.get(), 1, i) == CASS_OK);
61+
std::string str_value = str(boost::format("row%d") % i);
62+
BOOST_REQUIRE(cass_statement_bind_string(statement.get(), 2, str_value.c_str()) == CASS_OK);
63+
}
64+
5365
cass_statement_set_consistency(statement.get(), CASS_CONSISTENCY_QUORUM);
54-
BOOST_REQUIRE(cass_statement_bind_uuid(statement.get(), 0, id) == CASS_OK);
55-
BOOST_REQUIRE(cass_statement_bind_int32(statement.get(), 1, i) == CASS_OK);
56-
std::string str_value = str(boost::format("row%d") % i);
57-
BOOST_REQUIRE(cass_statement_bind_string_n(statement.get(), 2, str_value.data(), str_value.size()) == CASS_OK);
5866
futures->push_back(test_utils::CassFuturePtr(cass_session_execute(session, statement.get())));
5967
ids.push_back(id);
6068
}

0 commit comments

Comments
 (0)