You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by ji...@apache.org on 2024/11/30 13:39:40 UTC
(incubator-seata) branch 2.x updated: test: add test for seata-core (#6869)
This is an automated email from the ASF dual-hosted git repository.
jimin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new a60588a11c test: add test for seata-core (#6869)
a60588a11c is described below
commit a60588a11cc8d1deaa7bd03424aca1b7eee95702
Author: 云清 <33...@users.noreply.github.com>
AuthorDate: Sat Nov 30 21:39:36 2024 +0800
test: add test for seata-core (#6869)
---
changes/en-us/2.x.md | 2 +
changes/zh-cn/2.x.md | 3 +-
.../core/compressor/CompressorFactoryTest.java | 63 ++++++++++++++++++
.../exception/BranchTransactionExceptionTest.java | 75 ++++++++++++++++++++++
.../seata/core/exception/DecodeExceptionTest.java | 31 +++++++++
.../exception/GlobalTransactionExceptionTest.java | 75 ++++++++++++++++++++++
.../core/exception/RmTransactionExceptionTest.java | 75 ++++++++++++++++++++++
.../core/exception/TmTransactionExceptionTest.java | 75 ++++++++++++++++++++++
.../core/exception/TransactionExceptionTest.java | 75 ++++++++++++++++++++++
.../lock/BaseDistributedLockSqlServerTest.java | 61 ++++++++++++++++++
.../lock/BaseDistributedLockSqlTest.java | 61 ++++++++++++++++++
.../lock/DistributedLockSqlFactoryTest.java | 51 +++++++++++++++
12 files changed, 646 insertions(+), 1 deletion(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 51b2b1e17e..ed7de433ea 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -61,6 +61,7 @@ Add changes here for all PR submitted to the 2.x branch.
### test:
+- [[#6869](https://github.com/apache/incubator-seata/pull/6869)] Add unit tests for the `seata-core` module
- [[#6927](https://github.com/apache/incubator-seata/pull/6927)] Add unit tests for the `seata-rocketmq` module
- [[#7018](https://github.com/apache/incubator-seata/pull/7018)] Add unit tests for the `seata-tm` module
- [[#7030](https://github.com/apache/incubator-seata/pull/7030)] Add unit tests for the `seata-common` module
@@ -85,6 +86,7 @@ Thanks to these contributors for their code commits. Please report an unintended
- [whaon](https://github.com/whaon)
- [YvCeung](https://github.com/YvCeung)
- [jsbxyyx](https://github.com/jsbxyyx)
+- [lightClouds917](https://github.com/lightClouds917)
- [Muluo-cyan](https://github.com/Muluo-cyan)
- [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index c880eeb998..9abe2b6929 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -64,12 +64,12 @@
### test:
+- [[#6869](https://github.com/apache/incubator-seata/pull/6869)] 增加`seata-core`测试用例覆盖率
- [[#6927](https://github.com/apache/incubator-seata/pull/6927)] 增加`seata-rocketmq`模块的测试用例
- [[#7018](https://github.com/apache/incubator-seata/pull/7018)] 增加 `seata-tm` 模块的测试用例
- [[#7030](https://github.com/apache/incubator-seata/pull/7030)] 增加 `seata-common` 模块的测试用例
-
非常感谢以下 contributors 的代码贡献。若有无意遗漏,请报告。
<!-- 请确保您的 GitHub ID 在以下列表中 -->
@@ -90,6 +90,7 @@
- [whaon](https://github.com/whaon)
- [YvCeung](https://github.com/YvCeung)
- [jsbxyyx](https://github.com/jsbxyyx)
+- [lightClouds917](https://github.com/lightClouds917)
- [Muluo-cyan](https://github.com/Muluo-cyan)
- [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
diff --git a/core/src/test/java/org/apache/seata/core/compressor/CompressorFactoryTest.java b/core/src/test/java/org/apache/seata/core/compressor/CompressorFactoryTest.java
new file mode 100644
index 0000000000..b32cae9277
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/compressor/CompressorFactoryTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.seata.core.compressor;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CompressorFactoryTest {
+
+ @Test
+ void testGetCompressorNone() {
+ Compressor compressor = CompressorFactory.getCompressor(CompressorType.NONE.getCode());
+ assertNotNull(compressor);
+ assertTrue(compressor instanceof CompressorFactory.NoneCompressor);
+ }
+
+ @Test
+ void testNoneCompressor() {
+ CompressorFactory.NoneCompressor noneCompressor = new CompressorFactory.NoneCompressor();
+ byte[] testData = "Test data".getBytes();
+
+ byte[] compressed = noneCompressor.compress(testData);
+ assertArrayEquals(testData, compressed);
+
+ byte[] decompressed = noneCompressor.decompress(compressed);
+ assertArrayEquals(testData, decompressed);
+ }
+
+ @Test
+ void testCompressorCaching() {
+ Compressor compressor1 = CompressorFactory.getCompressor(CompressorType.NONE.getCode());
+ Compressor compressor2 = CompressorFactory.getCompressor(CompressorType.NONE.getCode());
+ assertSame(compressor1, compressor2);
+ }
+
+ @Test
+ void testInvalidCompressorCode() {
+ assertThrows(IllegalArgumentException.class, () -> CompressorFactory.getCompressor((byte) -1));
+ }
+
+ @Test
+ void testCompressorMapInitialization() {
+ assertTrue(CompressorFactory.COMPRESSOR_MAP.containsKey(CompressorType.NONE));
+ assertTrue(CompressorFactory.COMPRESSOR_MAP.get(CompressorType.NONE) instanceof CompressorFactory.NoneCompressor);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/BranchTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/BranchTransactionExceptionTest.java
new file mode 100644
index 0000000000..73a29cde7c
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/BranchTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class BranchTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ BranchTransactionException exception = new BranchTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message");
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message", cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/DecodeExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/DecodeExceptionTest.java
new file mode 100644
index 0000000000..3981c54b15
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/DecodeExceptionTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class DecodeExceptionTest {
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ DecodeException exception = new DecodeException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/GlobalTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/GlobalTransactionExceptionTest.java
new file mode 100644
index 0000000000..093e853b7b
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/GlobalTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class GlobalTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ GlobalTransactionException exception = new GlobalTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message");
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message", cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/RmTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/RmTransactionExceptionTest.java
new file mode 100644
index 0000000000..a8b8938651
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/RmTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class RmTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ RmTransactionException exception = new RmTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message");
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message", cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/TmTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/TmTransactionExceptionTest.java
new file mode 100644
index 0000000000..a1b64e5bb9
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/TmTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class TmTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ TmTransactionException exception = new TmTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message");
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message", cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/TransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/TransactionExceptionTest.java
new file mode 100644
index 0000000000..1b19a33480
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/TransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class TransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ TransactionException exception = new TransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message");
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message", cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlServerTest.java b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlServerTest.java
new file mode 100644
index 0000000000..4a51509c9e
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlServerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.seata.core.store.db.sql.distributed.lock;
+
+import org.apache.seata.core.constants.ServerTableColumnsName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+class BaseDistributedLockSqlServerTest {
+
+ private BaseDistributedLockSqlServer baseDistributedLockSqlServer;
+ private final String testTable = "test_lock_table";
+
+ @BeforeEach
+ void setUp() {
+ baseDistributedLockSqlServer = new BaseDistributedLockSqlServer();
+ }
+
+ @Test
+ void testGetSelectDistributeForUpdateSql() {
+ String expected = "SELECT " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ " FROM " + testTable + " WITH (ROWLOCK, UPDLOCK, HOLDLOCK) WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + " = ?";
+ String actual = baseDistributedLockSqlServer.getSelectDistributeForUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetInsertSql() {
+ String expected = "INSERT INTO " + testTable + "(" +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ ") VALUES (?, ?, ?)";
+ String actual = baseDistributedLockSqlServer.getInsertSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetUpdateSql() {
+ String expected = "UPDATE " + testTable + " SET " +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "=?, " + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE + "=?" +
+ " WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "=?";
+ String actual = baseDistributedLockSqlServer.getUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlTest.java b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlTest.java
new file mode 100644
index 0000000000..2b98cb1f78
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.seata.core.store.db.sql.distributed.lock;
+
+import org.apache.seata.core.constants.ServerTableColumnsName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+class BaseDistributedLockSqlTest {
+
+ private BaseDistributedLockSql baseDistributedLockSql;
+ private final String testTable = "test_lock_table";
+
+ @BeforeEach
+ void setUp() {
+ baseDistributedLockSql = new BaseDistributedLockSql();
+ }
+
+ @Test
+ void testGetSelectDistributeForUpdateSql() {
+ String expected = "SELECT " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ " FROM " + testTable + " WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + " = ? FOR UPDATE";
+ String actual = baseDistributedLockSql.getSelectDistributeForUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetInsertSql() {
+ String expected = "INSERT INTO " + testTable + "(" +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ ") VALUES (?, ?, ?)";
+ String actual = baseDistributedLockSql.getInsertSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetUpdateSql() {
+ String expected = "UPDATE " + testTable + " SET " +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "=?, " + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE + "=?" +
+ " WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "=?";
+ String actual = baseDistributedLockSql.getUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactoryTest.java b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactoryTest.java
new file mode 100644
index 0000000000..9d1c892b2e
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactoryTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.seata.core.store.db.sql.distributed.lock;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+class DistributedLockSqlFactoryTest {
+
+ @Test
+ void testGetDistributedLogStoreSqlForMysql() {
+ DistributedLockSql sql = DistributedLockSqlFactory.getDistributedLogStoreSql("mysql");
+ assertNotNull(sql);
+ assertTrue(sql instanceof BaseDistributedLockSql);
+ }
+
+ @Test
+ void testGetDistributedLogStoreSqlForSqlServer() {
+ DistributedLockSql sql = DistributedLockSqlFactory.getDistributedLogStoreSql("sqlserver");
+ assertNotNull(sql);
+ assertTrue(sql instanceof BaseDistributedLockSqlServer);
+ }
+
+ @Test
+ void testGetDistributedLogStoreSqlForUnsupportedDb() {
+ DistributedLockSql sql = DistributedLockSqlFactory.getDistributedLogStoreSql("unsupported");
+ assertNotNull(sql);
+ assertTrue(sql instanceof BaseDistributedLockSql);
+ }
+
+ @Test
+ void testCacheImplementation() {
+ DistributedLockSql sql1 = DistributedLockSqlFactory.getDistributedLogStoreSql("mysql");
+ DistributedLockSql sql2 = DistributedLockSqlFactory.getDistributedLogStoreSql("mysql");
+ assertSame(sql1, sql2);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org