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 98538100260 Add more test cases on MySQLBinlogRowsEventPacketTest
(#38179)
98538100260 is described below
commit 985381002601760a1c0df7272227eea8c7c569d4
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Feb 24 19:19:14 2026 +0800
Add more test cases on MySQLBinlogRowsEventPacketTest (#38179)
---
.../binlog/row/MySQLBinlogRowsEventPacket.java | 1 -
.../binlog/row/MySQLBinlogRowsEventPacketTest.java | 102 ++++++++++++++++-----
2 files changed, 78 insertions(+), 25 deletions(-)
diff --git
a/database/protocol/dialect/mysql/src/main/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacket.java
b/database/protocol/dialect/mysql/src/main/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacket.java
index 611b9f42d36..94ae7ae2990 100644
---
a/database/protocol/dialect/mysql/src/main/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacket.java
+++
b/database/protocol/dialect/mysql/src/main/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacket.java
@@ -111,6 +111,5 @@ public final class MySQLBinlogRowsEventPacket extends
AbstractMySQLBinlogEventPa
@Override
protected void writeEvent(final MySQLPacketPayload payload) {
- // TODO
}
}
diff --git
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
index 6d46acbb1fc..77a404bd1a1 100644
---
a/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
+++
b/database/protocol/dialect/mysql/src/test/java/org/apache/shardingsphere/database/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
@@ -19,27 +19,27 @@ package
org.apache.shardingsphere.database.protocol.mysql.packet.binlog.row;
import io.netty.buffer.ByteBuf;
import
org.apache.shardingsphere.database.protocol.mysql.constant.MySQLBinaryColumnType;
+import
org.apache.shardingsphere.database.protocol.mysql.constant.MySQLBinlogEventType;
import
org.apache.shardingsphere.database.protocol.mysql.packet.binlog.MySQLBinlogEventHeader;
import
org.apache.shardingsphere.database.protocol.mysql.packet.binlog.row.column.MySQLBinlogColumnDef;
import
org.apache.shardingsphere.database.protocol.mysql.payload.MySQLPacketPayload;
-import org.junit.jupiter.api.BeforeEach;
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.Mock;
-import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.nio.charset.StandardCharsets;
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.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -55,31 +55,85 @@ class MySQLBinlogRowsEventPacketTest {
@Mock
private MySQLBinlogEventHeader binlogEventHeader;
- private List<MySQLBinlogColumnDef> columnDefs;
+ @Mock
+ private MySQLBinlogTableMapEventPacket tableMapEventPacket;
- @BeforeEach
- void setUp() {
- columnDefs = Collections.singletonList(new
MySQLBinlogColumnDef(MySQLBinaryColumnType.LONGLONG));
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("assertNewArguments")
+ void assertNew(final String name, final int eventType, final int
expectedSkipReservedInvocationCount, final boolean
expectedHasColumnsPresentBitmap2) {
+ when(binlogEventHeader.getEventType()).thenReturn(eventType);
when(payload.readInt6()).thenReturn(1L);
- when(payload.readInt2()).thenReturn(2);
+ when(payload.readInt2()).thenReturn(2, 4);
when(payload.readIntLenenc()).thenReturn(1L);
+ when(payload.readInt1()).thenReturn(0, 0);
+ MySQLBinlogRowsEventPacket actual = new
MySQLBinlogRowsEventPacket(binlogEventHeader, payload);
+ assertThat(actual.getTableId(), is(1L));
+ assertThat(actual.getFlags(), is(2));
+ verify(payload,
times(expectedSkipReservedInvocationCount)).skipReserved(2);
+ assertThat(actual.getColumnNumber(), is(1));
+ assertFalse(actual.getColumnsPresentBitmap().isNullParameter(0));
+ assertThat(null != actual.getColumnsPresentBitmap2(),
is(expectedHasColumnsPresentBitmap2));
}
@Test
- void assertReadWriteRowV1WithoutNullValue() throws
InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+ void assertReadRowsWithWriteRowsEvent() {
+
when(binlogEventHeader.getEventType()).thenReturn(MySQLBinlogEventType.WRITE_ROWS_EVENT_V1.getValue());
+ when(binlogEventHeader.getEventSize()).thenReturn(2);
+ when(binlogEventHeader.getChecksumLength()).thenReturn(0);
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.readerIndex()).thenReturn(0, 0, 3, 3);
+ when(payload.readInt6()).thenReturn(1L);
+ when(payload.readInt2()).thenReturn(2, 4);
+ when(payload.readIntLenenc()).thenReturn(1L);
+ when(payload.readInt1()).thenReturn(0, 0);
+ when(payload.readInt8()).thenReturn(10L);
+
when(tableMapEventPacket.getColumnDefs()).thenReturn(Collections.singletonList(new
MySQLBinlogColumnDef(MySQLBinaryColumnType.LONGLONG)));
MySQLBinlogRowsEventPacket actual = new
MySQLBinlogRowsEventPacket(binlogEventHeader, payload);
- assertBinlogRowsEventV1BeforeRows(actual);
- assertFalse(actual.getColumnsPresentBitmap().isNullParameter(0));
- assertNull(actual.getColumnsPresentBitmap2());
- MySQLPacketPayload packetPayload = new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8);
- assertThat(((Serializable[]) Plugins.getMemberAccessor()
-
.invoke(MySQLBinlogRowsEventPacket.class.getDeclaredMethod("readRow",
List.class, MySQLPacketPayload.class), actual, columnDefs, packetPayload))[0],
is(0L));
+ actual.readRows(tableMapEventPacket, payload);
+ assertThat(actual.getRows().size(), is(1));
+ assertThat(actual.getRows2().size(), is(0));
+ assertThat(actual.getRows().get(0)[0], is((Object) 10L));
}
- private void assertBinlogRowsEventV1BeforeRows(final
MySQLBinlogRowsEventPacket actual) {
- assertThat(actual.getTableId(), is(1L));
- assertThat(actual.getFlags(), is(2));
- verify(payload, never()).skipReserved(2);
- assertThat(actual.getColumnNumber(), is(1));
+ @Test
+ void assertReadRowsWithUpdateRowsEvent() {
+
when(binlogEventHeader.getEventType()).thenReturn(MySQLBinlogEventType.UPDATE_ROWS_EVENT_V1.getValue());
+ when(binlogEventHeader.getEventSize()).thenReturn(2);
+ when(binlogEventHeader.getChecksumLength()).thenReturn(0);
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.readerIndex()).thenReturn(0, 0, 3, 3);
+ when(payload.readInt6()).thenReturn(1L);
+ when(payload.readInt2()).thenReturn(2, 4);
+ when(payload.readIntLenenc()).thenReturn(1L);
+ when(payload.readInt1()).thenReturn(0, 0, 1, 0);
+ when(payload.readInt8()).thenReturn(11L);
+
when(tableMapEventPacket.getColumnDefs()).thenReturn(Collections.singletonList(new
MySQLBinlogColumnDef(MySQLBinaryColumnType.LONGLONG)));
+ MySQLBinlogRowsEventPacket actual = new
MySQLBinlogRowsEventPacket(binlogEventHeader, payload);
+ actual.readRows(tableMapEventPacket, payload);
+ assertThat(actual.getRows().size(), is(1));
+ assertThat(actual.getRows2().size(), is(1));
+ assertNull(actual.getRows().get(0)[0]);
+ assertThat(actual.getRows2().get(0)[0], is((Object) 11L));
+ }
+
+ @Test
+ void assertWrite() {
+ when(payload.readInt6()).thenReturn(1L);
+ when(payload.readInt2()).thenReturn(2, 4);
+ when(payload.readIntLenenc()).thenReturn(1L);
+ when(payload.readInt1()).thenReturn(0, 0);
+ MySQLBinlogEventHeader eventHeader = new MySQLBinlogEventHeader(1,
MySQLBinlogEventType.WRITE_ROWS_EVENT_V1.getValue(), 1, 1, 1, 1, 0);
+ MySQLPacketPayload writePayload = mock(MySQLPacketPayload.class);
+ new MySQLBinlogRowsEventPacket(eventHeader,
payload).write(writePayload);
+
verify(writePayload).writeInt1(MySQLBinlogEventType.WRITE_ROWS_EVENT_V1.getValue());
+ }
+
+ private static Stream<Arguments> assertNewArguments() {
+ return Stream.of(
+ Arguments.of("write rows event v2",
MySQLBinlogEventType.WRITE_ROWS_EVENT_V2.getValue(), 1, false),
+ Arguments.of("update rows event v2",
MySQLBinlogEventType.UPDATE_ROWS_EVENT_V2.getValue(), 1, true),
+ Arguments.of("delete rows event v2",
MySQLBinlogEventType.DELETE_ROWS_EVENT_V2.getValue(), 1, false),
+ Arguments.of("update rows event v1",
MySQLBinlogEventType.UPDATE_ROWS_EVENT_V1.getValue(), 0, true),
+ Arguments.of("write rows event v1",
MySQLBinlogEventType.WRITE_ROWS_EVENT_V1.getValue(), 0, false));
}
}