This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d59d3401089 Add more test cases on MySQL query.binary.execute package 
(#38188)
d59d3401089 is described below

commit d59d340108919fc9bd7a61bc66f75a2e68426556
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 25 12:12:50 2026 +0800

    Add more test cases on MySQL query.binary.execute package (#38188)
---
 .../execute/MySQLComStmtExecutePacketTest.java     | 125 +++++++----
 .../protocol/MySQLDateBinaryProtocolValueTest.java | 234 +++++++++------------
 .../protocol/MySQLInt4BinaryProtocolValueTest.java |  31 ++-
 .../protocol/MySQLInt8BinaryProtocolValueTest.java |  24 ++-
 4 files changed, 234 insertions(+), 180 deletions(-)

diff --git 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/MySQLComStmtExecutePacketTest.java
 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/MySQLComStmtExecutePacketTest.java
index 042437f3ec0..35c53341bbf 100644
--- 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/MySQLComStmtExecutePacketTest.java
+++ 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/MySQLComStmtExecutePacketTest.java
@@ -21,92 +21,145 @@ import io.netty.buffer.Unpooled;
 import 
org.apache.shardingsphere.database.protocol.mysql.constant.MySQLBinaryColumnType;
 import 
org.apache.shardingsphere.database.protocol.mysql.constant.MySQLNewParametersBoundFlag;
 import 
org.apache.shardingsphere.database.protocol.mysql.packet.command.query.binary.MySQLPreparedStatementParameterType;
+import 
org.apache.shardingsphere.database.protocol.mysql.packet.command.query.MySQLColumnDefinitionFlag;
 import 
org.apache.shardingsphere.database.protocol.mysql.payload.MySQLPacketPayload;
+import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import java.nio.charset.StandardCharsets;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class MySQLComStmtExecutePacketTest {
     
-    @Test
-    void assertNewWithoutParameter() {
-        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00};
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("withoutParameterArguments")
+    void assertNewWithoutParameter(final String name, final byte[] data, final 
int expectedStatementId, final int expectedFlags) {
         MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
         MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 0);
-        assertThat(actual.getStatementId(), is(1));
+        assertThat(actual.getStatementId(), is(expectedStatementId));
+        assertThat(actual.getFlags(), is(expectedFlags));
         assertNull(actual.getNewParametersBoundFlag());
         assertTrue(actual.getNewParameterTypes().isEmpty());
     }
     
     @Test
-    void assertNewParameterBoundWithNotNullParameters() throws SQLException {
+    void assertNewWithInvalidIterationCount() {
+        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x02, 0x00, 0x00, 0x00};
+        MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
+        assertThrows(IllegalArgumentException.class, () -> new 
MySQLComStmtExecutePacket(payload, 0));
+    }
+    
+    @Test
+    void assertNewWithParameterTypeNotExist() {
+        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x00};
+        MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
+        MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 1);
+        assertThat(actual.getNewParametersBoundFlag(), 
is(MySQLNewParametersBoundFlag.PARAMETER_TYPE_NOT_EXIST));
+        assertTrue(actual.getNewParameterTypes().isEmpty());
+    }
+    
+    @Test
+    void assertReadParametersWithSignedInteger() throws SQLException {
         byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00};
         MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
         MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 1);
-        assertThat(actual.getStatementId(), is(1));
-        assertThat(actual.getNewParametersBoundFlag(), 
is(MySQLNewParametersBoundFlag.PARAMETER_TYPE_EXIST));
         List<MySQLPreparedStatementParameterType> parameterTypes = 
actual.getNewParameterTypes();
-        assertThat(parameterTypes.size(), is(1));
-        assertThat(parameterTypes.get(0).getColumnType(), 
is(MySQLBinaryColumnType.LONG));
-        assertThat(parameterTypes.get(0).getUnsignedFlag(), is(0));
         assertThat(actual.readParameters(parameterTypes, 
Collections.emptySet(), Collections.singletonList(0), Collections.emptyList()), 
is(Collections.<Object>singletonList(1)));
     }
     
     @Test
