diff --git a/core/src/test/java/io/aiven/kafka/tieredstorage/fetch/index/MemorySegmentIndexesCacheTest.java b/core/src/test/java/io/aiven/kafka/tieredstorage/fetch/index/MemorySegmentIndexesCacheTest.java index 83d4ee748..04751c18e 100644 --- a/core/src/test/java/io/aiven/kafka/tieredstorage/fetch/index/MemorySegmentIndexesCacheTest.java +++ b/core/src/test/java/io/aiven/kafka/tieredstorage/fetch/index/MemorySegmentIndexesCacheTest.java @@ -40,6 +40,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -211,11 +212,11 @@ void timeBasedEviction() throws IOException, StorageBackendException, Interrupte eq(RemovalCause.EXPIRED)); } - @Test + @RepeatedTest(10000) void sizeBasedEviction() throws IOException, StorageBackendException { cache.configure(Map.of( "size", "18", - "retention.ms", "-1" + "retention.ms", String.valueOf(Duration.ofSeconds(10).toMillis()) )); assertThat(cache.cache.asMap()).isEmpty(); @@ -253,13 +254,14 @@ void sizeBasedEviction() throws IOException, StorageBackendException { assertThat(timeIndex).hasBinaryContent(TIME_INDEX); assertThat(cache.cache.asMap()).isNotEmpty(); + // because of the retention ms, it may be deleting cached values 1, 2 or both. await() - .atMost(Duration.ofSeconds(30)) // increase to reduce chance of flakiness + .atMost(Duration.ofSeconds(30)) .pollDelay(Duration.ofSeconds(2)) .pollInterval(Duration.ofMillis(10)) .until(() -> !mockingDetails(removalListener).getInvocations().isEmpty()); - assertThat(cache.cache.asMap()).hasSize(1); + assertThat(cache.cache.asMap().size()).isLessThanOrEqualTo(1); verify(removalListener).onRemoval(any(SegmentIndexKey.class), any(), eq(RemovalCause.SIZE)); } }