AnatolyPopov commented on code in PR #23162:
URL: https://github.com/apache/kafka/pull/23162#discussion_r3796039688
##########
storage/src/test/java/org/apache/kafka/storage/internals/log/UnifiedLogTest.java:
##########
@@ -2982,6 +2982,60 @@ public void testMessageSetSizeCheck() throws IOException
{
assertThrows(RecordBatchTooLargeException.class, () ->
log.appendAsLeader(messageSet, 0));
}
+ @ParameterizedTest
+ @EnumSource(value = AppendOrigin.class, names = "REPLICATION", mode =
EnumSource.Mode.EXCLUDE)
+ public void testSegmentSizeCheckForNonReplicationOrigins(AppendOrigin
origin) throws IOException {
+ MemoryRecords records = MemoryRecords.withRecords(0, Compression.NONE,
0,
+ new SimpleRecord("You".getBytes()), new
SimpleRecord("bethe".getBytes()));
+ log = createLog(logDir, new LogTestUtils.LogConfigBuilder()
+ .segmentBytes(records.sizeInBytes() - 1)
+ .maxMessageBytes(records.sizeInBytes())
+ .build());
+
+ assertThrows(RecordBatchTooLargeException.class, () ->
log.appendAsLeader(records, 0, origin));
+ }
+
+ @Test
+ public void testSegmentSizeCheckInAppendAsFollower() throws IOException {
+ MemoryRecords records = MemoryRecords.withRecords(0, Compression.NONE,
0,
+ new SimpleRecord("You".getBytes()), new
SimpleRecord("bethe".getBytes()));
+ log = createLog(logDir, new LogTestUtils.LogConfigBuilder()
+ .segmentBytes(records.sizeInBytes() - 1)
+ .maxMessageBytes(records.sizeInBytes())
+ .build());
+
+ log.appendAsFollower(records, Integer.MAX_VALUE);
+
+ assertEquals(2L, log.logEndOffset());
+ assertEquals(1, log.numberOfSegments());
+ assertEquals(records.sizeInBytes(), log.activeSegment().size());
+ }
+
+ @Test
+ public void testSegmentSizeCheckInAppendAsFollowerWithNonEmptySegment()
throws IOException {
+ MemoryRecords first = MemoryRecords.withRecords(0, Compression.NONE, 0,
+ new SimpleRecord("small".getBytes()));
+ MemoryRecords oversized = MemoryRecords.withRecords(1,
Compression.NONE, 0,
+ new SimpleRecord("This record set is larger than the
configured segment size.".getBytes()),
+ new SimpleRecord("More padding for the oversized record
set.".getBytes()));
+ MemoryRecords last = MemoryRecords.withRecords(3, Compression.NONE, 0,
+ new SimpleRecord("small".getBytes()));
+ log = createLog(logDir, new LogTestUtils.LogConfigBuilder()
+ .segmentBytes(oversized.sizeInBytes() - 1)
+ .build());
+
+ log.appendAsFollower(first, Integer.MAX_VALUE);
+ log.appendAsFollower(oversized, Integer.MAX_VALUE);
+
+ assertEquals(3L, log.logEndOffset());
+ assertEquals(2, log.numberOfSegments());
+ assertEquals(oversized.sizeInBytes(), log.activeSegment().size());
+
+ log.appendAsFollower(last, Integer.MAX_VALUE);
Review Comment:
Added more assertions, thanks @viktorsomogyi!
--
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]