|
22 | 22 | #include "test_utils.hpp"
|
23 | 23 | #include "cluster.hpp"
|
24 | 24 |
|
| 25 | +#include <uv.h> |
| 26 | + |
25 | 27 | #include <boost/scoped_ptr.hpp>
|
26 | 28 | #include <boost/test/unit_test.hpp>
|
27 | 29 |
|
@@ -125,4 +127,53 @@ BOOST_AUTO_TEST_CASE(connection_spawn)
|
125 | 127 | }
|
126 | 128 | BOOST_CHECK_EQUAL(test_utils::CassLog::message_count(), 2u);
|
127 | 129 | }
|
| 130 | + |
| 131 | +/** |
| 132 | + * Create connection interruptions using CCM for four seconds on node 2 |
| 133 | + * |
| 134 | + * @param ccm CCM bridge pointer |
| 135 | + */ |
| 136 | +static void connection_interruptions(void *ccm) { |
| 137 | + boost::posix_time::ptime start = boost::posix_time::second_clock::universal_time(); |
| 138 | + while ((boost::posix_time::second_clock::universal_time() - start).total_seconds() < 4) { |
| 139 | + cql::cql_ccm_bridge_t* ccm_ptr = static_cast<cql::cql_ccm_bridge_t*>(ccm); |
| 140 | + ccm_ptr->pause(2); |
| 141 | + ccm_ptr->resume(2); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +/** |
| 146 | + * Don't Recycle Pool On Connection Timeout |
| 147 | + * |
| 148 | + * This test ensures that a pool does not completely remove itself while |
| 149 | + * allowing partial connections to remain and reconnection attempts to use the |
| 150 | + * existing pool. |
| 151 | + * |
| 152 | + * @since 2.1.0 |
| 153 | + * @test_category connection:connection_pool |
| 154 | + * @jira_ticket CPP-253 [https://datastax-oss.atlassian.net/browse/CPP-253] |
| 155 | + */ |
| 156 | +BOOST_AUTO_TEST_CASE(dont_recycle_pool_on_timeout) { |
| 157 | + ccm->bootstrap(2); |
| 158 | + test_utils::CassLog::reset("Host " + conf.ip_prefix() + "2 already present attempting to initiate immediate connection"); |
| 159 | + |
| 160 | + // Create session during "connection interruptions" |
| 161 | + cass_cluster_set_connect_timeout(cluster, 1000); |
| 162 | + cass_cluster_set_num_threads_io(cluster, 16); |
| 163 | + cass_cluster_set_core_connections_per_host(cluster, 2); |
| 164 | + cass_cluster_set_load_balance_round_robin(cluster); |
| 165 | + uv_thread_t connection_interruptions_thread; |
| 166 | + uv_thread_create(&connection_interruptions_thread, connection_interruptions, ccm.get()); |
| 167 | + test_utils::CassSessionPtr session(test_utils::create_session(cluster)); |
| 168 | + uv_thread_join(&connection_interruptions_thread); |
| 169 | + |
| 170 | + boost::posix_time::ptime start = boost::posix_time::second_clock::universal_time(); |
| 171 | + while ((boost::posix_time::second_clock::universal_time() - start).total_seconds() < 60) { |
| 172 | + test_utils::CassStatementPtr statement(cass_statement_new("SELECT * FROM system.local", 0)); |
| 173 | + test_utils::CassFuturePtr(cass_session_execute(session.get(), statement.get())); |
| 174 | + } |
| 175 | + |
| 176 | + BOOST_CHECK_GE(test_utils::CassLog::message_count(), 1); |
| 177 | +} |
| 178 | + |
128 | 179 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments