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 4c657d9bcf0 Add more test cases on
FirebirdGetBlobSegmentCommandExecutorTest (#37941)
4c657d9bcf0 is described below
commit 4c657d9bcf080ab6cea9089b7b61fe851002c6be
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 2 23:36:35 2026 +0800
Add more test cases on FirebirdGetBlobSegmentCommandExecutorTest (#37941)
---
.../FirebirdGetBlobSegmentCommandExecutorTest.java | 93 ++++++++++++++++++----
1 file changed, 79 insertions(+), 14 deletions(-)
diff --git
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/blob/FirebirdGetBlobSegmentCommandExecutorTest.java
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/blob/FirebirdGetBlobSegmentCommandExecutorTest.java
index 13e979bca51..e44de174340 100644
---
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/blob/FirebirdGetBlobSegmentCommandExecutorTest.java
+++
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/blob/FirebirdGetBlobSegmentCommandExecutorTest.java
@@ -17,16 +17,18 @@
package org.apache.shardingsphere.proxy.frontend.firebird.command.query.blob;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.database.protocol.firebird.packet.command.query.blob.FirebirdBlobRegistry;
import
org.apache.shardingsphere.database.protocol.firebird.packet.command.query.blob.FirebirdGetBlobSegmentCommandPacket;
+import
org.apache.shardingsphere.database.protocol.firebird.packet.command.query.blob.FirebirdGetBlobSegmentResponsePacket;
import
org.apache.shardingsphere.database.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
import org.apache.shardingsphere.database.protocol.packet.DatabasePacket;
import
org.apache.shardingsphere.proxy.frontend.firebird.command.query.blob.executors.FirebirdGetBlobSegmentCommandExecutor;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collection;
@@ -34,7 +36,7 @@ import java.util.Collection;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isA;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@@ -43,10 +45,7 @@ class FirebirdGetBlobSegmentCommandExecutorTest {
@Mock
private FirebirdGetBlobSegmentCommandPacket packet;
- @BeforeEach
- void setup() {
- FirebirdBlobRegistry.setSegment(new byte[]{1, 2, 3});
- }
+ private FirebirdGetBlobSegmentCommandExecutor executor;
@AfterEach
void tearDown() {
@@ -54,18 +53,84 @@ class FirebirdGetBlobSegmentCommandExecutorTest {
}
@Test
- void assertExecute() {
+ void assertExecuteWithNullSegment() {
+ FirebirdBlobRegistry.clearSegment();
+ when(packet.getBlobHandle()).thenReturn(7);
+ executor = new FirebirdGetBlobSegmentCommandExecutor(packet);
+ Collection<DatabasePacket> actualPackets = executor.execute();
+ assertThat(actualPackets.size(), is(1));
+ DatabasePacket actualResponsePacket = actualPackets.iterator().next();
+ assertThat(actualResponsePacket,
isA(FirebirdGenericResponsePacket.class));
+ FirebirdGenericResponsePacket actualGenericPacket =
(FirebirdGenericResponsePacket) actualResponsePacket;
+ assertThat(actualGenericPacket.getHandle(), is(7));
+ assertThat(actualGenericPacket.getData(),
isA(FirebirdGetBlobSegmentResponsePacket.class));
+ byte[] actualSegment = getResponseSegment(actualGenericPacket);
+ assertThat(actualSegment.length, is(0));
+ assertNull(FirebirdBlobRegistry.getSegment());
+ }
+
+ @Test
+ void assertExecuteWithZeroRequestedLength() {
+ FirebirdBlobRegistry.setSegment(new byte[]{9, 8});
+ when(packet.getSegmentLength()).thenReturn(0);
+ when(packet.getBlobHandle()).thenReturn(11);
+ executor = new FirebirdGetBlobSegmentCommandExecutor(packet);
+ Collection<DatabasePacket> actualPackets = executor.execute();
+ assertThat(actualPackets.size(), is(1));
+ DatabasePacket actualResponsePacket = actualPackets.iterator().next();
+ assertThat(actualResponsePacket,
isA(FirebirdGenericResponsePacket.class));
+ FirebirdGenericResponsePacket actualGenericPacket =
(FirebirdGenericResponsePacket) actualResponsePacket;
+ assertThat(actualGenericPacket.getHandle(), is(11));
+ byte[] actualSegment = getResponseSegment(actualGenericPacket);
+ assertThat(actualSegment.length, is(0));
+ byte[] actualRemainingSegment = FirebirdBlobRegistry.getSegment();
+ assertThat(actualRemainingSegment.length, is(2));
+ assertThat(actualRemainingSegment[0], is((byte) 9));
+ assertThat(actualRemainingSegment[1], is((byte) 8));
+ }
+
+ @Test
+ void assertExecuteWithPartialSegmentLeft() {
+ FirebirdBlobRegistry.setSegment(new byte[]{1, 2, 3});
when(packet.getSegmentLength()).thenReturn(2);
when(packet.getBlobHandle()).thenReturn(99);
- FirebirdGetBlobSegmentCommandExecutor executor = new
FirebirdGetBlobSegmentCommandExecutor(packet);
- Collection<DatabasePacket> actual = executor.execute();
- assertThat(actual.size(), is(1));
- DatabasePacket actualResponse = actual.iterator().next();
- assertThat(actualResponse, isA(FirebirdGenericResponsePacket.class));
- assertThat(((FirebirdGenericResponsePacket)
actualResponse).getHandle(), is(99));
+ executor = new FirebirdGetBlobSegmentCommandExecutor(packet);
+ Collection<DatabasePacket> actualPackets = executor.execute();
+ assertThat(actualPackets.size(), is(1));
+ DatabasePacket actualResponsePacket = actualPackets.iterator().next();
+ assertThat(actualResponsePacket,
isA(FirebirdGenericResponsePacket.class));
+ FirebirdGenericResponsePacket actualGenericPacket =
(FirebirdGenericResponsePacket) actualResponsePacket;
+ assertThat(actualGenericPacket.getHandle(), is(99));
+ byte[] actualSegment = getResponseSegment(actualGenericPacket);
+ assertThat(actualSegment.length, is(2));
+ assertThat(actualSegment[0], is((byte) 1));
+ assertThat(actualSegment[1], is((byte) 2));
byte[] actualRemainingSegment = FirebirdBlobRegistry.getSegment();
- assertNotNull(actualRemainingSegment);
assertThat(actualRemainingSegment.length, is(1));
assertThat(actualRemainingSegment[0], is((byte) 3));
}
+
+ @Test
+ void assertExecuteWithSegmentCleared() {
+ FirebirdBlobRegistry.setSegment(new byte[]{4, 5});
+ when(packet.getSegmentLength()).thenReturn(4);
+ when(packet.getBlobHandle()).thenReturn(15);
+ executor = new FirebirdGetBlobSegmentCommandExecutor(packet);
+ Collection<DatabasePacket> actualPackets = executor.execute();
+ assertThat(actualPackets.size(), is(1));
+ DatabasePacket actualResponsePacket = actualPackets.iterator().next();
+ assertThat(actualResponsePacket,
isA(FirebirdGenericResponsePacket.class));
+ FirebirdGenericResponsePacket actualGenericPacket =
(FirebirdGenericResponsePacket) actualResponsePacket;
+ assertThat(actualGenericPacket.getHandle(), is(15));
+ byte[] actualSegment = getResponseSegment(actualGenericPacket);
+ assertThat(actualSegment.length, is(2));
+ assertThat(actualSegment[0], is((byte) 4));
+ assertThat(actualSegment[1], is((byte) 5));
+ assertNull(FirebirdBlobRegistry.getSegment());
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private byte[] getResponseSegment(final FirebirdGenericResponsePacket
responsePacket) {
+ return (byte[])
Plugins.getMemberAccessor().get(FirebirdGetBlobSegmentResponsePacket.class.getDeclaredField("segment"),
responsePacket.getData());
+ }
}