Skip to content

Commit 88b00ab

Browse files
authored
CPP-720 - Improve custom memory alloc
1 parent b7f89a6 commit 88b00ab

166 files changed

Lines changed: 1766 additions & 1711 deletions

File tree

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/policies/ignore_retry_policy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class IgnoreRetryPolicy : public cass::DefaultRetryPolicy {
3838
* @return Driver ready retry policy
3939
*/
4040
static ::test::driver::RetryPolicy policy() {
41-
cass::RetryPolicy* policy = cass::Memory::allocate<IgnoreRetryPolicy>();
41+
cass::RetryPolicy* policy = new IgnoreRetryPolicy();
4242
policy->inc_ref();
4343
return CassRetryPolicy::to(policy);
4444
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class NextHostRetryPolicy : public cass::DefaultRetryPolicy {
3838
* @return Driver ready retry policy
3939
*/
4040
static ::test::driver::RetryPolicy policy() {
41-
cass::RetryPolicy* policy = cass::Memory::allocate<NextHostRetryPolicy>();
41+
cass::RetryPolicy* policy = new NextHostRetryPolicy();
4242
policy->inc_ref();
4343
return CassRetryPolicy::to(policy);
4444
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SharedPtr {
6262
SharedPtr(T* ptr = NULL)
6363
: object_(NULL) {
6464
if (ptr) {
65-
ObjectRef<T, D>* object_ref = cass::Memory::allocate<ObjectRef<T, D> >(ptr);
65+
ObjectRef<T, D>* object_ref = new ObjectRef<T, D>(ptr);
6666
object_ = cass::SharedRefPtr<ObjectRef<T, D> >(object_ref);
6767
}
6868
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Request {
3939
};
4040

4141
Request()
42-
: then_(cass::Memory::allocate<Success>()) { };
42+
: then_(new Success()) { };
4343

4444
/**
4545
* Generate the JSON for the priming request

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SimulacronIntegration::~SimulacronIntegration() {
3333

3434
void SimulacronIntegration::SetUpTestCase() {
3535
try {
36-
sc_ = cass::Memory::allocate<test::SimulacronCluster>();
36+
sc_ = new test::SimulacronCluster();
3737
} catch (SimulacronCluster::Exception scce) {
3838
TEST_LOG_ERROR(scce.what());
3939
}

cpp-driver/gtests/src/integration/tests/simulacron/test_simulacron_idempotent.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ SIMULACRON_INTEGRATION_TEST_F(IdempotentTest, WriteTimeoutNonIdempotentNoRetry)
7979
SKIP_TEST_IF_SIMULACRON_UNAVAILABLE;
8080

8181
// Simulate a write timeout on node 1
82-
prime_mock_query_with_result(cass::Memory::allocate<prime::WriteTimeout>(), 1);
82+
prime_mock_query_with_result(new prime::WriteTimeout(), 1);
8383

8484
// Loop through all the nodes in the cluster execute the mock query
8585
for (unsigned int n = 0; n < number_dc1_nodes_; ++n) {
@@ -108,7 +108,7 @@ SIMULACRON_INTEGRATION_TEST_F(IdempotentTest, WriteTimeoutIdempotentRetry) {
108108
SKIP_TEST_IF_SIMULACRON_UNAVAILABLE;
109109

110110
// Simulate a write timeout on node 1
111-
prime_mock_query_with_result(cass::Memory::allocate<prime::WriteTimeout>(), 1);
111+
prime_mock_query_with_result(new prime::WriteTimeout(), 1);
112112

113113
// Loop through all the nodes in the cluster execute the mock query
114114
bool was_node_one_attempted = false;
@@ -141,7 +141,7 @@ SIMULACRON_INTEGRATION_TEST_F(IdempotentTest, ClosedConnectionNonIdempotentNoRet
141141
SKIP_TEST_IF_SIMULACRON_UNAVAILABLE;
142142

143143
// Simulate a closed connection on node 1
144-
prime_mock_query_with_result(cass::Memory::allocate<prime::CloseConnection>(), 1);
144+
prime_mock_query_with_result(new prime::CloseConnection(), 1);
145145

146146
// Loop through all the nodes in the cluster execute the mock query
147147
for (unsigned int n = 0; n < number_dc1_nodes_; ++n) {
@@ -171,7 +171,7 @@ SIMULACRON_INTEGRATION_TEST_F(IdempotentTest, ClosedConnectionIdempotentRetry) {
171171
SKIP_TEST_IF_SIMULACRON_UNAVAILABLE;
172172

173173
// Simulate a closed connection on node 1
174-
prime_mock_query_with_result(cass::Memory::allocate<prime::CloseConnection>(), 1);
174+
prime_mock_query_with_result(new prime::CloseConnection(), 1);
175175

176176
// Loop through all the nodes in the cluster execute the mock query
177177
bool was_node_one_attempted = false;

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ControlConnectionFourNodeClusterTests : public ControlConnectionTests {
119119
* each
120120
*/
121121
class ControlConnectionSingleNodeDataCentersClusterTests
122-
: public ControlConnectionTests {
122+
: public ControlConnectionTests {
123123
public:
124124
ControlConnectionSingleNodeDataCentersClusterTests() {
125125
number_dc1_nodes_ = 1;
@@ -250,7 +250,7 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionTests,
250250
logger_.add_critera("Unable to establish a control connection to host " \
251251
"1.1.1.1 because of the following error:");
252252
Cluster cluster = Cluster::build().with_contact_points("1.1.1.1")
253-
.with_local_address("127.0.0.1");
253+
.with_local_address("127.0.0.1");
254254
try {
255255
cluster.connect();
256256
FAIL() << "Connection was established using invalid IP address";
@@ -289,8 +289,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionTwoNodeClusterTests,
289289
* node discovery of the second node
290290
*/
291291
Cluster cluster = default_cluster()
292-
.with_load_balance_round_robin()
293-
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
292+
.with_load_balance_round_robin()
293+
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
294294
Session session = cluster.connect();
295295

296296
// Stop the first node and bootstrap a third node into the cluster
@@ -331,7 +331,7 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionTests, TopologyChange) {
331331
* to ensure all nodes can be accessed during request execution
332332
*/
333333
Cluster cluster = default_cluster()
334-
.with_load_balance_round_robin();
334+
.with_load_balance_round_robin();
335335
Session session = cluster.connect();
336336

337337
// Bootstrap a second node and ensure all hosts are actively used
@@ -374,8 +374,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionTwoNodeClusterTests,
374374
* to ensure all nodes can be accessed during request execution
375375
*/
376376
Cluster cluster = default_cluster()
377-
.with_load_balance_round_robin()
378-
.with_reconnect_wait_time(10); // Ensure reconnect timeout is quick
377+
.with_load_balance_round_robin()
378+
.with_reconnect_wait_time(10); // Ensure reconnect timeout is quick
379379
Session session = cluster.connect();
380380

381381
// Ensure all hosts are actively used
@@ -422,8 +422,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionThreeNodeClusterTests,
422422
* node discovery
423423
*/
424424
Cluster cluster = default_cluster()
425-
.with_load_balance_round_robin()
426-
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
425+
.with_load_balance_round_robin()
426+
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
427427
Session session = cluster.connect();
428428

429429
// Ensure all hosts are actively used
@@ -461,10 +461,10 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionThreeNodeClusterTests,
461461
logger_.add_critera("to host 192.0.2.2 closed");
462462
logger_.add_critera("to host 192.0.2.3 closed");
463463
Cluster cluster = default_cluster(false) // Do not add the default contact points
464-
.with_load_balance_round_robin()
465-
.with_contact_points(generate_contact_points("192.0.2.", 3)) // Invalid IPs
466-
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1)) // Single valid contact point
467-
.with_connect_timeout(1000u); // Handle initial invalid IPs
464+
.with_load_balance_round_robin()
465+
.with_contact_points(generate_contact_points("192.0.2.", 3)) // Invalid IPs
466+
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1)) // Single valid contact point
467+
.with_connect_timeout(1000u); // Handle initial invalid IPs
468468
Session session = cluster.connect();
469469

470470
// Ensure the invalid IPs were not reached
@@ -501,8 +501,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionThreeNodeClusterTests,
501501
* node discovery
502502
*/
503503
Cluster cluster = default_cluster()
504-
.with_load_balance_round_robin()
505-
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
504+
.with_load_balance_round_robin()
505+
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
506506
Session session = cluster.connect();
507507

508508
// Delete the `local` row from the system table (control connection info)
@@ -538,8 +538,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionThreeNodeClusterTests,
538538
connect(); // Create the default session
539539
std::stringstream update_system_table;
540540
update_system_table
541-
<< "UPDATE system.peers SET rpc_address = null WHERE peer = '"
542-
<< ccm_->get_ip_prefix() << "3'";
541+
<< "UPDATE system.peers SET rpc_address = null WHERE peer = '"
542+
<< ccm_->get_ip_prefix() << "3'";
543543
for (int i = 0; i < 3; ++i) { // Ensure all the nodes in the cluster are updated
544544
session_.execute(update_system_table.str());
545545
}
@@ -550,8 +550,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionThreeNodeClusterTests,
550550
* node discovery
551551
*/
552552
Cluster cluster = default_cluster(false)
553-
.with_load_balance_round_robin()
554-
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
553+
.with_load_balance_round_robin()
554+
.with_contact_points(generate_contact_points(ccm_->get_ip_prefix(), 1));
555555
Session session = cluster.connect();
556556

557557
// Ensure nodes one and two are actively used
@@ -665,8 +665,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionFourNodeClusterTests,
665665

666666
// Create a cluster object using randomized contact points
667667
Cluster cluster = default_cluster()
668-
.with_load_balance_round_robin()
669-
.with_randomized_contact_points(true);
668+
.with_load_balance_round_robin()
669+
.with_randomized_contact_points(true);
670670

671671
// Establish a connect and ensure the first established host is not node 1
672672
Session session;
@@ -691,7 +691,7 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionFourNodeClusterTests,
691691

692692
// Ensure the next host is the expected host
693693
std::string current_host =
694-
session.execute(SELECT_ALL_SYSTEM_LOCAL_CQL).host();
694+
session.execute(SELECT_ALL_SYSTEM_LOCAL_CQL).host();
695695
ASSERT_STREQ(expected_host.str().c_str(), current_host.c_str());
696696
}
697697

@@ -723,7 +723,7 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionSingleNodeDataCentersClusterTests,
723723
* policy
724724
*/
725725
Cluster cluster = default_cluster()
726-
.with_load_balance_dc_aware("invalid_data_center", 0, false);
726+
.with_load_balance_dc_aware("invalid_data_center", 0, false);
727727
try {
728728
Session session = cluster.connect();
729729
FAIL() << "Connection was established using invalid data center";
@@ -766,8 +766,8 @@ CASSANDRA_INTEGRATION_TEST_F(ControlConnectionTests,
766766
std::stringstream expected_message;
767767
// Message to validate number of I/O worker threads
768768
expected_message << "Unable to connect to host " << ccm_->get_ip_prefix()
769-
<< "1 because of the following error: Received error response "
770-
<< "'Keyspace '" << inavlid_keyspace_name << "' does not exist'";
769+
<< "1 because of the following error: Received error response "
770+
<< "'Keyspace '" << inavlid_keyspace_name << "' does not exist'";
771771
logger_.add_critera(expected_message.str());
772772
// Message to validate connection/host is ready/up
773773
expected_message.str("");

cpp-driver/gtests/src/unit/event_loop_test.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class EventLoopTest : public Unit {
5555
* @return Generic future instance.
5656
*/
5757
cass::Future::Ptr execute_outage_plan(OutagePlan* outage_plan) {
58-
cass::Future::Ptr future(cass::Memory::allocate<cass::Future>(cass::Future::FUTURE_TYPE_GENERIC));
59-
add_task(cass::Memory::allocate<ExecuteOutagePlan>(outage_plan, future));
58+
cass::Future::Ptr future(new cass::Future(cass::Future::FUTURE_TYPE_GENERIC));
59+
add_task(new ExecuteOutagePlan(outage_plan, future));
6060
return future;
6161
}
6262

cpp-driver/gtests/src/unit/loop_test.hpp

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

2020
#include "unit.hpp"
2121
#include "test_utils.hpp"
22-
#include "memory.hpp"
2322

2423
#include <uv.h>
2524

@@ -61,7 +60,7 @@ class LoopTest : public Unit {
6160
*/
6261
void starve_thread_pool(unsigned int sleep_ms) {
6362
for (int i = 0; i < NUM_WORKERS; ++i) {
64-
workers[i].data = cass::Memory::allocate<unsigned int>(sleep_ms);
63+
workers[i].data = new unsigned int(sleep_ms);
6564
uv_queue_work(loop(), &workers[i], on_work, NULL);
6665
}
6766
}
@@ -70,7 +69,7 @@ class LoopTest : public Unit {
7069
static void on_work(uv_work_t* req) {
7170
unsigned int* sleep_ms = static_cast<unsigned int*>(req->data);
7271
test::Utils::msleep(*sleep_ms);
73-
cass::Memory::deallocate(sleep_ms);
72+
delete sleep_ms;
7473
}
7574

7675
private:

0 commit comments

Comments
 (0)