chia7712 commented on code in PR #18889:
URL: https://github.com/apache/kafka/pull/18889#discussion_r1955302461


##########
core/src/test/scala/integration/kafka/api/ConsumerWithLegacyMessageFormatIntegrationTest.scala:
##########
@@ -18,16 +18,41 @@ package kafka.api
 
 import kafka.utils.TestInfoUtils
 import org.apache.kafka.common.TopicPartition
+import org.apache.kafka.common.compress.Compression
+import org.apache.kafka.common.record.{AbstractRecords, CompressionType, 
MemoryRecords, RecordBatch, SimpleRecord, TimestampType}
+import org.apache.kafka.storage.internals.log.AppendOrigin
 import org.junit.jupiter.api.Assertions.{assertEquals, assertNull, 
assertThrows}
 import org.junit.jupiter.params.ParameterizedTest
 import org.junit.jupiter.params.provider.MethodSource
 
+import java.nio.ByteBuffer
 import java.util
 import java.util.{Collections, Optional}
 import scala.jdk.CollectionConverters._
 
 class ConsumerWithLegacyMessageFormatIntegrationTest extends 
AbstractConsumerTest {
 
+  private def appendLegacyRecords(numRecords: Int, tp: TopicPartition, 
startingTimestamp: Long, brokerId: Int): Unit = {
+    val records = (0 until numRecords).map { i =>
+      new SimpleRecord(startingTimestamp + i, s"key $i".getBytes, s"value 
$i".getBytes)
+    }
+    val buffer = 
ByteBuffer.allocate(AbstractRecords.estimateSizeInBytes(RecordBatch.MAGIC_VALUE_V1,
 CompressionType.NONE, records.asJava))
+    val builder = MemoryRecords.builder(buffer, RecordBatch.MAGIC_VALUE_V1, 
Compression.of(CompressionType.NONE).build,
+      TimestampType.CREATE_TIME, 0L, RecordBatch.NO_TIMESTAMP, 
RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH,
+      0, false, RecordBatch.NO_PARTITION_LEADER_EPOCH)
+
+    records.foreach(builder.append)
+
+    brokers.filter(_.config.brokerId == brokerId).foreach(b => 
b.replicaManager.appendRecords(

Review Comment:
   `replicaManager.appendRecords` performs the conversion if the `magic` of the 
batch is not equal to `v2`. Therefore, to handle older record formats, you 
should follow @ijuma's suggestion in the jira to utilize the Log class for 
writing records in the legacy format.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to