youngyjd commented on code in PR #8871:
URL: https://github.com/apache/gravitino/pull/8871#discussion_r2450313676


##########
core/src/test/java/org/apache/gravitino/cache/TestCacheConfig.java:
##########
@@ -152,22 +152,31 @@ void testPolicyAndTagCacheWeigher() throws 
InterruptedException {
           List.of(fileset));
     }
 
-    Thread.sleep(1000);
+    // Access all filesets to make them more likely to be retained
+    for (int i = 5; i < 15; i++) {
+      String filesetName = "fileset" + i;
+      cache.getIfPresent(
+          EntityCacheRelationKey.of(
+              NameIdentifier.of(new String[] {"metalake1", "catalog1", 
"schema1", filesetName}),
+              Entity.EntityType.FILESET));
+    }
 
-    // There should no tag entities in the cache, because the weight of each 
tag entity is 100 that
-    // is higher than the maximum weight of the fileset entity which is 200.
-    Awaitility.await()
-        .atMost(Duration.ofSeconds(10))
-        .pollInterval(Duration.ofMillis(10))
-        .until(
-            () ->
-                IntStream.of(0, 1, 2, 3)
-                    .mapToObj(i -> NameIdentifierUtil.ofTag("metalake", "tag" 
+ i))
-                    .allMatch(
-                        tagNameIdent ->
-                            cache.getIfPresent(
-                                    EntityCacheRelationKey.of(tagNameIdent, 
Entity.EntityType.TAG))
-                                == null));
+    cache.cleanUp(); // Force synchronous eviction
+
+    // Count how many tags are still in cache - expect some to be evicted
+    long remainingTags =
+        IntStream.range(0, 10)
+            .mapToObj(i -> NameIdentifierUtil.ofTag("metalake", "tag" + i))
+            .filter(
+                tagNameIdent ->
+                    cache.getIfPresent(
+                            EntityCacheRelationKey.of(tagNameIdent, 
Entity.EntityType.TAG))
+                        != null)
+            .count();
+
+    Assertions.assertTrue(
+        remainingTags < 10,
+        "Expected some tags to be evicted, but found " + remainingTags + " 
tags still in cache");

Review Comment:
   @yuqi1129 it's non deterministic. It seems you cannot simply rely on weight 
to control which cache gets evicted first. If you want a guarantee that lower 
weight cache gets evicted first, likely you will need a new solution.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to