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 126b1e638dc Add FirebirdStartTransactionPacketTest (#37602)
126b1e638dc is described below
commit 126b1e638dc8088cdb455fde45e8a34cafd1f9cb
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jan 1 14:40:53 2026 +0800
Add FirebirdStartTransactionPacketTest (#37602)
---
.../FirebirdStartTransactionPacket.java | 2 +-
.../FirebirdStartTransactionPacketTest.java | 114 +++++++++++++++++++++
.../FirebirdStartTransactionCommandExecutor.java | 2 +-
...irebirdStartTransactionCommandExecutorTest.java | 2 +-
4 files changed, 117 insertions(+), 3 deletions(-)
diff --git
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacket.java
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacket.java
index 3404a4d4397..6bbe0843e02 100644
---
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacket.java
+++
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacket.java
@@ -45,7 +45,7 @@ public final class FirebirdStartTransactionPacket extends
FirebirdCommandPacket
*
* @return auto commit or not
*/
- public boolean isAutocommit() {
+ public boolean isAutoCommit() {
return null !=
tpb.getValue(FirebirdTransactionParameterBufferType.AUTOCOMMIT);
}
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacketTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacketTest.java
new file mode 100644
index 00000000000..a163a831376
--- /dev/null
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/transaction/FirebirdStartTransactionPacketTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.shardingsphere.database.protocol.firebird.packet.command.query.transaction;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import lombok.SneakyThrows;
+import
org.apache.shardingsphere.database.protocol.firebird.constant.buffer.FirebirdParameterBuffer;
+import
org.apache.shardingsphere.database.protocol.firebird.constant.buffer.type.FirebirdTransactionParameterBufferType;
+import
org.apache.shardingsphere.database.protocol.firebird.payload.FirebirdPacketPayload;
+import
org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
+import org.junit.jupiter.api.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+class FirebirdStartTransactionPacketTest {
+
+ @Test
+ void assertIsAutoCommit() {
+ assertTrue(new FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.AUTOCOMMIT)).isAutoCommit());
+ assertFalse(new FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.READ)).isAutoCommit());
+ }
+
+ @Test
+ void assertIsReadOnly() {
+ assertTrue(new FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.READ)).isReadOnly());
+ assertFalse(new FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.AUTOCOMMIT)).isReadOnly());
+ }
+
+ @Test
+ void assertIsolationLevelReadCommitted() {
+ assertThat(new FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.READ_COMMITTED)).getIsolationLevel(),
is(TransactionIsolationLevel.READ_COMMITTED));
+ }
+
+ @Test
+ void assertIsolationLevelRepeatableRead() {
+ assertThat(new FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.CONCURRENCY)).getIsolationLevel(),
is(TransactionIsolationLevel.REPEATABLE_READ));
+ }
+
+ @Test
+ void assertIsolationLevelSerializable() {
+ FirebirdStartTransactionPacket packet = new
FirebirdStartTransactionPacket(createPayload(1,
FirebirdTransactionParameterBufferType.CONSISTENCY));
+
getParameterBuffer(packet).put(FirebirdTransactionParameterBufferType.CONCURRENCY,
false);
+ assertThat(packet.getIsolationLevel(),
is(TransactionIsolationLevel.SERIALIZABLE));
+ }
+
+ @Test
+ void assertIsolationLevelNone() {
+ FirebirdStartTransactionPacket packet = new
FirebirdStartTransactionPacket(createPayload(1));
+ Map<FirebirdTransactionParameterBufferType, Object> parameterBuffer =
getParameterBuffer(packet);
+
parameterBuffer.put(FirebirdTransactionParameterBufferType.CONCURRENCY, false);
+
parameterBuffer.put(FirebirdTransactionParameterBufferType.CONSISTENCY, false);
+ assertThat(packet.getIsolationLevel(),
is(TransactionIsolationLevel.NONE));
+ }
+
+ @SuppressWarnings("unchecked")
+ @SneakyThrows(ReflectiveOperationException.class)
+ private Map<FirebirdTransactionParameterBufferType, Object>
getParameterBuffer(final FirebirdStartTransactionPacket packet) {
+ FirebirdParameterBuffer tpb = (FirebirdParameterBuffer)
Plugins.getMemberAccessor().get(FirebirdStartTransactionPacket.class.getDeclaredField("tpb"),
packet);
+ return (Map<FirebirdTransactionParameterBufferType, Object>)
Plugins.getMemberAccessor().get(FirebirdParameterBuffer.class.getDeclaredField("parameterBuffer"),
tpb);
+ }
+
+ @Test
+ void assertWrite() {
+ FirebirdPacketPayload payload = mock(FirebirdPacketPayload.class,
RETURNS_DEEP_STUBS);
+ assertDoesNotThrow(() -> new
FirebirdStartTransactionPacket(payload).write(payload));
+ }
+
+ @Test
+ void assertGetLength() {
+ assertThat(FirebirdStartTransactionPacket.getLength(createPayload(1)),
is(16));
+ }
+
+ private FirebirdPacketPayload createPayload(final int handle, final
FirebirdTransactionParameterBufferType... types) {
+ ByteBuf byteBuf = Unpooled.buffer();
+ byteBuf.writeInt(0);
+ byteBuf.writeInt(handle);
+ ByteBuf tpbBuffer = Unpooled.buffer();
+ tpbBuffer.writeByte(1);
+ for (FirebirdTransactionParameterBufferType each : types) {
+ tpbBuffer.writeByte(each.getCode());
+ }
+ int tpbLength = tpbBuffer.readableBytes();
+ byteBuf.writeInt(tpbLength);
+ byteBuf.writeBytes(tpbBuffer);
+ byteBuf.writeZero((4 - tpbLength) & 3);
+ return new FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8);
+ }
+}
diff --git
a/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutor.java
b/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutor.java
index 4e556d13473..9f82a6d281a 100644
---
a/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutor.java
+++
b/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutor.java
@@ -39,7 +39,7 @@ public final class FirebirdStartTransactionCommandExecutor
implements CommandExe
@Override
public Collection<DatabasePacket> execute() {
- connectionSession.setAutoCommit(packet.isAutocommit());
+ connectionSession.setAutoCommit(packet.isAutoCommit());
connectionSession.setReadOnly(packet.isReadOnly());
connectionSession.setIsolationLevel(packet.getIsolationLevel());
int transactionId =
FirebirdTransactionIdGenerator.getInstance().nextTransactionId(connectionSession.getConnectionId());
diff --git
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
index 6d57c80b0bb..cff9ecc4f30 100644
---
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
+++
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
@@ -62,7 +62,7 @@ class FirebirdStartTransactionCommandExecutorTest {
@Test
void assertExecute() {
- when(packet.isAutocommit()).thenReturn(true);
+ when(packet.isAutoCommit()).thenReturn(true);
when(packet.isReadOnly()).thenReturn(true);
when(packet.getIsolationLevel()).thenReturn(TransactionIsolationLevel.SERIALIZABLE);
FirebirdStartTransactionCommandExecutor executor = new
FirebirdStartTransactionCommandExecutor(packet, connectionSession);