Skip to content

Commit d0c61a0

Browse files
committed
Add test method for connection throttling
Adds `all_reconnections_but_one_should_use_tickets_when_throttled_TLSv13` to `SessionTicketsIT`. This test checks whether throttling reconnections to a batch size of 1 helps with the session resumptions. Since the Java 11 cache can only store information for 1 session resumption this in theory should allow for resumptions to happen if the connections are established sequentially. The test relies on server to send NewSessionTicket messages in a timely manner.
1 parent 3c740e6 commit d0c61a0

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

integration-tests/src/test/java/com/datastax/oss/driver/core/ssl/SessionTicketsIT.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
1414
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
1515
import com.datastax.oss.driver.categories.IsolatedTests;
16+
import com.datastax.oss.driver.internal.core.connection.ConstantReconnectionPolicy;
1617
import com.datastax.oss.driver.shaded.guava.common.util.concurrent.Uninterruptibles;
1718
import com.google.common.collect.ImmutableList;
1819
import java.io.ByteArrayOutputStream;
@@ -22,6 +23,7 @@
2223
import java.nio.file.Paths;
2324
import java.security.KeyStore;
2425
import java.security.SecureRandom;
26+
import java.time.Duration;
2527
import java.util.List;
2628
import java.util.Map;
2729
import java.util.concurrent.TimeUnit;
@@ -183,6 +185,65 @@ public void all_reconnections_should_use_tickets_with_TLSv13() throws Exception
183185
reconnectionPsks);
184186
}
185187

188+
@Test
189+
public void all_reconnections_but_one_should_use_tickets_when_throttled_TLSv13()
190+
throws Exception {
191+
int initialResumptions, reconnectionResumptions;
192+
int initialHellos, reconnectionHellos;
193+
int initialPsks, reconnectionPsks;
194+
try {
195+
SSLContext context = createSslContext("TLSv1.3");
196+
try (DriverConfigLoader configLoader =
197+
SessionUtils.configLoaderBuilder()
198+
.withString(
199+
DefaultDriverOption.PROTOCOL_VERSION, DefaultProtocolVersion.V4.name())
200+
.withClass(
201+
DefaultDriverOption.RECONNECTION_POLICY_CLASS,
202+
ConstantReconnectionPolicy.class)
203+
.withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, Duration.ofSeconds(1))
204+
.withInt(DefaultDriverOption.CONNECTION_POOL_INIT_BATCH_SIZE, 1)
205+
.build();
206+
CqlSession session =
207+
(CqlSession)
208+
SessionUtils.baseBuilder()
209+
.addContactEndPoints(CCM_RULE.getContactPointsWithShardAwarePort())
210+
.withSslContext(context)
211+
.withConfigLoader(configLoader)
212+
.build()) {
213+
healthCheck(session);
214+
215+
// Perform a node restart to force all connections to be re-established
216+
initialResumptions = resumptions.get();
217+
initialHellos = serverHellos.get();
218+
initialPsks = pskUses.get();
219+
CCM_RULE.getCcmBridge().stop();
220+
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
221+
CCM_RULE.getCcmBridge().start();
222+
healthCheck(session);
223+
reconnectionResumptions = resumptions.get() - initialResumptions;
224+
reconnectionHellos = serverHellos.get() - initialHellos;
225+
reconnectionPsks = pskUses.get() - initialPsks;
226+
}
227+
} finally {
228+
handler.flush();
229+
}
230+
231+
Assert.assertEquals(
232+
"Each connection should have negotiated TLSv1.3.",
233+
serverHellos.get(),
234+
negotiatedTls13.get());
235+
Assert.assertTrue("Client should have received some tickets.", ticketsReceived.get() > 0);
236+
Assert.assertTrue(
237+
String.format(
238+
"Each reconnection but first should be a resumption. Meanwhile found %s ServerHellos and %s resumptions.",
239+
reconnectionHellos, reconnectionResumptions),
240+
reconnectionResumptions >= reconnectionHellos - 1);
241+
Assert.assertEquals(
242+
"PSK should have been used for each resumption on reconnection.",
243+
reconnectionResumptions,
244+
reconnectionPsks);
245+
}
246+
186247
private void healthCheck(CqlSession session) {
187248
Awaitility.await()
188249
.atMost(20, TimeUnit.SECONDS)

0 commit comments

Comments
 (0)