junrao commented on code in PR #20614:
URL: https://github.com/apache/kafka/pull/20614#discussion_r2557562323


##########
clients/src/test/java/org/apache/kafka/common/message/ProtocolSerializationConsistencyTest.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.common.message;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.protocol.types.Field;
+import org.apache.kafka.common.protocol.types.Struct;
+import org.apache.kafka.common.record.MemoryRecords;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.TreeMap;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProtocolSerializationConsistencyTest {
+
+    private Struct nonFlexibleStruct;
+
+    private Struct flexibleStruct;
+
+    private AllTypeMessageData messageData;
+
+    @BeforeEach
+    public void setup() {
+        nonFlexibleStruct = new Struct(AllTypeMessageData.SCHEMA_0)
+            .set("my_boolean", false)
+            .set("my_int8", (byte) 12)
+            .set("my_int16", (short) 123)
+            .set("my_uint16", 33000)
+            .set("my_int32", 1234)
+            .set("my_uint32", 1234567L)
+            .set("my_uint64", 0xcafcacafcacafcaL)
+            .set("my_uuid", Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"))
+            .set("my_float64", 12.34D)
+            .set("my_string", "string")
+            .set("my_nullable_string", null)
+            .set("my_bytes", ByteBuffer.wrap("bytes".getBytes()))
+            .set("my_nullable_bytes", null)
+            .set("my_records", MemoryRecords.EMPTY)
+            .set("my_nullable_records", null)
+            .set("my_int_array", new Object[] {})
+            .set("my_nullable_int_array", null);
+        nonFlexibleStruct.set("my_common_struct", 
nonFlexibleStruct.instance("my_common_struct")
+            .set("foo", 123)
+            .set("bar", 123));
+
+        flexibleStruct = new Struct(AllTypeMessageData.SCHEMA_1)
+            .set("my_boolean", false)
+            .set("my_int8", (byte) 12)
+            .set("my_int16", (short) 123)
+            .set("my_uint16", 33000)
+            .set("my_int32", 1234)
+            .set("my_uint32", 1234567L)
+            .set("my_uint64", 0xcafcacafcacafcaL)
+            .set("my_uuid", Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"))
+            .set("my_float64", 12.34D)
+            .set("my_compact_string", "compact string")
+            .set("my_compact_nullable_string", null)
+            .set("my_compact_bytes", ByteBuffer.wrap("compact 
bytes".getBytes()))
+            .set("my_compact_nullable_bytes", null)
+            .set("my_compact_records", MemoryRecords.EMPTY)
+            .set("my_compact_nullable_records", null)
+            .set("my_int_array", new Object[] {})
+            .set("my_nullable_int_array", null)
+            .set("_tagged_fields", new TreeMap<Integer, Field>());
+        flexibleStruct.set("my_common_struct", 
flexibleStruct.instance("my_common_struct")
+            .set("foo", 123)
+            .set("bar", 123)
+            .set("_tagged_fields", new TreeMap<Integer, Field>()));
+
+        messageData = new AllTypeMessageData();
+    }
+
+    @Test
+    public void testNonFlexibleWithNullValue() {
+        messageData.setMyBytes("bytes".getBytes());

Review Comment:
   Hmm, we are not setting null value here as the method name indicates.



##########
clients/src/test/java/org/apache/kafka/common/message/ProtocolSerializationConsistencyTest.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.common.message;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.protocol.types.Field;
+import org.apache.kafka.common.protocol.types.Struct;
+import org.apache.kafka.common.record.MemoryRecords;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.TreeMap;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProtocolSerializationConsistencyTest {
+
+    private Struct nonFlexibleStruct;
+
+    private Struct flexibleStruct;
+
+    private AllTypeMessageData messageData;
+
+    @BeforeEach
+    public void setup() {
+        nonFlexibleStruct = new Struct(AllTypeMessageData.SCHEMA_0)
+            .set("my_boolean", false)
+            .set("my_int8", (byte) 12)
+            .set("my_int16", (short) 123)
+            .set("my_uint16", 33000)
+            .set("my_int32", 1234)
+            .set("my_uint32", 1234567L)
+            .set("my_uint64", 0xcafcacafcacafcaL)
+            .set("my_uuid", Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"))
+            .set("my_float64", 12.34D)
+            .set("my_string", "string")
+            .set("my_nullable_string", null)
+            .set("my_bytes", ByteBuffer.wrap("bytes".getBytes()))
+            .set("my_nullable_bytes", null)
+            .set("my_records", MemoryRecords.EMPTY)
+            .set("my_nullable_records", null)
+            .set("my_int_array", new Object[] {})
+            .set("my_nullable_int_array", null);
+        nonFlexibleStruct.set("my_common_struct", 
nonFlexibleStruct.instance("my_common_struct")
+            .set("foo", 123)
+            .set("bar", 123));
+
+        flexibleStruct = new Struct(AllTypeMessageData.SCHEMA_1)
+            .set("my_boolean", false)
+            .set("my_int8", (byte) 12)
+            .set("my_int16", (short) 123)
+            .set("my_uint16", 33000)
+            .set("my_int32", 1234)
+            .set("my_uint32", 1234567L)
+            .set("my_uint64", 0xcafcacafcacafcaL)
+            .set("my_uuid", Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"))
+            .set("my_float64", 12.34D)
+            .set("my_compact_string", "compact string")
+            .set("my_compact_nullable_string", null)
+            .set("my_compact_bytes", ByteBuffer.wrap("compact 
bytes".getBytes()))
+            .set("my_compact_nullable_bytes", null)
+            .set("my_compact_records", MemoryRecords.EMPTY)
+            .set("my_compact_nullable_records", null)
+            .set("my_int_array", new Object[] {})
+            .set("my_nullable_int_array", null)
+            .set("_tagged_fields", new TreeMap<Integer, Field>());
+        flexibleStruct.set("my_common_struct", 
flexibleStruct.instance("my_common_struct")
+            .set("foo", 123)
+            .set("bar", 123)
+            .set("_tagged_fields", new TreeMap<Integer, Field>()));
+
+        messageData = new AllTypeMessageData();
+    }
+
+    @Test
+    public void testNonFlexibleWithNullValue() {
+        messageData.setMyBytes("bytes".getBytes());
+        messageData.setMyRecords(MemoryRecords.EMPTY);

Review Comment:
   Hmm, myIntArray has no default in version 0. Since the test doesn't set its 
value in messageData. Why doesn't the serialization fail?



##########
clients/src/test/java/org/apache/kafka/common/message/ProtocolSerializationConsistencyTest.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.common.message;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.protocol.types.Field;
+import org.apache.kafka.common.protocol.types.Struct;
+import org.apache.kafka.common.record.MemoryRecords;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.TreeMap;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProtocolSerializationConsistencyTest {
+
+    private Struct nonFlexibleStruct;
+
+    private Struct flexibleStruct;
+
+    private AllTypeMessageData messageData;
+
+    @BeforeEach
+    public void setup() {
+        nonFlexibleStruct = new Struct(AllTypeMessageData.SCHEMA_0)
+            .set("my_boolean", false)

Review Comment:
   This is the default value. Do we need to set it explicitly?



##########
clients/src/test/java/org/apache/kafka/common/message/ProtocolSerializationConsistencyTest.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.common.message;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.protocol.types.Field;
+import org.apache.kafka.common.protocol.types.Struct;
+import org.apache.kafka.common.record.MemoryRecords;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.TreeMap;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProtocolSerializationConsistencyTest {
+
+    private Struct nonFlexibleStruct;
+
+    private Struct flexibleStruct;
+
+    private AllTypeMessageData messageData;
+
+    @BeforeEach
+    public void setup() {
+        nonFlexibleStruct = new Struct(AllTypeMessageData.SCHEMA_0)
+            .set("my_boolean", false)
+            .set("my_int8", (byte) 12)
+            .set("my_int16", (short) 123)
+            .set("my_uint16", 33000)
+            .set("my_int32", 1234)
+            .set("my_uint32", 1234567L)
+            .set("my_uint64", 0xcafcacafcacafcaL)
+            .set("my_uuid", Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"))
+            .set("my_float64", 12.34D)
+            .set("my_string", "string")
+            .set("my_nullable_string", null)
+            .set("my_bytes", ByteBuffer.wrap("bytes".getBytes()))
+            .set("my_nullable_bytes", null)
+            .set("my_records", MemoryRecords.EMPTY)
+            .set("my_nullable_records", null)
+            .set("my_int_array", new Object[] {})
+            .set("my_nullable_int_array", null);
+        nonFlexibleStruct.set("my_common_struct", 
nonFlexibleStruct.instance("my_common_struct")
+            .set("foo", 123)
+            .set("bar", 123));
+
+        flexibleStruct = new Struct(AllTypeMessageData.SCHEMA_1)
+            .set("my_boolean", false)
+            .set("my_int8", (byte) 12)
+            .set("my_int16", (short) 123)
+            .set("my_uint16", 33000)
+            .set("my_int32", 1234)
+            .set("my_uint32", 1234567L)
+            .set("my_uint64", 0xcafcacafcacafcaL)
+            .set("my_uuid", Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"))
+            .set("my_float64", 12.34D)
+            .set("my_compact_string", "compact string")
+            .set("my_compact_nullable_string", null)
+            .set("my_compact_bytes", ByteBuffer.wrap("compact 
bytes".getBytes()))
+            .set("my_compact_nullable_bytes", null)
+            .set("my_compact_records", MemoryRecords.EMPTY)
+            .set("my_compact_nullable_records", null)
+            .set("my_int_array", new Object[] {})
+            .set("my_nullable_int_array", null)
+            .set("_tagged_fields", new TreeMap<Integer, Field>());
+        flexibleStruct.set("my_common_struct", 
flexibleStruct.instance("my_common_struct")
+            .set("foo", 123)
+            .set("bar", 123)
+            .set("_tagged_fields", new TreeMap<Integer, Field>()));
+
+        messageData = new AllTypeMessageData();
+    }
+
+    @Test
+    public void testNonFlexibleWithNullValue() {
+        messageData.setMyBytes("bytes".getBytes());
+        messageData.setMyRecords(MemoryRecords.EMPTY);
+
+        checkSchemaAndMessageSerializationConsistency((short) 0, messageData, 
nonFlexibleStruct);
+    }
+
+    @Test
+    public void testNonFlexibleWithNotNullValue() {

Review Comment:
   NotNullValue => NonNullValue



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