Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public void initialize(String name, Map<String, String> unresolved) {
.toUpperCase(Locale.US));

this.reporter = CatalogUtil.loadMetricsReporter(mergedProps);
this.closeables.addCloseable(reporter);

this.reportingViaRestEnabled =
PropertyUtil.propertyAsBoolean(
Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down