From a3e902c863b1a713c4a6e1e910441aba8545ee03 Mon Sep 17 00:00:00 2001 From: Bouncheck <36934780+Bouncheck@users.noreply.github.com> Date: Fri, 18 Apr 2025 18:56:42 +0200 Subject: [PATCH] Use strong value cache in PreparedStatementCachingIT Previously this test was using strong values in cache to prevent them from disappearing mid-test. Code comments explicitly say so. However at some point with the change to using a decorator for CqlPrepareAsyncProcessor it seems that the test was accidentally changed to use weak values. This change makes the test use a decorator which ignores CacheBuilder passed to it and replaces it with brand new instance that has not yet called `.weakValues()`. Additionally assertion related to preparedStmtCacheRemoveLatch is moved after typeChangeEventLatch since it looks like the latter triggers the former. This part is mainly cosmetic. --- .../driver/core/cql/PreparedStatementCachingIT.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java b/integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java index 617d489fb95..83163cfedfb 100644 --- a/integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java +++ b/integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java @@ -40,6 +40,7 @@ import com.datastax.oss.driver.internal.core.session.BuiltInRequestProcessors; import com.datastax.oss.driver.internal.core.session.RequestProcessor; import com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry; +import com.datastax.oss.driver.shaded.guava.common.cache.CacheBuilder; import com.datastax.oss.driver.shaded.guava.common.cache.RemovalListener; import com.datastax.oss.driver.shaded.guava.common.util.concurrent.Uninterruptibles; import com.google.common.collect.ImmutableList; @@ -135,7 +136,9 @@ private static RemovalListener buildCacheRemoveCallback( public TestCqlPrepareAsyncProcessor(@NonNull Optional context) { // Default CqlPrepareAsyncProcessor uses weak values here as well. We avoid doing so // to prevent cache entries from unexpectedly disappearing mid-test. - super(context, builder -> builder.removalListener(buildCacheRemoveCallback(context))); + super( + context, + builder -> CacheBuilder.newBuilder().removalListener(buildCacheRemoveCallback(context))); } } @@ -267,14 +270,14 @@ 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(typeChangeEventLatch, 10, TimeUnit.SECONDS)) + .withFailMessage("typeChangeEventLatch did not trigger before timeout") + .isTrue(); 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(); /* Okay, the latch triggered so cache processing should now be done. Let's validate :allthethings: */ assertThat(changedTypes.keySet()).isEqualTo(expectedChangedTypes);