-    void assertNewWithNullParameters() throws SQLException {
-        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x01, 0x01, 0x03, 0x00};
+    void assertReadParametersWithUnsignedInteger() throws SQLException {
+        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x01, 0x03, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};
         MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
         MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 1);
-        assertThat(actual.getStatementId(), is(1));
-        assertThat(actual.getNewParametersBoundFlag(), 
is(MySQLNewParametersBoundFlag.PARAMETER_TYPE_EXIST));
         List<MySQLPreparedStatementParameterType> parameterTypes = 
actual.getNewParameterTypes();
-        assertThat(parameterTypes.size(), is(1));
-        assertThat(parameterTypes.get(0).getColumnType(), 
is(MySQLBinaryColumnType.LONG));
-        assertThat(parameterTypes.get(0).getUnsignedFlag(), is(0));
-        assertThat(actual.readParameters(parameterTypes, 
Collections.emptySet(), Collections.emptyList(), Collections.emptyList()), 
is(Collections.singletonList(null)));
+        int unsignedFlag = MySQLColumnDefinitionFlag.UNSIGNED.getValue();
+        assertThat(actual.readParameters(parameterTypes, 
Collections.emptySet(), Collections.singletonList(unsignedFlag), 
Collections.emptyList()), is(Collections.<Object>singletonList(4294967295L)));
     }
     
     @Test
-    void assertNewWithLongDataParameter() throws SQLException {
-        byte[] data = {0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x01, (byte) 0xfc, 0x00};
+    void assertReadParametersWithNullParameter() throws SQLException {
+        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x01, 0x01, 0x03, 0x00};
         MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
         MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 1);
-        assertThat(actual.getStatementId(), is(2));
-        assertThat(actual.getNewParametersBoundFlag(), 
is(MySQLNewParametersBoundFlag.PARAMETER_TYPE_EXIST));
         List<MySQLPreparedStatementParameterType> parameterTypes = 
actual.getNewParameterTypes();
-        assertThat(parameterTypes.size(), is(1));
-        assertThat(parameterTypes.get(0).getColumnType(), 
is(MySQLBinaryColumnType.BLOB));
-        assertThat(parameterTypes.get(0).getUnsignedFlag(), is(0));
-        assertThat(actual.readParameters(parameterTypes, 
Collections.singleton(0), Collections.emptyList(), Collections.emptyList()), 
is(Collections.singletonList(null)));
+        List<Integer> parameterFlags = Collections.singletonList(0);
+        assertThat(actual.readParameters(parameterTypes, 
Collections.emptySet(), parameterFlags, Collections.emptyList()), 
is(Collections.singletonList(null)));
     }
     
     @Test
-    void assertNewWithStringParameterBoundToVarStringColumn() throws 
SQLException {
-        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x01, (byte) 0xfe, 0x00, 0x01, 0x61};
+    void assertReadParametersWithLongDataParameter() throws SQLException {
+        byte[] data = {0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x01, (byte) 0xfc, 0x00};
         MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
         MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 1);
         List<MySQLPreparedStatementParameterType> parameterTypes = 
actual.getNewParameterTypes();
-        assertThat(actual.readParameters(parameterTypes, 
Collections.emptySet(), Collections.singletonList(0), 
Collections.singletonList(MySQLBinaryColumnType.VAR_STRING)),
-                is(Collections.<Object>singletonList("a")));
+        assertThat(actual.readParameters(parameterTypes, 
Collections.singleton(0), Collections.emptyList(), Collections.emptyList()), 
is(Collections.singletonList(null)));
     }
     
