cxm940188 commented on code in PR #23525:
URL: https://github.com/apache/kafka/pull/23525#discussion_r4090387497
##########
metadata/src/test/java/org/apache/kafka/controller/QuorumControllerTest.java:
##########
@@ -1637,6 +1652,72 @@ public void testAppendRecordsAtomically() {
appender)).getMessage());
}
+ @ParameterizedTest(name = "numRecords={0}, max={1}")
+ @CsvSource({
+ "1, 1", "1, 2", "2, 2", "3, 2", "4, 2", "5, 2", "6, 2",
+ "2, 1", "3, 1", "5, 1", "100, 1",
+ "1, 10", "2, 10", "10, 3", "100, 7"
+ })
+ public void testAppendRecordsNonAtomicBatching(int numRecords, int max) {
+ List<ApiMessageAndVersion> records = new ArrayList<>();
+ for (int i = 0; i < numRecords; i++) {
+ records.add(rec(i));
+ }
+ RecordingAppender appender = new RecordingAppender();
+ long returned = QuorumController.appendRecords(log,
+ ControllerResult.of(records, null), max, appender);
+
+ List<Integer> expectedSizes = new ArrayList<>();
+ for (int i = 0; i < numRecords; i += max) {
+ expectedSizes.add(Math.min(max, numRecords - i));
+ }
+ assertEquals(expectedSizes, appender.batchSizes,
+ "batches should be exactly max-sized except the final one");
+ assertTrue(appender.batchSizes.stream().allMatch(s -> s > 0 && s <=
max),
+ "every batch should be non-empty and no larger than max");
+ assertEquals(numRecords,
appender.batchSizes.stream().mapToLong(Integer::longValue).sum(),
+ "no record should be dropped or duplicated");
+ assertEquals(numRecords == 0 ? -1L : (long) numRecords, returned);
+ }
+
+ @Test
+ public void testAppendRecordsNonAtomicDoesNotAppendEmptyBatch() {
+ assertEquals(2L, appendWithThrowingAppender(2, 2));
+ assertEquals(4L, appendWithThrowingAppender(4, 2));
Review Comment:
After checking, this method is indeed redundant — the parameterized test's
`RecordingAppender` already asserts every batch is non-empty, so I removed it
along with its helper.
--
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]