|
13 | 13 | import com.datastax.oss.driver.api.testinfra.requirement.BackendType; |
14 | 14 | import com.datastax.oss.driver.api.testinfra.session.SessionUtils; |
15 | 15 | import com.datastax.oss.driver.categories.IsolatedTests; |
| 16 | +import com.datastax.oss.driver.internal.core.connection.ConstantReconnectionPolicy; |
16 | 17 | import com.datastax.oss.driver.shaded.guava.common.util.concurrent.Uninterruptibles; |
17 | 18 | import com.google.common.collect.ImmutableList; |
18 | 19 | import java.io.ByteArrayOutputStream; |
|
22 | 23 | import java.nio.file.Paths; |
23 | 24 | import java.security.KeyStore; |
24 | 25 | import java.security.SecureRandom; |
| 26 | +import java.time.Duration; |
25 | 27 | import java.util.List; |
26 | 28 | import java.util.Map; |
27 | 29 | import java.util.concurrent.TimeUnit; |
@@ -183,6 +185,65 @@ public void all_reconnections_should_use_tickets_with_TLSv13() throws Exception |
183 | 185 | reconnectionPsks); |
184 | 186 | } |
185 | 187 |
|
| 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 | + |
186 | 247 | private void healthCheck(CqlSession session) { |
187 | 248 | Awaitility.await() |
188 | 249 | .atMost(20, TimeUnit.SECONDS) |
|
0 commit comments