@Test
    public void testCloseAllocations() throws Exception {
        BufferPool pool = new BufferPool(10, 1, metrics, Time.SYSTEM, metricGroup);
        ByteBuffer buffer = pool.allocate(1, maxBlockTimeMs);

        // Close the buffer pool. This should prevent any further allocations.
        pool.close();

        assertThrows(KafkaException.class, () -> pool.allocate(1, maxBlockTimeMs));

        // Ensure deallocation still works.
        pool.deallocate(buffer);
    }
This test creates lots of threads that hammer on the pool
clients/src/test/java/org/apache/kafka/clients/producer/internals/BufferPoolTest.java