-    @Test
-    void assertNewWithStringParameterBoundToBlobColumn() throws SQLException {
-        byte[] data = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x01, (byte) 0xfe, 0x00, 0x01, 0x61};
+    @DisplayName("assertReadParametersWithStringDecoding")
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("stringDecodingArguments")
+    void assertReadParametersWithStringDecoding(final String name, final 
MySQLBinaryColumnType parameterType,
+                                                final 
List<MySQLBinaryColumnType> parameterColumnTypes, final boolean expectedString) 
throws SQLException {
+        byte[] data = createPacketData(parameterType);
         MySQLPacketPayload payload = new 
MySQLPacketPayload(Unpooled.wrappedBuffer(data), StandardCharsets.UTF_8);
         MySQLComStmtExecutePacket actual = new 
MySQLComStmtExecutePacket(payload, 1);
         List<MySQLPreparedStatementParameterType> parameterTypes = 
actual.getNewParameterTypes();
-        Object actualValue = actual.readParameters(parameterTypes, 
Collections.emptySet(), Collections.singletonList(0), 
Collections.singletonList(MySQLBinaryColumnType.BLOB)).get(0);
-        assertTrue(actualValue instanceof byte[]);
+        List<Integer> parameterFlags = Collections.singletonList(0);
+        Object actualValue = actual.readParameters(parameterTypes, 
Collections.emptySet(), parameterFlags, parameterColumnTypes).get(0);
+        assertThat(actualValue instanceof String, is(expectedString));
+        if (expectedString) {
+            assertThat(actualValue, is("a"));
+            return;
+        }
         assertArrayEquals(new byte[]{0x61}, (byte[]) actualValue);
     }
+    
+    private static Stream<Arguments> stringDecodingArguments() {
+        return Stream.of(
+                Arguments.of("string-column", MySQLBinaryColumnType.STRING, 
Collections.singletonList(MySQLBinaryColumnType.STRING), true),
+                Arguments.of("var-string-column", 
MySQLBinaryColumnType.STRING, 
Collections.singletonList(MySQLBinaryColumnType.VAR_STRING), true),
+                Arguments.of("varchar-column", MySQLBinaryColumnType.STRING, 
Collections.singletonList(MySQLBinaryColumnType.VARCHAR), true),
+                Arguments.of("blob-column", MySQLBinaryColumnType.STRING, 
Collections.singletonList(MySQLBinaryColumnType.BLOB), false),
+                Arguments.of("missing-column-type", 
MySQLBinaryColumnType.STRING, Collections.emptyList(), false),
+                Arguments.of("blob-parameter-type", 
MySQLBinaryColumnType.BLOB, 
Collections.singletonList(MySQLBinaryColumnType.VAR_STRING), false));
+    }
+    
+    private static Stream<Arguments> withoutParameterArguments() {
+        return Stream.of(
+                Arguments.of("statement-id-1", new byte[]{0x01, 0x00, 0x00, 
0x00, 0x09, 0x01, 0x00, 0x00, 0x00}, 1, 9),
+                Arguments.of("statement-id-2", new byte[]{0x02, 0x00, 0x00, 
0x00, 0x05, 0x01, 0x00, 0x00, 0x00}, 2, 5),
+                Arguments.of("statement-id-256", new byte[]{0x00, 0x01, 0x00, 
0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, 256, 0));
+    }
+    
+    private byte[] createPacketData(final MySQLBinaryColumnType parameterType) 
{
+        List<Byte> result = new ArrayList<>();
+        byte[] fixedPrefix = {0x01, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 
0x00, 0x00, 0x01};
+        for (byte each : fixedPrefix) {
+            result.add(each);
+        }
+        result.add((byte) parameterType.getValue());
+        result.add((byte) 0x00);
+        result.add((byte) 0x01);
+        result.add((byte) 0x61);
+        byte[] bytes = new byte[result.size()];
+        for (int i = 0; i < result.size(); i++) {
+            bytes[i] = result.get(i);
+        }
+        return bytes;
+    }
 }
diff --git 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLDateBinaryProtocolValueTest.java
 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLDateBinaryProtocolValueTest.java
index b69a178ffd0..7a001f31765 100644
--- 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLDateBinaryProtocolValueTest.java
+++ 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLDateBinaryProtocolValueTest.java
@@ -20,19 +20,29 @@ package 
org.apache.shardingsphere.database.protocol.mysql.packet.command.query.b
 import 
org.apache.shardingsphere.database.protocol.mysql.payload.MySQLPacketPayload;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InOrder;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
 import java.sql.Timestamp;
