nastra commented on code in PR #8844:
URL: https://github.com/apache/iceberg/pull/8844#discussion_r1360588962


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestCachingCatalogExpirationAfterWrite.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.extensions;
+
+import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.hive.HiveClientPool;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runners.Parameterized;
+import org.mockito.Mockito;
+
+public class TestCachingCatalogExpirationAfterWrite extends 
SparkExtensionsTestBase {
+  private static HiveClientPool clients;
+
+  @Parameterized.Parameters(name = "catalogName = {0}, implementation = {1}, 
config = {2}")
+  public static Object[][] parameters() {
+    return new Object[][] {
+      {
+        "iceberg",
+        SparkCatalog.class.getName(),
+        ImmutableMap.of(
+            "type", "hive",
+            "default-namespace", "default",
+            "parquet-enabled", "true",
+            "cache-enabled", "true",
+            "cache.expiration-interval-ms", "5000")
+      }
+    };
+  }
+
+  public TestCachingCatalogExpirationAfterWrite(
+      String catalogName, String implementation, Map<String, String> config) {
+    super(catalogName, implementation, config);
+  }
+
+  @BeforeClass
+  public static void start() {
+    HiveClientPool clientPool = new HiveClientPool(2, new Configuration());
+    clients = Mockito.spy(clientPool);
+  }
+
+  @After
+  public void removeTable() {
+    sql("DROP TABLE IF EXISTS iceberg.default.foo");
+  }
+
+  @Test(timeout = 60000)
+  public void testExpireCacheAfterWrite() throws Exception {
+    sql("create table iceberg.default.foo(x int) using iceberg");
+    clients.run(
+        client -> {
+          client.dropTable("default", "foo");
+          return null;
+        });
+    SparkCatalog sparkCatalog =
+        (SparkCatalog) 
spark.sessionState().catalogManager().catalog(catalogName);
+    while (sparkCatalog.tableExists(Identifier.of(new String[] {"default"}, 
"foo"))) {
+      Thread.sleep(1000);

Review Comment:
   I think it's better to use Awaitility here, because we don't want to use 
sleeps and potentially have a long running (60 seconds) test:
   
   ```
   @BeforeClass
     public static void start() {
       clients = new HiveClientPool(2, new Configuration());
     }
   
     @AfterClass
     public static void stop() {
       if (null != clients) {
         clients.close();
       }
     }
   
     @After
     public void removeTable() {
       sql("DROP TABLE IF EXISTS iceberg.default.foo");
     }
   
     @Test
     public void testExpireCacheAfterWrite() throws Exception {
       sql("create table iceberg.default.foo(x int) using iceberg");
       clients.run(
           client -> {
             client.dropTable("default", "foo");
             return null;
           });
   
       SparkCatalog sparkCatalog =
           (SparkCatalog) 
spark.sessionState().catalogManager().catalog(catalogName);
   
       Awaitility.await("wait for table to be removed from cache")
           .atMost(3, TimeUnit.SECONDS)
           .until(() -> !sparkCatalog.tableExists(Identifier.of(new String[] 
{"default"}, "foo")));
     }
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to