Skip to content

4.x: Occasionally force cache cleanup in PreparedStatementCachingIT #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,17 @@ private void invalidationTestInner(
session.execute("ALTER TYPE test_type_2 add i blob");

// wait for latches and fail if they don't reach zero before timeout
assertThat(
Uninterruptibles.awaitUninterruptibly(
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS))
.withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
.isTrue();
if (!Uninterruptibles.awaitUninterruptibly(
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS)) {
// On rare occasions cache does not trigger removal shortly after alter.
forceCacheCleanUp((DefaultDriverContext) session.getContext());
assertThat(
Uninterruptibles.awaitUninterruptibly(
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS))
.withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
.isTrue();
}

assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 10, TimeUnit.SECONDS))
.withFailMessage("typeChangeEventLatch did not trigger before timeout")
.isTrue();
Expand Down Expand Up @@ -426,4 +432,18 @@ private static long getPreparedCacheSize(CqlSession session) {
"Could not access metric "
+ DefaultSessionMetric.CQL_PREPARED_CACHE_SIZE.getPath()));
}

private void forceCacheCleanUp(DefaultDriverContext context) {
context
.getRequestProcessorRegistry()
.getProcessors()
.forEach(
requestProcessor -> {
if (requestProcessor instanceof CqlPrepareAsyncProcessor) {
((CqlPrepareAsyncProcessor) requestProcessor).getCache().cleanUp();
} else if (requestProcessor instanceof CqlPrepareSyncProcessor) {
((CqlPrepareSyncProcessor) requestProcessor).getCache().cleanUp();
}
});
}
}
Loading