openinx commented on code in PR #14440:
URL: https://github.com/apache/iceberg/pull/14440#discussion_r4542126181


##########
core/src/test/java/org/apache/iceberg/hadoop/TestCachingCatalog.java:
##########
@@ -436,6 +464,49 @@ public void 
testRegisterTableWithOverwriteInvalidatesCache() throws Exception {
     assertThat(catalog.cache().asMap()).doesNotContainKey(targetIdent);
   }
 
+  @Test
+  public void testCachePolicyExpireAfterWrite() throws Exception {
+    Duration expireAfterWriteInterval = Duration.ofMinutes(3);
+    TestableCachingCatalog catalog =
+        TestableCachingCatalog.wrap(
+            hadoopCatalog(), EXPIRATION_TTL, expireAfterWriteInterval, ticker);
+
+    Namespace namespace = Namespace.of("db", "ns1", "ns2");
+    TableIdentifier tableIdent = TableIdentifier.of(namespace, "tbl");
+    catalog.createTable(tableIdent, SCHEMA, SPEC, ImmutableMap.of("key", 
"value"));
+
+    // Ensure table is cached with full ttl remaining upon creation
+    assertThat(catalog.cache().asMap()).containsKey(tableIdent);
+    
assertThat(catalog.remainingAgeFor(tableIdent)).isPresent().get().isEqualTo(EXPIRATION_TTL);
+    assertThat(catalog.cache().policy().expireAfterWrite().flatMap(t -> 
t.ageOf(tableIdent)))
+        .isPresent()
+        .get()
+        .isEqualTo(Duration.ZERO);
+
+    ticker.advance(HALF_OF_EXPIRATION);
+    assertThat(catalog.cache().asMap()).containsKey(tableIdent);
+    
assertThat(catalog.ageOf(tableIdent)).isPresent().get().isEqualTo(HALF_OF_EXPIRATION);
+    assertThat(catalog.cache().policy().expireAfterWrite().flatMap(t -> 
t.ageOf(tableIdent)))
+        .isPresent()
+        .get()
+        .isEqualTo(HALF_OF_EXPIRATION);
+
+    // Access the cache to check policy behaviour
+    catalog.loadTable(tableIdent);
+
+    //  Object age does not change after access
+    
assertThat(catalog.cache().policy().expireAfterWrite().get().ageOf(tableIdent))
+        .isPresent()
+        .get()
+        .isEqualTo(HALF_OF_EXPIRATION);
+
+    ticker.advance(HALF_OF_EXPIRATION.plus(Duration.ofMinutes(1)));
+    assertThat(catalog.cache().asMap()).doesNotContainKey(tableIdent);
+    assertThat(catalog.loadTable(tableIdent))
+        .as("CachingCatalog should return a new instance after expiration")
+        .isNotSameAs(table);

Review Comment:
   nit: Capture the `Table` returned by `catalog.createTable(...)` above and 
compare the reload with that instance. `table` here resolves to 
`HadoopTableTestBase.table`, which is a different fixture table, so this 
assertion does not verify that the cached instance was replaced. The preceding 
cache-removal assertion still exercises write expiration.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to