From fe797ea2635ab209210d92647d13db5fc77f33d8 Mon Sep 17 00:00:00 2001 From: Sanjay Dutt Date: Fri, 23 Oct 2026 19:39:06 +0530 Subject: [PATCH] Assert eviction count, not victim, in cache testSimple TestCaffeineCache.testSimple and TestThinCache.testSimple asserted that key 1 is evicted after 101 puts into a cache of size 100. Which entry is evicted is up to Caffeine's eviction policy, not insertion order, and it changed in Caffeine 3.3.0: both tests now fail on every branch_9x run. Assert that exactly one entry was evicted instead, and drop the get(1) lookup from the cumulative lookup count. TestThinCache also warms the second cache into the shared backing cache while it is still full. On Caffeine 3.3.0 the warmed entries lose to the existing ones and are evicted, so enlarge the backing before warming (the same change as SOLR-18506 / #5029). --- .../test/org/apache/solr/search/TestCaffeineCache.java | 8 +++++--- .../src/test/org/apache/solr/search/TestThinCache.java | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java b/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java index ec951df04398..4ff90efce165 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java +++ b/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java @@ -93,7 +93,9 @@ public void testSimple() throws IOException { assertEquals(3.0, hitDatapoint + missDatapoint, 0.001); // total lookups assertEquals(2.0, hitDatapoint, 0.001); assertEquals(101.0, insertDatapoint, 0.001); - assertNull(lfuCache.get(1)); + // Exactly one entry is evicted; which one is up to Caffeine's eviction policy. + assertEquals(100, lfuCache.size()); + assertEquals(1.0, evictionsDatapoint, 0.001); // Test autowarming newLFUCache.init(params, initObj, regenerator); @@ -115,11 +117,11 @@ public void testSimple() throws IOException { var newInsertDatapoint = cumInsertDatapoint - insertDatapoint; var newEvictionDatapoint = cumEvictionsDatapoint - evictionsDatapoint; assertEquals(3.0, newHitDatapoint + missDatapoint, 0.001); // total lookups - assertEquals(2.0, newMissDatapoint, 0.001); + assertEquals(1.0, newMissDatapoint, 0.001); assertEquals(1.0, newInsertDatapoint, 0.001); assertEquals(0.0, newEvictionDatapoint, 0.001); - assertEquals(7.0, cumHitDatapoint + cumMissDatapoint, 0.001); // total cumulative lookups + assertEquals(6.0, cumHitDatapoint + cumMissDatapoint, 0.001); // total cumulative lookups assertEquals(4.0, cumHitDatapoint, 0.001); assertEquals(102.0, cumInsertDatapoint, 0.001); diff --git a/solr/core/src/test/org/apache/solr/search/TestThinCache.java b/solr/core/src/test/org/apache/solr/search/TestThinCache.java index 7d668a8e9ed5..79dfe8520588 100644 --- a/solr/core/src/test/org/apache/solr/search/TestThinCache.java +++ b/solr/core/src/test/org/apache/solr/search/TestThinCache.java @@ -148,7 +148,12 @@ public void testSimple() throws IOException { assertEquals(2L, hits); assertEquals(101L, inserts); - assertNull(lfuCache.get(1)); // first item put in should be the first out + // Exactly one entry is evicted; which one is up to Caffeine's eviction policy. + // lfuCache isn't registered for removals here, so check the backing cache's size. + assertEquals(100, backing.size()); + + // The backing is full; make room so warming doesn't evict the new cache's own entries. + backing.setMaxSize(200); // Test autowarming newLFUCache.init(Map.of("autowarmCount", "25"), initObj, regenerator); @@ -164,7 +169,7 @@ public void testSimple() throws IOException { var newmiss = getNodeCacheLookups(metricManager, registry, newLfuCacheName, "miss"); var newinserts = getNodeCacheOp(metricManager, registry, newLfuCacheName, "inserts"); var evictions = getNodeCacheOp(metricManager, registry, newLfuCacheName, "evictions"); - assertEquals(7L, newhits + newmiss); + assertEquals(6L, newhits + newmiss); assertEquals(4L, newhits); assertEquals(102L, newinserts); assertEquals(0L, evictions);