@Test
    public void testCountCloses() {
        AtomicInteger onCloseCounter = new AtomicInteger();
        IdempotentCloser ic = new IdempotentCloser();

        // Verify initial invariants.
        assertFalse(ic.isClosed());
        assertEquals(0, onCloseCounter.get());

        // Close with our onClose callback to increment our counter.
        ic.close(onCloseCounter::getAndIncrement);
        assertTrue(ic.isClosed());
        assertEquals(1, onCloseCounter.get());

        // Close with our onClose callback again, but verify it wasn't invoked as it was previously closed.
        ic.close(onCloseCounter::getAndIncrement);
        assertTrue(ic.isClosed());
        assertEquals(1, onCloseCounter.get());
    }
Tests that the onClose callback is only invoked once.
clients/src/test/java/org/apache/kafka/common/internals/IdempotentCloserTest.java