Skip to content

Commit ed59669

Browse files
committed
Occasionally force cache cleanup in PreparedStatementCachingIT
This integration test periodically fails on one of its methods. Evidence points to the cache itself being the culprit, as there is no guarantee that elements will be removed right away. This leads to removal event not being fired and timing out on wait for it. Calling `cache.cleanUp()` seems to greatly improve stability of this test. Fixes #476 and #477
1 parent d975001 commit ed59669

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java

+24-5
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,17 @@ private void invalidationTestInner(
267267
session.execute("ALTER TYPE test_type_2 add i blob");
268268

269269
// wait for latches and fail if they don't reach zero before timeout
270-
assertThat(
271-
Uninterruptibles.awaitUninterruptibly(
272-
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS))
273-
.withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
274-
.isTrue();
270+
if (!Uninterruptibles.awaitUninterruptibly(
271+
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS)) {
272+
// On rare occasions cache does not trigger removal shortly after alter.
273+
forceCacheCleanUp((DefaultDriverContext) session.getContext());
274+
assertThat(
275+
Uninterruptibles.awaitUninterruptibly(
276+
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS))
277+
.withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
278+
.isTrue();
279+
}
280+
275281
assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 10, TimeUnit.SECONDS))
276282
.withFailMessage("typeChangeEventLatch did not trigger before timeout")
277283
.isTrue();
@@ -426,4 +432,17 @@ private static long getPreparedCacheSize(CqlSession session) {
426432
"Could not access metric "
427433
+ DefaultSessionMetric.CQL_PREPARED_CACHE_SIZE.getPath()));
428434
}
435+
436+
private void forceCacheCleanUp(DefaultDriverContext context) {
437+
context
438+
.getRequestProcessorRegistry()
439+
.getProcessors()
440+
.forEach(requestProcessor -> {
441+
if (requestProcessor instanceof CqlPrepareAsyncProcessor) {
442+
((CqlPrepareAsyncProcessor) requestProcessor).getCache().cleanUp();
443+
} else if (requestProcessor instanceof CqlPrepareSyncProcessor) {
444+
((CqlPrepareSyncProcessor) requestProcessor).getCache().cleanUp();
445+
}
446+
});
447+
}
429448
}

0 commit comments

Comments
 (0)