-import java.time.Instant;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.ZoneId;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -44,45 +54,24 @@ class MySQLDateBinaryProtocolValueTest {
     
     @Test
     void assertReadWithZeroByte() {
+        when(payload.readInt1()).thenReturn(0);
         assertThrows(SQLFeatureNotSupportedException.class, () -> new 
MySQLDateBinaryProtocolValue().read(payload, false));
     }
     
-    @Test
-    void assertReadWithFourBytes() throws SQLException {
-        when(payload.readInt1()).thenReturn(4, 12, 31);
-        when(payload.readInt2()).thenReturn(2018);
-        LocalDateTime actual = 
LocalDateTime.ofInstant(Instant.ofEpochMilli(((Timestamp) new 
MySQLDateBinaryProtocolValue().read(payload, false)).getTime()), 
ZoneId.systemDefault());
-        assertThat(actual.getYear(), is(2018));
-        assertThat(actual.getMonthValue(), is(12));
-        assertThat(actual.getDayOfMonth(), is(31));
-    }
-    
-    @Test
-    void assertReadWithSevenBytes() throws SQLException {
-        when(payload.readInt1()).thenReturn(7, 12, 31, 10, 59, 0);
-        when(payload.readInt2()).thenReturn(2018);
-        LocalDateTime actual = 
LocalDateTime.ofInstant(Instant.ofEpochMilli(((Timestamp) new 
MySQLDateBinaryProtocolValue().read(payload, false)).getTime()), 
ZoneId.systemDefault());
-        assertThat(actual.getYear(), is(2018));
-        assertThat(actual.getMonthValue(), is(12));
-        assertThat(actual.getDayOfMonth(), is(31));
-        assertThat(actual.getHour(), is(10));
-        assertThat(actual.getMinute(), is(59));
-        assertThat(actual.getSecond(), is(0));
-    }
-    
-    @Test
-    void assertReadWithElevenBytes() throws SQLException {
-        when(payload.readInt1()).thenReturn(11, 12, 31, 10, 59, 0);
-        when(payload.readInt2()).thenReturn(2018);
-        when(payload.readInt4()).thenReturn(230000);
-        LocalDateTime actual = 
LocalDateTime.ofInstant(Instant.ofEpochMilli(((Timestamp) new 
MySQLDateBinaryProtocolValue().read(payload, false)).getTime()), 
ZoneId.systemDefault());
-        assertThat(actual.getYear(), is(2018));
-        assertThat(actual.getMonthValue(), is(12));
-        assertThat(actual.getDayOfMonth(), is(31));
-        assertThat(actual.getHour(), is(10));
-        assertThat(actual.getMinute(), is(59));
-        assertThat(actual.getSecond(), is(0));
-        assertThat(actual.getNano(), is(230000000));
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("readArguments")
+    void assertRead(final String name, final int[] readInt1Values, final int 
year, final int microseconds, final LocalDateTime expected) throws SQLException 
{
+        Integer[] tailValues = new Integer[readInt1Values.length - 1];
+        for (int i = 1; i < readInt1Values.length; i++) {
+            tailValues[i - 1] = readInt1Values[i];
+        }
+        when(payload.readInt1()).thenReturn(readInt1Values[0], tailValues);
+        when(payload.readInt2()).thenReturn(year);
+        if (0 <= microseconds) {
+            when(payload.readInt4()).thenReturn(microseconds);
+        }
+        Timestamp actual = (Timestamp) new 
MySQLDateBinaryProtocolValue().read(payload, false);
+        assertThat(actual.toLocalDateTime(), is(expected));
     }
     
     @Test
@@ -91,106 +80,91 @@ class MySQLDateBinaryProtocolValueTest {
         assertThrows(SQLFeatureNotSupportedException.class, () -> new 
MySQLDateBinaryProtocolValue().read(payload, false));
     }
     
-    @Test
-    void assertWriteLocalDateTimeTypeFourBytes() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, LocalDateTime.of(1970, 1, 14, 0, 0, 0));
-        verify(payload).writeInt1(4);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("writeArguments")
+    void assertWrite(final String name, final Object value, final int 
expectedLength, final int year, final int month,
+                     final int dayOfMonth, final int hour, final int minute, 
final int second, final Integer expectedMicroseconds) {
+        new MySQLDateBinaryProtocolValue().write(payload, value);
+        verify(payload).writeInt2(year);
+        List<Integer> expectedValues = new LinkedList<>();
+        expectedValues.add(expectedLength);
+        expectedValues.add(month);
+        expectedValues.add(dayOfMonth);
+        if (4 != expectedLength) {
+            expectedValues.add(hour);
+            expectedValues.add(minute);
+            expectedValues.add(second);
+        }
+        ArgumentCaptor<Integer> int1Captor = 
ArgumentCaptor.forClass(Integer.class);
+        verify(payload, 
times(expectedValues.size())).writeInt1(int1Captor.capture());
+        if (11 == expectedLength) {
+            verify(payload).writeInt4(expectedMicroseconds);
+        }
+        assertThat(int1Captor.getAllValues(), is(expectedValues));
     }
     
     @Test
-    void assertWriteLocalDateTimeTypeSevenBytes() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, LocalDateTime.of(1970, 1, 14, 12, 10, 30));
-        verify(payload).writeInt1(7);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
-        verify(payload).writeInt1(12);
-        verify(payload).writeInt1(10);
-        verify(payload).writeInt1(30);
+    void assertWriteWithNanoOverflowWithoutSecondCarry() {
+        LocalDateTime dateTime = mock(LocalDateTime.class);
+        when(dateTime.getYear()).thenReturn(2026);
+        when(dateTime.getMonthValue()).thenReturn(1);
+        when(dateTime.getDayOfMonth()).thenReturn(2);
+        when(dateTime.getHour()).thenReturn(3);
+        when(dateTime.getMinute()).thenReturn(4);
+        when(dateTime.getSecond()).thenReturn(10);
+        when(dateTime.getNano()).thenReturn(1_000_000_001);
+        new MySQLDateBinaryProtocolValue().write(payload, dateTime);
+        InOrder inOrder = inOrder(payload);
+        inOrder.verify(payload).writeInt1(11);
+        inOrder.verify(payload).writeInt2(2026);
+        inOrder.verify(payload).writeInt1(1);
+        inOrder.verify(payload).writeInt1(2);
+        inOrder.verify(payload).writeInt1(3);
+        inOrder.verify(payload).writeInt1(4);
+        inOrder.verify(payload).writeInt1(11);
+        inOrder.verify(payload).writeInt4(0);
     }
     
     @Test
