Class ChunkedRecordAccumulatorTest

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

public class ChunkedRecordAccumulatorTest extends Object
  • Constructor Details

    • ChunkedRecordAccumulatorTest

      public ChunkedRecordAccumulatorTest()
  • Method Details

    • teardown

      @AfterEach public void teardown()
    • testFirstRecordCreatesChunkedBatch

      @Test public void testFirstRecordCreatesChunkedBatch() throws Exception
      Throws:
      Exception
    • testSmallFollowupRecordFitsWithoutExtension

      @Test public void testSmallFollowupRecordFitsWithoutExtension() throws Exception
      Throws:
      Exception
    • testMidBatchExtensionGrowsExistingBatch

      @Test public void testMidBatchExtensionGrowsExistingBatch() throws Exception
      A follow-up record that would overflow the existing chunks triggers mid-batch extension: additional chunks are attached and the record lands in the same batch.
      Throws:
      Exception
    • testConcurrentExtensionRaceLoserExtendsAgain

      @Test public void testConcurrentExtensionRaceLoserExtendsAgain() throws Exception
      Two concurrent appenders race to extend the same open batch, each sizing its extension against the same remaining capacity off-lock. Whichever attaches and appends first consumes that capacity, leaving the other appender's extension too small for its record. Verifies that the post-attach tryAppend — which attempts the write based on the batch's actual capacity — makes that appender extend again and land its record in the same batch, rather than write past the stream's chunk capacity (which would surface here as an IllegalStateException thrown by the append).
      Throws:
      Exception
    • testConcurrentExtensionRaceLoserStartsNewBatch

      @Test public void testConcurrentExtensionRaceLoserStartsNewBatch() throws Exception
      Concurrent extensions can over-reserve: each appender sizes its own gap against the same remaining capacity, so a batch can end up with more chunk capacity than its batch-size limit admits. The limit must still be enforced on append: a record that no longer fits after the race winner's append rolls to a new batch even though the over-reserved chunks could physically hold it, and the unused surplus returns to the pool as soon as the batch is closed for appends during that roll (before completion).
      Throws:
      Exception
    • testPartitionSwitchRefundsHeldExtensionChunks

      @Test public void testPartitionSwitchRefundsHeldExtensionChunks() throws Exception
      When the sticky partition switches while extension chunks are held off-lock, those chunks (sized against the previous partition's open batch) must be refunded to the pool on the retry (not carried over and attached to a different partition's open batch)
      Throws:
      Exception
    • testInflightExpirationReturnsAllChunksToPool

      @Test public void testInflightExpirationReturnsAllChunksToPool() throws Exception
      Throws:
      Exception
    • testExhaustedExtensionFallsBackToBlockingNewBatchPath

      @Test public void testExhaustedExtensionFallsBackToBlockingNewBatchPath() throws Exception
      When the pool is exhausted during a mid-batch extension, the append must not busy-loop retrying the non-blocking acquire: after a single failed extension acquire (maxTimeToBlockMs = 0), the open batch is closed and the very next pool call is the blocking new-batch acquire (maxTimeToBlockMs > 0), where the record lands in a new batch.
      Throws:
      Exception
    • testBufferExhaustedNotDoubleCountedAcrossExtensionAndNewBatch

      @Test public void testBufferExhaustedNotDoubleCountedAcrossExtensionAndNewBatch() throws Exception
      A single dropped record is counted exactly once even when it first fails the extension attempt (recovered) and then fails the new-batch acquire. Uses a real (non-overridden) pool so the actual allocateChunks path runs on both acquires.
      Throws:
      Exception
    • testBatchCloseDoesNotDeallocateChunksPrematurely

      @Test public void testBatchCloseDoesNotDeallocateChunksPrematurely() throws Exception
      Test that chunks are returned to the pool only at batch completion (deallocate), never at close.
      Throws:
      Exception
    • testExtensionTracksCumulativeBatchSize

      @Test public void testExtensionTracksCumulativeBatchSize() throws Exception
      As small records accumulate in a batch, the attached chunks grow with the batch's cumulative projected output (not per-record).
      Throws:
      Exception
    • testCumulativeAccountsForBatchHeaderOnce

      @Test public void testCumulativeAccountsForBatchHeaderOnce() throws Exception
      Throws:
      Exception
    • testChunkedBatchRejectsNonChunkedStream

      @Test public void testChunkedBatchRejectsNonChunkedStream()
    • testBatchClosedForAppendsDuringAllocationIsNotExtended

      @Test public void testBatchClosedForAppendsDuringAllocationIsNotExtended() throws Exception
      A batch closed for appends while the extension chunks were acquired off-lock must not be attached to: the chunks go back to the pool and the record goes to a new batch.
      Throws:
      Exception