Skip to content

Commit f70522d

Browse files
committed
IT: introduce test that checks connection count if configured per-shard
This tests `cass_cluster_set_core_connections_per_shard` as well as `cass_session_get_metrics`.
1 parent 7ccded3 commit f70522d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SCYLLA_TEST_FILTER := $(subst ${SPACE},${EMPTY},ClusterTests.*\
2727
:UseKeyspaceCaseSensitiveTests.*\
2828
:MetricsTests.Integration_Cassandra_ErrorsRequestTimeouts\
2929
:MetricsTests.Integration_Cassandra_Requests\
30+
:MetricsTests.Integration_Cassandra_StatsShardConnections\
3031
:-PreparedTests.Integration_Cassandra_PreparedIDUnchangedDuringReprepare\
3132
:HeartbeatTests.Integration_Cassandra_HeartbeatFailed\
3233
:ControlConnectionTests.Integration_Cassandra_TopologyChange\
@@ -68,6 +69,7 @@ CASSANDRA_TEST_FILTER := $(subst ${SPACE},${EMPTY},ClusterTests.*\
6869
:UseKeyspaceCaseSensitiveTests.*\
6970
:MetricsTests.Integration_Cassandra_ErrorsRequestTimeouts\
7071
:MetricsTests.Integration_Cassandra_Requests\
72+
:MetricsTests.Integration_Cassandra_StatsShardConnections\
7173
:-PreparedTests.Integration_Cassandra_PreparedIDUnchangedDuringReprepare\
7274
:PreparedTests.Integration_Cassandra_FailFastWhenPreparedIDChangesDuringReprepare\
7375
:HeartbeatTests.Integration_Cassandra_HeartbeatFailed\

tests/src/integration/objects/cluster.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ class Cluster : public Object<CassCluster, cass_cluster_free> {
170170
return *this;
171171
}
172172

173+
/**
174+
* Assign the number of connections made to each shard
175+
*
176+
* NOTE: One extra connection is established (the control connection)
177+
*
178+
* @param connections Number of connection per shard (default: 1)
179+
* @return Cluster object
180+
*/
181+
Cluster& with_core_connections_per_shard(unsigned int connections = 1u) {
182+
EXPECT_EQ(CASS_OK, cass_cluster_set_core_connections_per_shard(get(), connections));
183+
return *this;
184+
}
185+
173186
/**
174187
* Sets credentials for plain text authentication
175188
*

tests/src/integration/tests/test_metrics.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ CASSANDRA_INTEGRATION_TEST_F(MetricsTests, ErrorsConnectionTimeouts) {
7676
EXPECT_GE(2u, metrics.errors.connection_timeouts);
7777
}
7878

79+
/**
80+
* This test ensures that the driver is reporting the number of connections
81+
* when connection pool size is configured per shard.
82+
*/
83+
CASSANDRA_INTEGRATION_TEST_F(MetricsTests, StatsShardConnections) {
84+
CHECK_FAILURE;
85+
86+
const unsigned int CONNS_PER_SHARD = 2;
87+
88+
Session session =
89+
default_cluster().with_core_connections_per_shard(CONNS_PER_SHARD).connect();
90+
91+
size_t nr_hosts = explode(contact_points_, ',').size();
92+
size_t nr_shards = Options::is_scylla() ? Options::smp() : 1;
93+
size_t expected_connection_count = nr_hosts * nr_shards * CONNS_PER_SHARD;
94+
95+
CassMetrics metrics = session.metrics();
96+
for (int i = 0; i < 100 && metrics.stats.total_connections < expected_connection_count; ++i) {
97+
metrics = session.metrics();
98+
msleep(100);
99+
}
100+
101+
EXPECT_GE(metrics.stats.total_connections, expected_connection_count);
102+
}
103+
79104
/**
80105
* This test ensures that the driver is reporting the proper timeouts for requests
81106
*

0 commit comments

Comments
 (0)