ahuang98 commented on code in PR #21028:
URL: https://github.com/apache/kafka/pull/21028#discussion_r2729507608


##########
raft/src/test/java/org/apache/kafka/raft/internals/KafkaRaftLogTest.java:
##########
@@ -1083,6 +1087,74 @@ public void testSegmentsLessThanLatestSnapshot() throws 
IOException {
         );
     }
 
+    @Test
+    public void testReadRespectsDefaultInternalMaxFetchSize() throws 
IOException {
+        int defaultMaxToReadBytes = 1;
+        MetadataLogConfig config = createMetadataLogConfig(
+                10240,
+                10 * 1000,
+                10240,
+                60 * 1000,
+                128,
+                defaultMaxToReadBytes
+        );
+        KafkaRaftLog log = buildMetadataLog(tempDir, mockTime, config);
+        // Append twice to ensure we have 2 batches.
+        append(log, 2, 1);
+        append(log, 1, 1);
+
+        LogFetchInfo info = log.read(0, Isolation.UNCOMMITTED);
+
+        // There are 2 batches. The 1st has 2 records and will be larger than 
1 Byte in size.
+        // read implementation will return at least 1 batch.
+        assertRecordBatches(info, 2, 2);
+    }
+
+    @ParameterizedTest
+    @ValueSource(ints = {1, 2, 3})
+    public void testReadRespectsMaxSizeInBytes(int expectedBatches) throws 
IOException {
+        // 5 records are written in batches of 101 bytes each (at time of 
writing).
+        int magicMaxBatchSizeBytes = 101;
+        MetadataLogConfig config = createMetadataLogConfig(
+                10240,
+                10 * 1000,
+                10240,
+                60 * 1000,
+                magicMaxBatchSizeBytes,
+                1
+        );
+        KafkaRaftLog log = buildMetadataLog(tempDir, mockTime, config);
+        int recordsPerBatch = 5;
+        append(log, recordsPerBatch, 1);
+        append(log, recordsPerBatch, 1);
+        append(log, recordsPerBatch, 1);
+        append(log, recordsPerBatch, 1);
+
+        LogFetchInfo info = log.read(0,
+                Isolation.UNCOMMITTED,
+                magicMaxBatchSizeBytes * expectedBatches);
+        assertRecordBatches(info, recordsPerBatch * expectedBatches, 
recordsPerBatch);
+
+    }
+
+    private static void assertRecordBatches(LogFetchInfo info, int 
numberExpected, int recordsPerBatch) {
+        // Asserts that we have exactly B * R records. Further there must be B 
batches of SimpleRecords each with a value of

Review Comment:
   so we're assuming any use case of this validator is with batches with same 
number of records in them 



-- 
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