Class ChunkedRecordAccumulatorTest
java.lang.Object
org.apache.kafka.clients.producer.internals.ChunkedRecordAccumulatorTest
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidteardown()voidA 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.voidTest that chunks are returned to the pool only at batch completion (deallocate), never at close.voidA single dropped record is counted exactly once even when it first fails the extension attempt (recovered) and then fails the new-batch acquire.voidvoidTwo concurrent appenders race to extend the same open batch, each sizing its extension against the same remaining capacity off-lock.voidConcurrent 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.voidvoidWhen 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.voidAs small records accumulate in a batch, the attached chunks grow with the batch's cumulative projected output (not per-record).voidvoidvoidA 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.voidWhen 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)void
-
Constructor Details
-
ChunkedRecordAccumulatorTest
public ChunkedRecordAccumulatorTest()
-
-
Method Details
-
teardown
@AfterEach public void teardown() -
testFirstRecordCreatesChunkedBatch
-
testSmallFollowupRecordFitsWithoutExtension
-
testMidBatchExtensionGrowsExistingBatch
-
testConcurrentExtensionRaceLoserExtendsAgain
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-attachtryAppend— 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 anIllegalStateExceptionthrown by the append).- Throws:
Exception
-
testConcurrentExtensionRaceLoserStartsNewBatch
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
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
-
testExhaustedExtensionFallsBackToBlockingNewBatchPath
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
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
-
testExtensionTracksCumulativeBatchSize
-
testCumulativeAccountsForBatchHeaderOnce
-
testChunkedBatchRejectsNonChunkedStream
@Test public void testChunkedBatchRejectsNonChunkedStream() -
testBatchClosedForAppendsDuringAllocationIsNotExtended
-