Skip to content

Commit 8b45abc

Browse files
authored
Close metrics reporter in RESTSessionCatalog and add test in CatalogTests (#16310)
1 parent 22f8666 commit 8b45abc

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ public void initialize(String name, Map<String, String> unresolved) {
269269
.toUpperCase(Locale.US));
270270

271271
this.reporter = CatalogUtil.loadMetricsReporter(mergedProps);
272+
this.closeables.addCloseable(reporter);
272273

273274
this.reportingViaRestEnabled =
274275
PropertyUtil.propertyAsBoolean(

core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.assertj.core.api.Assertions.setMaxStackTraceElementsDisplayed;
2525
import static org.assertj.core.api.Assumptions.assumeThat;
2626

27+
import java.io.Closeable;
2728
import java.io.IOException;
2829
import java.io.UncheckedIOException;
2930
import java.net.URI;
@@ -3391,11 +3392,18 @@ public void testCatalogWithCustomMetricsReporter() throws IOException {
33913392
assertThat(CustomMetricsReporter.SCAN_COUNTER.get()).isEqualTo(1);
33923393
// reset counter in case subclasses run this test multiple times
33933394
CustomMetricsReporter.SCAN_COUNTER.set(0);
3395+
3396+
CustomMetricsReporter.CLOSE_COUNTER.set(0);
3397+
((Closeable) catalogWithCustomReporter).close();
3398+
assertThat(CustomMetricsReporter.CLOSE_COUNTER.get())
3399+
.as("Catalog.close() must propagate to the configured MetricsReporter")
3400+
.isEqualTo(1);
33943401
}
33953402

33963403
public static class CustomMetricsReporter implements MetricsReporter {
33973404
static final AtomicInteger SCAN_COUNTER = new AtomicInteger(0);
33983405
static final AtomicInteger COMMIT_COUNTER = new AtomicInteger(0);
3406+
static final AtomicInteger CLOSE_COUNTER = new AtomicInteger(0);
33993407

34003408
@Override
34013409
public void report(MetricsReport report) {
@@ -3405,6 +3413,11 @@ public void report(MetricsReport report) {
34053413
COMMIT_COUNTER.incrementAndGet();
34063414
}
34073415
}
3416+
3417+
@Override
3418+
public void close() {
3419+
CLOSE_COUNTER.incrementAndGet();
3420+
}
34083421
}
34093422

34103423
private static void assertEmpty(String context, Catalog catalog, Namespace ns) {

0 commit comments

Comments
 (0)