-    void assertWriteWithFourBytes() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, Timestamp.valueOf("1970-01-14 0:0:0"));
-        verify(payload).writeInt1(4);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
+    void assertWriteWithNanoOverflowAndSecondCarry() {
+        LocalDateTime dateTime = mock(LocalDateTime.class);
+        LocalDateTime normalized = LocalDateTime.of(2026, 1, 2, 3, 4, 1);
+        when(dateTime.getYear()).thenReturn(2026);
+        when(dateTime.getMonthValue()).thenReturn(1);
+        when(dateTime.getDayOfMonth()).thenReturn(2);
+        when(dateTime.getHour()).thenReturn(3);
+        when(dateTime.getMinute()).thenReturn(4);
+        when(dateTime.getSecond()).thenReturn(59);
+        when(dateTime.getNano()).thenReturn(2_000_000_000);
+        when(dateTime.plusSeconds(2)).thenReturn(normalized);
+        new MySQLDateBinaryProtocolValue().write(payload, dateTime);
+        verify(dateTime).plusSeconds(2);
+        InOrder inOrder = inOrder(payload);
+        inOrder.verify(payload).writeInt1(7);
+        inOrder.verify(payload).writeInt2(2026);
+        inOrder.verify(payload).writeInt1(1);
+        inOrder.verify(payload).writeInt1(2);
+        inOrder.verify(payload).writeInt1(3);
+        inOrder.verify(payload).writeInt1(4);
+        inOrder.verify(payload).writeInt1(1);
     }
     
