chia7712 commented on code in PR #9766: URL: https://github.com/apache/kafka/pull/9766#discussion_r1976429195
########## clients/src/test/java/org/apache/kafka/common/record/EndTransactionMarkerTest.java: ########## @@ -17,16 +17,30 @@ package org.apache.kafka.common.record; import org.apache.kafka.common.InvalidRecordException; +import org.apache.kafka.common.message.EndTxnMarker; +import org.apache.kafka.common.protocol.types.Field; +import org.apache.kafka.common.protocol.types.Schema; +import org.apache.kafka.common.protocol.types.Struct; +import org.apache.kafka.common.protocol.types.Type; import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; public class EndTransactionMarkerTest { + // Old hard-coded schema, used to validate old hard-coded schema format is exactly the same as new auto generated protocol format + private Schema v0Schema = new Schema( Review Comment: could you please add `final`? ########## clients/src/main/java/org/apache/kafka/common/record/EndTransactionMarker.java: ########## @@ -95,32 +76,35 @@ public int hashCode() { private static void ensureTransactionMarkerControlType(ControlRecordType type) { if (type != ControlRecordType.COMMIT && type != ControlRecordType.ABORT) - throw new IllegalArgumentException("Invalid control record type for end transaction marker" + type); + throw new IllegalArgumentException("Invalid control record type for end transaction marker " + type); } public static EndTransactionMarker deserialize(Record record) { ControlRecordType type = ControlRecordType.parse(record.key()); return deserializeValue(type, record.value()); } + // Visible for testing static EndTransactionMarker deserializeValue(ControlRecordType type, ByteBuffer value) { ensureTransactionMarkerControlType(type); - if (value.remaining() < CURRENT_END_TXN_MARKER_VALUE_SIZE) - throw new InvalidRecordException("Invalid value size found for end transaction marker. Must have " + - "at least " + CURRENT_END_TXN_MARKER_VALUE_SIZE + " bytes, but found only " + value.remaining()); - - short version = value.getShort(0); - if (version < 0) + short version = value.getShort(); + if (version < EndTxnMarker.LOWEST_SUPPORTED_VERSION) throw new InvalidRecordException("Invalid version found for end transaction marker: " + version + ". May indicate data corruption"); - if (version > CURRENT_END_TXN_MARKER_VERSION) + if (version > EndTxnMarker.HIGHEST_SUPPORTED_VERSION) log.debug("Received end transaction marker value version {}. Parsing as version {}", version, - CURRENT_END_TXN_MARKER_VERSION); + EndTxnMarker.HIGHEST_SUPPORTED_VERSION); + EndTxnMarker marker = new EndTxnMarker(new ByteBufferAccessor(value), version); + return new EndTransactionMarker(type, marker.coordinatorEpoch()); + } - int coordinatorEpoch = value.getInt(2); - return new EndTransactionMarker(type, coordinatorEpoch); + public int endTxnMarkerValueSize() { Review Comment: Could you please add unit test for this method? -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org