From e53673d5b30d0eeabb23efbe9707e710b9ef6823 Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Tue, 14 May 2024 13:46:29 +0800 Subject: [PATCH 1/2] MINOR: revisit LogValidatorTest#checkRecompression --- .../test/scala/unit/kafka/log/LogValidatorTest.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala b/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala index ee1b896e7afae..3b07eaaae4d16 100644 --- a/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala +++ b/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala @@ -452,7 +452,7 @@ class LogValidatorTest { (RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, false, RecordBatch.NO_PARTITION_LEADER_EPOCH) - val records = MemoryRecords.withRecords(magic, 0L, CompressionType.GZIP, TimestampType.CREATE_TIME, producerId, + val records = MemoryRecords.withRecords(magic, 0L, CompressionType.NONE, TimestampType.CREATE_TIME, producerId, producerEpoch, baseSequence, partitionLeaderEpoch, isTransactional, new SimpleRecord(timestampSeq(0), "hello".getBytes), new SimpleRecord(timestampSeq(1), "there".getBytes), @@ -497,9 +497,11 @@ class LogValidatorTest { assertEquals(now + 1, validatingResults.maxTimestampMs, s"Max timestamp should be ${now + 1}") - // Both V2 and V1 has single branch in the record when compression is enable, and hence their shallow OffsetOfMaxTimestamp - // is the last offset of the single branch - assertEquals(1, records.batches().asScala.size) + // V2 has single batch, and other versions has many single-record batches + assertEquals(if (magic >= RecordBatch.MAGIC_VALUE_V2) 1 else 3, records.batches().asScala.size) + // Both V2 and V1 has single batch in the record when compression is enable, and hence their shallow OffsetOfMaxTimestamp + // is the last offset of the single batch + assertEquals(1, validatedRecords.batches().asScala.size) assertEquals(2, validatingResults.shallowOffsetOfMaxTimestamp) assertTrue(validatingResults.messageSizeMaybeChanged, "Message size should have been changed") From 40cabe2795ab8c051281ee03ead967cd525fd502 Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Wed, 15 May 2024 02:10:38 +0800 Subject: [PATCH 2/2] address comment --- .../src/test/scala/unit/kafka/log/LogValidatorTest.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala b/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala index 3b07eaaae4d16..0462fb86753d7 100644 --- a/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala +++ b/core/src/test/scala/unit/kafka/log/LogValidatorTest.scala @@ -458,6 +458,9 @@ class LogValidatorTest { new SimpleRecord(timestampSeq(1), "there".getBytes), new SimpleRecord(timestampSeq(2), "beautiful".getBytes)) + // V2 has single batch, and other versions has many single-record batches + assertEquals(if (magic >= RecordBatch.MAGIC_VALUE_V2) 1 else 3, records.batches().asScala.size) + val validatingResults = new LogValidator(records, topicPartition, time, @@ -497,10 +500,8 @@ class LogValidatorTest { assertEquals(now + 1, validatingResults.maxTimestampMs, s"Max timestamp should be ${now + 1}") - // V2 has single batch, and other versions has many single-record batches - assertEquals(if (magic >= RecordBatch.MAGIC_VALUE_V2) 1 else 3, records.batches().asScala.size) - // Both V2 and V1 has single batch in the record when compression is enable, and hence their shallow OffsetOfMaxTimestamp - // is the last offset of the single batch + // Both V2 and V1 has single batch in the validated records when compression is enable, and hence their shallow + // OffsetOfMaxTimestamp is the last offset of the single batch assertEquals(1, validatedRecords.batches().asScala.size) assertEquals(2, validatingResults.shallowOffsetOfMaxTimestamp) assertTrue(validatingResults.messageSizeMaybeChanged,