|
72 | 72 | @Category(IsolatedTests.class)
|
73 | 73 | public class PreparedStatementCachingIT {
|
74 | 74 |
|
| 75 | + private static final Logger LOG = LoggerFactory.getLogger(PreparedStatementCachingIT.class); |
| 76 | + |
75 | 77 | private CustomCcmRule ccmRule = CustomCcmRule.builder().build();
|
76 | 78 |
|
77 | 79 | private SessionRule<CqlSession> sessionRule =
|
@@ -266,15 +268,46 @@ private void invalidationTestInner(
|
266 | 268 | // alter test_type_caching_2 to trigger cache invalidation and above events
|
267 | 269 | session.execute("ALTER TYPE test_type_caching_2 add i blob");
|
268 | 270 |
|
| 271 | + // Give a small delay to allow the schema change to propagate before checking agreement |
| 272 | + Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); |
269 | 273 | session.checkSchemaAgreement();
|
270 | 274 |
|
271 | 275 | // wait for latches and fail if they don't reach zero before timeout
|
272 |
| - assertThat( |
273 |
| - Uninterruptibles.awaitUninterruptibly( |
274 |
| - preparedStmtCacheRemoveLatch, 120, TimeUnit.SECONDS)) |
| 276 | + // Use longer timeout for cache removal as it depends on complex event chain |
| 277 | + boolean cacheRemovalSuccess = |
| 278 | + Uninterruptibles.awaitUninterruptibly( |
| 279 | + preparedStmtCacheRemoveLatch, 180, TimeUnit.SECONDS); |
| 280 | + boolean typeChangeSuccess = |
| 281 | + Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 60, TimeUnit.SECONDS); |
| 282 | + |
| 283 | + // Provide detailed diagnostics if either latch fails |
| 284 | + if (!cacheRemovalSuccess || !typeChangeSuccess) { |
| 285 | + String diagnostics = |
| 286 | + String.format( |
| 287 | + "Test failure diagnostics:\n" |
| 288 | + + " - Cache removal latch success: %s (count: %d)\n" |
| 289 | + + " - Type change latch success: %s (count: %d)\n" |
| 290 | + + " - Current cache size: %d\n" |
| 291 | + + " - Changed types detected: %s\n" |
| 292 | + + " - Removed query IDs: %s\n" |
| 293 | + + " - Type change errors: %s\n" |
| 294 | + + " - Removal event errors: %s", |
| 295 | + cacheRemovalSuccess, |
| 296 | + preparedStmtCacheRemoveLatch.getCount(), |
| 297 | + typeChangeSuccess, |
| 298 | + typeChangeEventLatch.getCount(), |
| 299 | + getPreparedCacheSize(session), |
| 300 | + changedTypes.keySet(), |
| 301 | + removedQueryIds.get(), |
| 302 | + typeChangeEventError.get(), |
| 303 | + removedQueryEventError.get()); |
| 304 | + LOG.error("Prepared statement cache invalidation test failed: {}", diagnostics); |
| 305 | + } |
| 306 | + |
| 307 | + assertThat(cacheRemovalSuccess) |
275 | 308 | .withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
|
276 | 309 | .isTrue();
|
277 |
| - assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 20, TimeUnit.SECONDS)) |
| 310 | + assertThat(typeChangeSuccess) |
278 | 311 | .withFailMessage("typeChangeEventLatch did not trigger before timeout")
|
279 | 312 | .isTrue();
|
280 | 313 |
|
|
0 commit comments