Class BufferPoolChunkAllocationTest

java.lang.Object
org.apache.kafka.clients.producer.internals.BufferPoolChunkAllocationTest

public class BufferPoolChunkAllocationTest extends Object
  • Constructor Details

    • BufferPoolChunkAllocationTest

      public BufferPoolChunkAllocationTest()
  • Method Details

    • teardown

      @AfterEach public void teardown()
    • testAllocateOneChunk

      @Test public void testAllocateOneChunk() throws Exception
      Single-chunk request returns a list of one buffer at the chunk size.
      Throws:
      Exception
    • testAllocateRoundsUpToChunkBoundary

      @Test public void testAllocateRoundsUpToChunkBoundary() throws Exception
      Total size that's not a multiple of chunk size rounds up
      Throws:
      Exception
    • testAllocateMultipleChunks

      @Test public void testAllocateMultipleChunks() throws Exception
      Multi-chunk request returns ceil(totalSize / chunkSize) chunks.
      Throws:
      Exception
    • testAvailableMemoryAfterAllocation

      @Test public void testAvailableMemoryAfterAllocation() throws Exception
      Pool memory accounting: after allocation, the unallocated portion shrinks by the request.
      Throws:
      Exception
    • testDeallocationRestoresMemory

      @Test public void testDeallocationRestoresMemory() throws Exception
      Returning chunks via deallocate restores pool memory.
      Throws:
      Exception
    • testRejectsRequestExceedingTotalMemory

      @Test public void testRejectsRequestExceedingTotalMemory()
    • testRejectsNonPositiveRequest

      @Test public void testRejectsNonPositiveRequest()
    • testImmediateTimeoutAcquiresNothing

      @Test public void testImmediateTimeoutAcquiresNothing() throws Exception
      A request that cannot be satisfied immediately and has no time to wait takes nothing: it blocks on the wait queue before acquiring anything, so the timeout leaves pool memory untouched (no roll back needed).
      Throws:
      Exception
    • testNoPartialHoldsDuringWait

      @Test public void testNoPartialHoldsDuringWait() throws Exception
      No partial chunk holds during the wait. While a multi-chunk request blocks, the pool's availableMemory() must reflect bytes the waiter has not yet "earned".
      Throws:
      Exception
    • testFifoFairnessAcrossMultiChunkAndSingleChunkRequests

      @Test public void testFifoFairnessAcrossMultiChunkAndSingleChunkRequests() throws Exception
      FIFO fairness across the K-chunk request. A multi-chunk request that joins the wait queue before a single-chunk request must complete first when memory becomes available — the K-chunk request occupies a single waiter slot, not K of them.
      Throws:
      Exception
    • testWaitingRequestDoesNotDoubleRefundChunksOnTimeout

      @Test public void testWaitingRequestDoesNotDoubleRefundChunksOnTimeout() throws Exception
      A chunk request that can't be satisfied immediately must wait for memory, taking chunks as they are freed. If it then times out before acquiring all it needs, each chunk it already took must be returned to the pool exactly once. A double refund would make the pool over-report availableMemory(), letting later allocations exceed the configured buffer.memory limit.
      Throws:
      Exception
    • testWaitingRequestDoesNotCorruptAccountingOnSuccess

      @Test public void testWaitingRequestDoesNotCorruptAccountingOnSuccess() throws Exception
      A chunk request that must wait for memory and then completes by taking chunks as they are freed must account for those chunks exactly once — as memory now held by the caller — so the pool neither loses nor over-reports capacity.
      Throws:
      Exception
    • testCloseDuringAtomicWait

      @Test public void testCloseDuringAtomicWait() throws Exception
      Closing the pool while a multi-chunk request is parked must surface a KafkaException and refund all reserved bytes.
      Throws:
      Exception