Skip to content

Commit 83ea604

Browse files
authored
Use strong value cache in PreparedStatementCachingIT (#525)
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.
1 parent de10f2f commit 83ea604

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.datastax.oss.driver.internal.core.session.BuiltInRequestProcessors;
4141
import com.datastax.oss.driver.internal.core.session.RequestProcessor;
4242
import com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry;
43+
import com.datastax.oss.driver.shaded.guava.common.cache.CacheBuilder;
4344
import com.datastax.oss.driver.shaded.guava.common.cache.RemovalListener;
4445
import com.datastax.oss.driver.shaded.guava.common.util.concurrent.Uninterruptibles;
4546
import com.google.common.collect.ImmutableList;
@@ -135,7 +136,9 @@ private static RemovalListener<Object, Object> buildCacheRemoveCallback(
135136
public TestCqlPrepareAsyncProcessor(@NonNull Optional<DefaultDriverContext> context) {
136137
// Default CqlPrepareAsyncProcessor uses weak values here as well. We avoid doing so
137138
// to prevent cache entries from unexpectedly disappearing mid-test.
138-
super(context, builder -> builder.removalListener(buildCacheRemoveCallback(context)));
139+
super(
140+
context,
141+
builder -> CacheBuilder.newBuilder().removalListener(buildCacheRemoveCallback(context)));
139142
}
140143
}
141144

@@ -267,14 +270,14 @@ private void invalidationTestInner(
267270
session.execute("ALTER TYPE test_type_2 add i blob");
268271

269272
// wait for latches and fail if they don't reach zero before timeout
273+
assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 10, TimeUnit.SECONDS))
274+
.withFailMessage("typeChangeEventLatch did not trigger before timeout")
275+
.isTrue();
270276
assertThat(
271277
Uninterruptibles.awaitUninterruptibly(
272278
preparedStmtCacheRemoveLatch, 10, TimeUnit.SECONDS))
273279
.withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
274280
.isTrue();
275-
assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 10, TimeUnit.SECONDS))
276-
.withFailMessage("typeChangeEventLatch did not trigger before timeout")
277-
.isTrue();
278281

279282
/* Okay, the latch triggered so cache processing should now be done. Let's validate :allthethings: */
280283
assertThat(changedTypes.keySet()).isEqualTo(expectedChangedTypes);

0 commit comments

Comments
 (0)