From 154b4afddf440c596bead00ba69c33f7084a20a9 Mon Sep 17 00:00:00 2001 From: Talat Uyarer Date: Wed, 13 May 2026 16:23:35 -0700 Subject: [PATCH] Close metrics reporter in RESTSessionCatalog and add test in CatalogTests --- .../org/apache/iceberg/rest/RESTSessionCatalog.java | 1 + .../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 3f3626589566..5dc1f3320a8e 100644 --- a/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java +++ b/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java @@ -260,6 +260,7 @@ public void initialize(String name, Map unresolved) { .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 5d20bc15a9c1..8668cf2a76f2 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.setMaxStackTraceElementsDisplayed; import static org.assertj.core.api.Assumptions.assumeThat; +import java.io.Closeable; import java.io.IOException; import java.io.UncheckedIOException; import java.util.Arrays; @@ -3233,11 +3234,18 @@ public void testCatalogWithCustomMetricsReporter() throws IOException { 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) { @@ -3247,6 +3255,11 @@ public void report(MetricsReport report) { COMMIT_COUNTER.incrementAndGet(); } } + + @Override + public void close() { + CLOSE_COUNTER.incrementAndGet(); + } } private static void assertEmpty(String context, Catalog catalog, Namespace ns) {