Skip to content

Commit dc72d73

Browse files
committed
feat: Add test for max capacity in InMemoryCache implementation
1 parent b1a617f commit dc72d73

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

connector/src/test/java/com/datastax/oss/cdc/MutationCacheTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,32 @@ public final void testExpireAfter() throws Exception {
5656
assertFalse(mutationCache.isMutationProcessed("mutation1", "digest1"));
5757
}
5858

59+
@Test
60+
public final void testMaxCapacity() throws Exception {
61+
MutationCache<String> mutationCache = new InMemoryCache<>(3, 10, Duration.ofHours(1));
62+
63+
// Access and modify the private field using reflection
64+
Field field = InMemoryCache.class.getDeclaredField("mutationCache");
65+
field.setAccessible(true);
66+
field.set(mutationCache, Caffeine.newBuilder()
67+
.expireAfterWrite(Duration.ofHours(1).getSeconds(), TimeUnit.SECONDS)
68+
.maximumSize(10)
69+
.recordStats()
70+
.executor(Runnable::run) // https://github.com/ben-manes/caffeine/wiki/Testing
71+
.build()
72+
);
73+
74+
for (int i = 0; i <20; i++) {
75+
mutationCache.addMutationMd5("mutation" + i, "digest" + i);
76+
}
77+
78+
int count = 0;
79+
for (int i = 0; i < 20; i++) {
80+
if(mutationCache.getMutationCRCs("mutation" + i) != null) {
81+
count++;
82+
}
83+
}
84+
assertEquals(10, count);
85+
}
86+
5987
}

0 commit comments

Comments
 (0)