-    @Test
-    void assertWriteWithSevenBytes() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, Timestamp.valueOf("1970-01-14 12:10:30"));
-        verify(payload).writeInt1(7);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
-        verify(payload).writeInt1(12);
-        verify(payload).writeInt1(10);
-        verify(payload).writeInt1(30);
+    private static Stream<Arguments> readArguments() {
+        return Stream.of(
+                Arguments.of("four-bytes", new int[]{4, 12, 31}, 2018, -1, 
LocalDateTime.of(2018, 12, 31, 0, 0, 0)),
+                Arguments.of("seven-bytes", new int[]{7, 12, 31, 10, 59, 0}, 
2018, -1, LocalDateTime.of(2018, 12, 31, 10, 59, 0)),
+                Arguments.of("eleven-bytes", new int[]{11, 12, 31, 10, 59, 0}, 
2018, 230000, LocalDateTime.of(2018, 12, 31, 10, 59, 0, 230000000)));
     }
     
-    @Test
-    void assertWriteWithElevenBytes() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, Timestamp.valueOf("1970-01-14 12:10:30.123"));
-        verify(payload).writeInt1(11);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
-        verify(payload).writeInt1(12);
-        verify(payload).writeInt1(10);
-        verify(payload).writeInt1(30);
-        verify(payload).writeInt4(123000);
-    }
-    
-    @Test
-    void assertWriteLocalDateTimeWithMaxNanos() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        LocalDateTime dateTime = LocalDateTime.of(1970, 1, 14, 12, 10, 29, 
999_999_999);
-        actual.write(payload, dateTime);
-        verify(payload).writeInt1(11);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
-        verify(payload).writeInt1(12);
-        verify(payload).writeInt1(10);
-        verify(payload).writeInt1(29);
-        verify(payload).writeInt4(999999);
-    }
-    
-    @Test
-    void assertWriteLocalDateTimeWithBoundaryNanos() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, LocalDateTime.of(1970, 1, 14, 12, 10, 29, 1000));
-        verify(payload).writeInt1(11);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
-        verify(payload).writeInt1(12);
-        verify(payload).writeInt1(10);
-        verify(payload).writeInt1(29);
-        verify(payload).writeInt4(1);
-    }
-    
-    @Test
-    void assertWriteLocalDateTimeWithMicrosecondPrecision() {
-        MySQLDateBinaryProtocolValue actual = new 
MySQLDateBinaryProtocolValue();
-        actual.write(payload, LocalDateTime.of(1970, 1, 14, 12, 10, 29, 
123456789));
-        verify(payload).writeInt1(11);
-        verify(payload).writeInt2(1970);
-        verify(payload).writeInt1(1);
-        verify(payload).writeInt1(14);
-        verify(payload).writeInt1(12);
-        verify(payload).writeInt1(10);
-        verify(payload).writeInt1(29);
-        verify(payload).writeInt4(123456);
+    private static Stream<Arguments> writeArguments() {
+        return Stream.of(
+                Arguments.of("local-date", LocalDate.of(1970, 1, 14), 4, 1970, 
1, 14, 0, 0, 0, null),
+                Arguments.of("local-date-time-date-only", 
LocalDateTime.of(1970, 1, 14, 0, 0, 0), 4, 1970, 1, 14, 0, 0, 0, null),
+                Arguments.of("local-date-time-minute-only", 
LocalDateTime.of(1970, 1, 14, 0, 1, 0), 7, 1970, 1, 14, 0, 1, 0, null),
+                Arguments.of("local-date-time-second-only", 
LocalDateTime.of(1970, 1, 14, 0, 0, 1), 7, 1970, 1, 14, 0, 0, 1, null),
+                Arguments.of("local-date-time-with-time", 
LocalDateTime.of(1970, 1, 14, 12, 10, 30), 7, 1970, 1, 14, 12, 10, 30, null),
+                Arguments.of("timestamp-with-time", 
Timestamp.valueOf("1970-01-14 12:10:30"), 7, 1970, 1, 14, 12, 10, 30, null),
+                Arguments.of("timestamp-with-microseconds", 
Timestamp.valueOf("1970-01-14 12:10:30.123"), 11, 1970, 1, 14, 12, 10, 30, 
123000),
+                Arguments.of("time-absent-with-nanos", LocalDateTime.of(1970, 
1, 14, 0, 0, 0, 1_000), 11, 1970, 1, 14, 0, 0, 0, 1));
     }
 }
