|
|
|
@ -103,7 +103,7 @@ public class RecordAccumulatorTest {
@@ -103,7 +103,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
int batchSize = 1025; |
|
|
|
|
|
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10L * batchSize, CompressionType.NONE, 10L); |
|
|
|
|
batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10L * batchSize, CompressionType.NONE, 10); |
|
|
|
|
int appends = expectedNumAppends(batchSize); |
|
|
|
|
for (int i = 0; i < appends; i++) { |
|
|
|
|
// append to the first batch
|
|
|
|
@ -152,7 +152,7 @@ public class RecordAccumulatorTest {
@@ -152,7 +152,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
int batchSize = 512; |
|
|
|
|
byte[] value = new byte[2 * batchSize]; |
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, compressionType, 0L); |
|
|
|
|
batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, compressionType, 0); |
|
|
|
|
accum.append(tp1, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs); |
|
|
|
|
assertEquals("Our partition's leader should be ready", Collections.singleton(node1), accum.ready(cluster, time.milliseconds()).readyNodes); |
|
|
|
|
|
|
|
|
@ -191,7 +191,7 @@ public class RecordAccumulatorTest {
@@ -191,7 +191,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
new ApiVersionsResponse.ApiVersion(ApiKeys.PRODUCE.id, (short) 0, (short) 2)))); |
|
|
|
|
|
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, compressionType, 0L); |
|
|
|
|
batchSize + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, compressionType, 0); |
|
|
|
|
accum.append(tp1, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs); |
|
|
|
|
assertEquals("Our partition's leader should be ready", Collections.singleton(node1), accum.ready(cluster, time.milliseconds()).readyNodes); |
|
|
|
|
|
|
|
|
@ -213,7 +213,7 @@ public class RecordAccumulatorTest {
@@ -213,7 +213,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testLinger() throws Exception { |
|
|
|
|
long lingerMs = 10L; |
|
|
|
|
int lingerMs = 10; |
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, lingerMs); |
|
|
|
|
accum.append(tp1, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs); |
|
|
|
@ -234,7 +234,7 @@ public class RecordAccumulatorTest {
@@ -234,7 +234,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testPartialDrain() throws Exception { |
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, 10L); |
|
|
|
|
1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, 10); |
|
|
|
|
int appends = 1024 / msgSize + 1; |
|
|
|
|
List<TopicPartition> partitions = asList(tp1, tp2); |
|
|
|
|
for (TopicPartition tp : partitions) { |
|
|
|
@ -254,7 +254,7 @@ public class RecordAccumulatorTest {
@@ -254,7 +254,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
final int msgs = 10000; |
|
|
|
|
final int numParts = 2; |
|
|
|
|
final RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, 0L); |
|
|
|
|
1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, 0); |
|
|
|
|
List<Thread> threads = new ArrayList<>(); |
|
|
|
|
for (int i = 0; i < numThreads; i++) { |
|
|
|
|
threads.add(new Thread() { |
|
|
|
@ -293,7 +293,7 @@ public class RecordAccumulatorTest {
@@ -293,7 +293,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testNextReadyCheckDelay() throws Exception { |
|
|
|
|
// Next check time will use lingerMs since this test won't trigger any retries/backoff
|
|
|
|
|
long lingerMs = 10L; |
|
|
|
|
int lingerMs = 10; |
|
|
|
|
|
|
|
|
|
// test case assumes that the records do not fill the batch completely
|
|
|
|
|
int batchSize = 1025; |
|
|
|
@ -331,10 +331,9 @@ public class RecordAccumulatorTest {
@@ -331,10 +331,9 @@ public class RecordAccumulatorTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testRetryBackoff() throws Exception { |
|
|
|
|
long lingerMs = Integer.MAX_VALUE / 16; |
|
|
|
|
int lingerMs = Integer.MAX_VALUE / 16; |
|
|
|
|
long retryBackoffMs = Integer.MAX_VALUE / 8; |
|
|
|
|
int requestTimeoutMs = Integer.MAX_VALUE / 4; |
|
|
|
|
long deliveryTimeoutMs = Integer.MAX_VALUE; |
|
|
|
|
int deliveryTimeoutMs = Integer.MAX_VALUE; |
|
|
|
|
long totalSize = 10 * 1024; |
|
|
|
|
int batchSize = 1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD; |
|
|
|
|
String metricGrpName = "producer-metrics"; |
|
|
|
@ -377,7 +376,7 @@ public class RecordAccumulatorTest {
@@ -377,7 +376,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFlush() throws Exception { |
|
|
|
|
long lingerMs = Integer.MAX_VALUE; |
|
|
|
|
int lingerMs = Integer.MAX_VALUE; |
|
|
|
|
final RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
4 * 1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 64 * 1024, CompressionType.NONE, lingerMs); |
|
|
|
|
|
|
|
|
@ -419,7 +418,7 @@ public class RecordAccumulatorTest {
@@ -419,7 +418,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testAwaitFlushComplete() throws Exception { |
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
|
4 * 1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 64 * 1024, CompressionType.NONE, Long.MAX_VALUE); |
|
|
|
|
4 * 1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 64 * 1024, CompressionType.NONE, Integer.MAX_VALUE); |
|
|
|
|
accum.append(new TopicPartition(topic, 0), 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs); |
|
|
|
|
|
|
|
|
|
accum.beginFlush(); |
|
|
|
@ -515,8 +514,8 @@ public class RecordAccumulatorTest {
@@ -515,8 +514,8 @@ public class RecordAccumulatorTest {
|
|
|
|
|
assertTrue(accum.hasIncomplete()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doExpireBatchSingle(long deliveryTimeoutMs) throws InterruptedException { |
|
|
|
|
long lingerMs = 300L; |
|
|
|
|
private void doExpireBatchSingle(int deliveryTimeoutMs) throws InterruptedException { |
|
|
|
|
int lingerMs = 300; |
|
|
|
|
List<Boolean> muteStates = Arrays.asList(false, true); |
|
|
|
|
Set<Node> readyNodes = null; |
|
|
|
|
List<ProducerBatch> expiredBatches = new ArrayList<>(); |
|
|
|
@ -554,20 +553,20 @@ public class RecordAccumulatorTest {
@@ -554,20 +553,20 @@ public class RecordAccumulatorTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testExpiredBatchSingle() throws InterruptedException { |
|
|
|
|
doExpireBatchSingle(3200L); |
|
|
|
|
doExpireBatchSingle(3200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testExpiredBatchSingleMaxValue() throws InterruptedException { |
|
|
|
|
doExpireBatchSingle(Long.MAX_VALUE); |
|
|
|
|
doExpireBatchSingle(Integer.MAX_VALUE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testExpiredBatches() throws InterruptedException { |
|
|
|
|
long retryBackoffMs = 100L; |
|
|
|
|
long lingerMs = 30L; |
|
|
|
|
int lingerMs = 30; |
|
|
|
|
int requestTimeout = 60; |
|
|
|
|
long deliveryTimeoutMs = 3200L; |
|
|
|
|
int deliveryTimeoutMs = 3200; |
|
|
|
|
|
|
|
|
|
// test case assumes that the records do not fill the batch completely
|
|
|
|
|
int batchSize = 1025; |
|
|
|
@ -700,9 +699,8 @@ public class RecordAccumulatorTest {
@@ -700,9 +699,8 @@ public class RecordAccumulatorTest {
|
|
|
|
|
// Simulate talking to an older broker, ie. one which supports a lower magic.
|
|
|
|
|
ApiVersions apiVersions = new ApiVersions(); |
|
|
|
|
int batchSize = 1025; |
|
|
|
|
int requestTimeoutMs = 1600; |
|
|
|
|
long deliveryTimeoutMs = 3200L; |
|
|
|
|
long lingerMs = 10L; |
|
|
|
|
int deliveryTimeoutMs = 3200; |
|
|
|
|
int lingerMs = 10; |
|
|
|
|
long retryBackoffMs = 100L; |
|
|
|
|
long totalSize = 10 * batchSize; |
|
|
|
|
String metricGrpName = "producer-metrics"; |
|
|
|
@ -777,7 +775,7 @@ public class RecordAccumulatorTest {
@@ -777,7 +775,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
|
|
|
|
|
// First set the compression ratio estimation to be good.
|
|
|
|
|
CompressionRatioEstimator.setEstimation(tp1.topic(), CompressionType.GZIP, 0.1f); |
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator(batchSize, bufferCapacity, CompressionType.GZIP, 0L); |
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator(batchSize, bufferCapacity, CompressionType.GZIP, 0); |
|
|
|
|
int numSplitBatches = prepareSplitBatches(accum, seed, 100, 20); |
|
|
|
|
assertTrue("There should be some split batches", numSplitBatches > 0); |
|
|
|
|
// Drain all the split batches.
|
|
|
|
@ -829,7 +827,7 @@ public class RecordAccumulatorTest {
@@ -829,7 +827,7 @@ public class RecordAccumulatorTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSoonToExpireBatchesArePickedUpForExpiry() throws InterruptedException { |
|
|
|
|
long lingerMs = 500L; |
|
|
|
|
int lingerMs = 500; |
|
|
|
|
int batchSize = 1025; |
|
|
|
|
|
|
|
|
|
RecordAccumulator accum = createTestRecordAccumulator( |
|
|
|
@ -993,17 +991,16 @@ public class RecordAccumulatorTest {
@@ -993,17 +991,16 @@ public class RecordAccumulatorTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RecordAccumulator createTestRecordAccumulator(int batchSize, long totalSize, CompressionType type, long lingerMs) { |
|
|
|
|
long deliveryTimeoutMs = 3200L; |
|
|
|
|
private RecordAccumulator createTestRecordAccumulator(int batchSize, long totalSize, CompressionType type, int lingerMs) { |
|
|
|
|
int deliveryTimeoutMs = 3200; |
|
|
|
|
return createTestRecordAccumulator(deliveryTimeoutMs, batchSize, totalSize, type, lingerMs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return a test RecordAccumulator instance |
|
|
|
|
*/ |
|
|
|
|
private RecordAccumulator createTestRecordAccumulator(long deliveryTimeoutMs, int batchSize, long totalSize, CompressionType type, long lingerMs) { |
|
|
|
|
private RecordAccumulator createTestRecordAccumulator(int deliveryTimeoutMs, int batchSize, long totalSize, CompressionType type, int lingerMs) { |
|
|
|
|
long retryBackoffMs = 100L; |
|
|
|
|
int requestTimeoutMs = 1600; |
|
|
|
|
String metricGrpName = "producer-metrics"; |
|
|
|
|
|
|
|
|
|
return new RecordAccumulator( |
|
|
|
|