@Test
    public void testClosingQuorumControllerClosesMetrics() throws Throwable {
        MockControllerMetrics metrics = new MockControllerMetrics();
        try (
            LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv.Builder(1).
                build();
            QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv.Builder(logEnv).
                setControllerBuilderInitializer(controllerBuilder ->
                    controllerBuilder.setMetrics(metrics)
                ).
                build()
        ) {
            assertEquals(1, controlEnv.activeController().controllerMetrics().newActiveControllers());
        }
        assertTrue(metrics.closed.get(), "metrics were not closed");
    }
Test that closing the QuorumController closes the metrics object.
metadata/src/test/java/org/apache/kafka/controller/QuorumControllerMetricsIntegrationTest.java