diff --git 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValueTest.java
 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValueTest.java
index 70c7dfd751d..5cda09a440d 100644
--- 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValueTest.java
+++ 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValueTest.java
@@ -20,10 +20,16 @@ package 
org.apache.shardingsphere.database.protocol.mysql.packet.command.query.b
 import io.netty.buffer.Unpooled;
 import 
org.apache.shardingsphere.database.protocol.mysql.payload.MySQLPacketPayload;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
+import java.math.BigDecimal;
+import java.util.stream.Stream;
+
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.verify;
@@ -36,15 +42,28 @@ class MySQLInt4BinaryProtocolValueTest {
     private MySQLPacketPayload payload;
     
     @Test
-    void assertRead() {
-        when(payload.getByteBuf()).thenReturn(Unpooled.wrappedBuffer(new 
byte[]{1, 0, 0, 0, 1, 0, 0, 0}));
+    void assertReadWithSigned() {
+        when(payload.getByteBuf()).thenReturn(Unpooled.wrappedBuffer(new 
byte[]{1, 0, 0, 0}));
         assertThat(new MySQLInt4BinaryProtocolValue().read(payload, false), 
is(1));
-        assertThat(new MySQLInt4BinaryProtocolValue().read(payload, true), 
is(1L));
     }
     
     @Test
-    void assertWrite() {
-        new MySQLInt4BinaryProtocolValue().write(payload, 1);
-        verify(payload).writeInt4(1);
+    void assertReadWithUnsigned() {
+        when(payload.getByteBuf()).thenReturn(Unpooled.wrappedBuffer(new 
byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}));
+        assertThat(new MySQLInt4BinaryProtocolValue().read(payload, true), 
is(4294967295L));
+    }
+    
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("writeArguments")
+    void assertWrite(final String name, final Object value, final int 
expectedValue) {
+        new MySQLInt4BinaryProtocolValue().write(payload, value);
+        verify(payload).writeInt4(expectedValue);
+    }
+    
+    private static Stream<Arguments> writeArguments() {
+        return Stream.of(
+                Arguments.of("big-decimal", new BigDecimal("1"), 1),
+                Arguments.of("integer", 1, 1),
+                Arguments.of("long", 1L, 1));
     }
 }
diff --git 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt8BinaryProtocolValueTest.java
 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt8BinaryProtocolValueTest.java
index 92ad610a7ec..1c614c9eba9 100644
--- 
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt8BinaryProtocolValueTest.java
+++ 
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt8BinaryProtocolValueTest.java
@@ -19,11 +19,16 @@ package 
org.apache.shardingsphere.database.protocol.mysql.packet.command.query.b
 
 import 
org.apache.shardingsphere.database.protocol.mysql.payload.MySQLPacketPayload;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.stream.Stream;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -42,15 +47,18 @@ class MySQLInt8BinaryProtocolValueTest {
         assertThat(new MySQLInt8BinaryProtocolValue().read(payload, false), 
is(1L));
     }
     
-    @Test
-    void assertWriteWithLong() {
-        new MySQLInt8BinaryProtocolValue().write(payload, 1L);
-        verify(payload).writeInt8(1L);
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("writeArguments")
+    void assertWrite(final String name, final Object value, final long 
expectedValue) {
+        new MySQLInt8BinaryProtocolValue().write(payload, value);
+        verify(payload).writeInt8(expectedValue);
     }
     
-    @Test
-    void assertWriteWithBigDecimal() {
-        new MySQLInt8BinaryProtocolValue().write(payload, new BigDecimal(1L));
-        verify(payload).writeInt8(1L);
+    private static Stream<Arguments> writeArguments() {
+        return Stream.of(
+                Arguments.of("big-decimal", new BigDecimal("1"), 1L),
+                Arguments.of("integer", 1, 1L),
+                Arguments.of("big-integer", new BigInteger("1"), 1L),
+                Arguments.of("long", 1L, 1L));
     }
 }

Reply via email to