From 4ecdfb713f2055b8bef8022df91814615557aa63 Mon Sep 17 00:00:00 2001 From: Jorge Esteban Quilcate Otoya Date: Thu, 8 Aug 2024 20:42:25 +0300 Subject: [PATCH] fix: add retention-based eviction to memory-based cache metrics test Similar to disk-based test, as deletion is not happening consistently leading to flakiness, this commit includes time-based retention to force deletion and validate metrics. --- .../fetch/index/MemorySegmentIndexesCacheTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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)); } }