diff --git a/rls/src/test/java/io/grpc/rls/LinkedHashLruCacheTest.java b/rls/src/test/java/io/grpc/rls/LinkedHashLruCacheTest.java index f38b28d8416..e06661120cf 100644 --- a/rls/src/test/java/io/grpc/rls/LinkedHashLruCacheTest.java +++ b/rls/src/test/java/io/grpc/rls/LinkedHashLruCacheTest.java @@ -119,7 +119,6 @@ public void eviction_explicit() { cache.cache(1, survivor); assertThat(cache.invalidate(0)).isEqualTo(toBeEvicted); - verify(evictionListener).onEviction(0, toBeEvicted, EvictionType.EXPLICIT); } @@ -143,7 +142,7 @@ public void eviction_size_shouldEvictAlreadyExpired() { // should remove MAX_SIZE-1 instead of MAX_SIZE because MAX_SIZE is accessed later verify(evictionListener) - .onEviction(eq(MAX_SIZE - 1), any(Entry.class), eq(EvictionType.EXPIRED)); + .onEviction(eq(MAX_SIZE - 1), any(Entry.class), eq(EvictionType.EXPIRED)); assertThat(cache.estimatedSize()).isEqualTo(MAX_SIZE); } @@ -266,4 +265,43 @@ public int hashCode() { return Objects.hash(value, expireTime); } } + + @Test + public void testFitToLimitUsingReSize() { + + Entry entry1 = new Entry("Entry1", ticker.read() + 10,4); + Entry entry2 = new Entry("Entry2", ticker.read() + 20,2); + Entry entry3 = new Entry("Entry3", ticker.read() + 30,1); + + cache.cache(1, entry1); + cache.cache(2, entry2); + cache.cache(3, entry3); + + assertThat(cache.estimatedSize()).isEqualTo(2); + cache.resize(1); + + assertThat(cache.estimatedMaxSizeBytes()).isEqualTo(1); + assertThat(cache.fitToLimit()).isEqualTo(false); + assertThat(cache.estimatedSizeBytes()).isEqualTo(1); + } + + @Test + public void testFitToLimitWithEntry() { + Entry entry1 = new Entry("Entry1", ticker.read() + 10,4); + Entry entry2 = new Entry("Entry2", ticker.read() + 20,2); + Entry entry3 = new Entry("Entry3", ticker.read() + 30,1); + Entry entry4 = new Entry("Entry4", ticker.read() + 20,2); + + cache.cache(1, entry1); + cache.cache(2, entry2); + cache.cache(3, entry3); + + assertThat(cache.estimatedSize()).isEqualTo(2); + cache.cache(4, entry4); + + assertThat(cache.estimatedSize()).isEqualTo(3); + assertThat(cache.estimatedMaxSizeBytes()).isEqualTo(5); + assertThat(cache.fitToLimit()).isEqualTo(false); + assertThat(cache.estimatedSizeBytes()).isEqualTo(5); + } }