This is an automated email from the ASF dual-hosted git repository.

huaxingao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 8b45abce03 Close metrics reporter in RESTSessionCatalog and add test 
in CatalogTests (#16310)
8b45abce03 is described below

commit 8b45abce036b480fbecd2427d4ae70fae0536640
Author: Talat UYARER <[email protected]>
AuthorDate: Thu May 14 16:57:07 2026 -0700

    Close metrics reporter in RESTSessionCatalog and add test in CatalogTests 
(#16310)
---
 .../java/org/apache/iceberg/rest/RESTSessionCatalog.java    |  1 +
 .../test/java/org/apache/iceberg/catalog/CatalogTests.java  | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java 
b/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
index ec30d9de89..9effb875e0 100644
--- a/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java
@@ -269,6 +269,7 @@ public class RESTSessionCatalog extends 
BaseViewSessionCatalog
                 .toUpperCase(Locale.US));
 
     this.reporter = CatalogUtil.loadMetricsReporter(mergedProps);
+    this.closeables.addCloseable(reporter);
 
     this.reportingViaRestEnabled =
         PropertyUtil.propertyAsBoolean(
diff --git a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java 
b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
index 8997cf15a0..6c6949ce42 100644
--- a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
@@ -24,6 +24,7 @@ import static 
org.assertj.core.api.Assertions.assertThatThrownBy;
 import static 
org.assertj.core.api.Assertions.setMaxStackTraceElementsDisplayed;
 import static org.assertj.core.api.Assumptions.assumeThat;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.net.URI;
@@ -3391,11 +3392,18 @@ public abstract class CatalogTests<C extends Catalog & 
SupportsNamespaces> {
     assertThat(CustomMetricsReporter.SCAN_COUNTER.get()).isEqualTo(1);
     // reset counter in case subclasses run this test multiple times
     CustomMetricsReporter.SCAN_COUNTER.set(0);
+
+    CustomMetricsReporter.CLOSE_COUNTER.set(0);
+    ((Closeable) catalogWithCustomReporter).close();
+    assertThat(CustomMetricsReporter.CLOSE_COUNTER.get())
+        .as("Catalog.close() must propagate to the configured MetricsReporter")
+        .isEqualTo(1);
   }
 
   public static class CustomMetricsReporter implements MetricsReporter {
     static final AtomicInteger SCAN_COUNTER = new AtomicInteger(0);
     static final AtomicInteger COMMIT_COUNTER = new AtomicInteger(0);
+    static final AtomicInteger CLOSE_COUNTER = new AtomicInteger(0);
 
     @Override
     public void report(MetricsReport report) {
@@ -3405,6 +3413,11 @@ public abstract class CatalogTests<C extends Catalog & 
SupportsNamespaces> {
         COMMIT_COUNTER.incrementAndGet();
       }
     }
+
+    @Override
+    public void close() {
+      CLOSE_COUNTER.incrementAndGet();
+    }
   }
 
   private static void assertEmpty(String context, Catalog catalog, Namespace 
ns) {

Reply via email to