This is an automated email from the ASF dual-hosted git repository.
jianbin 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 b1db26b022 test: add unit tests for DBType and RedisKeyConstants in
core module (#7874)
b1db26b022 is described below
commit b1db26b0221d909a724d6b734cfcc86c07838181
Author: NiMv1 <[email protected]>
AuthorDate: Mon Dec 29 05:14:22 2025 +0300
test: add unit tests for DBType and RedisKeyConstants in core module (#7874)
---
changes/en-us/2.x.md | 3 +
.../apache/seata/core/constants/DBTypeTest.java | 130 +++++++++++++++++++++
.../core/constants/RedisKeyConstantsTest.java | 93 +++++++++++++++
3 files changed, 226 insertions(+)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 552bf94c90..67da55c873 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -158,6 +158,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7827](https://github.com/apache/incubator-seata/pull/7827)] Fix
non-deteriministic in TableMetaTest#testGetPrimaryKeyOnlyName
- [[#7859](https://github.com/apache/incubator-seata/pull/7859)] Fix flaky
tests in MetadataTest caused by shared state and brittle toString assertions
- [[#7858](https://github.com/apache/incubator-seata/pull/7858)] Fix flakiness
in HttpTest.convertParamOfJsonStringTest caused by non-deterministic Map
iteration order
+- [[#7874](https://github.com/apache/incubator-seata/pull/7874)] add unit
tests for DBType and RedisKeyConstants in core module
- [[#7907](https://github.com/apache/incubator-seata/pull/7907)] test: fixes
CI errors caused by timing issues in ZkConfigurationTest
@@ -212,7 +213,9 @@ Thanks to these contributors for their code commits. Please
report an unintended
- [xingfudeshi](https://github.com/xingfudeshi)
- [diguage](https://github.com/diguage)
- [aias00](https://github.com/aias00)
+- [NiMv1](https://github.com/NiMv1)
- [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
+
Also, we receive many valuable issues, questions and advices from our
community. Thanks for you all.
diff --git a/core/src/test/java/org/apache/seata/core/constants/DBTypeTest.java
b/core/src/test/java/org/apache/seata/core/constants/DBTypeTest.java
new file mode 100644
index 0000000000..6cc50f8732
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/constants/DBTypeTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.constants;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unit tests for {@link DBType}.
+ */
+public class DBTypeTest {
+
+ @Test
+ void testValueofWithValidDbType() {
+ assertEquals(DBType.MYSQL, DBType.valueof("mysql"));
+ assertEquals(DBType.MYSQL, DBType.valueof("MYSQL"));
+ assertEquals(DBType.MYSQL, DBType.valueof("MySQL"));
+ }
+
+ @Test
+ void testValueofWithOracle() {
+ assertEquals(DBType.ORACLE, DBType.valueof("oracle"));
+ assertEquals(DBType.ORACLE, DBType.valueof("ORACLE"));
+ }
+
+ @Test
+ void testValueofWithPostgresql() {
+ assertEquals(DBType.POSTGRESQL, DBType.valueof("postgresql"));
+ assertEquals(DBType.POSTGRESQL, DBType.valueof("POSTGRESQL"));
+ }
+
+ @Test
+ void testValueofWithH2() {
+ assertEquals(DBType.H2, DBType.valueof("h2"));
+ assertEquals(DBType.H2, DBType.valueof("H2"));
+ }
+
+ @Test
+ void testValueofWithSqlserver() {
+ assertEquals(DBType.SQLSERVER, DBType.valueof("sqlserver"));
+ assertEquals(DBType.SQLSERVER, DBType.valueof("SQLSERVER"));
+ }
+
+ @Test
+ void testValueofWithDb2() {
+ assertEquals(DBType.DB2, DBType.valueof("db2"));
+ assertEquals(DBType.DB2, DBType.valueof("DB2"));
+ }
+
+ @Test
+ void testValueofWithMariadb() {
+ assertEquals(DBType.MARIADB, DBType.valueof("mariadb"));
+ assertEquals(DBType.MARIADB, DBType.valueof("MARIADB"));
+ }
+
+ @Test
+ void testValueofWithOceanbase() {
+ assertEquals(DBType.OCEANBASE, DBType.valueof("oceanbase"));
+ assertEquals(DBType.OCEANBASE, DBType.valueof("OCEANBASE"));
+ }
+
+ @Test
+ void testValueofWithDm() {
+ assertEquals(DBType.DM, DBType.valueof("dm"));
+ assertEquals(DBType.DM, DBType.valueof("DM"));
+ }
+
+ @Test
+ void testValueofWithPolardb() {
+ assertEquals(DBType.POLARDB, DBType.valueof("polardb"));
+ assertEquals(DBType.POLARDB, DBType.valueof("POLARDB"));
+ }
+
+ @Test
+ void testValueofWithClickhouse() {
+ assertEquals(DBType.CLICKHOUSE, DBType.valueof("clickhouse"));
+ assertEquals(DBType.CLICKHOUSE, DBType.valueof("CLICKHOUSE"));
+ }
+
+ @Test
+ void testValueofWithInvalidDbType() {
+ assertThrows(IllegalArgumentException.class, () ->
DBType.valueof("unknown"));
+ assertThrows(IllegalArgumentException.class, () -> DBType.valueof(""));
+ assertThrows(IllegalArgumentException.class, () ->
DBType.valueof("invalid_db"));
+ }
+
+ @Test
+ void testValueofWithNullDbType() {
+ assertThrows(IllegalArgumentException.class, () ->
DBType.valueof(null));
+ }
+
+ @Test
+ void testAllDbTypesCanBeRetrieved() {
+ for (DBType dbType : DBType.values()) {
+ assertEquals(dbType, DBType.valueof(dbType.name()));
+ assertEquals(dbType, DBType.valueof(dbType.name().toLowerCase()));
+ }
+ }
+
+ @Test
+ void testDbTypeEnumValues() {
+ DBType[] values = DBType.values();
+ assertTrue(values.length > 0);
+
+ // Verify some common database types exist
+ assertNotNull(DBType.valueOf("MYSQL"));
+ assertNotNull(DBType.valueOf("ORACLE"));
+ assertNotNull(DBType.valueOf("POSTGRESQL"));
+ assertNotNull(DBType.valueOf("H2"));
+ assertNotNull(DBType.valueOf("SQLSERVER"));
+ }
+}
diff --git
a/core/src/test/java/org/apache/seata/core/constants/RedisKeyConstantsTest.java
b/core/src/test/java/org/apache/seata/core/constants/RedisKeyConstantsTest.java
new file mode 100644
index 0000000000..14874a362a
--- /dev/null
+++
b/core/src/test/java/org/apache/seata/core/constants/RedisKeyConstantsTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.constants;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Unit tests for {@link RedisKeyConstants}.
+ */
+public class RedisKeyConstantsTest {
+
+ @Test
+ void testGlobalTransactionKeyConstants() {
+ assertEquals("xid", RedisKeyConstants.REDIS_KEY_GLOBAL_XID);
+ assertEquals("transactionId",
RedisKeyConstants.REDIS_KEY_GLOBAL_TRANSACTION_ID);
+ assertEquals("status", RedisKeyConstants.REDIS_KEY_GLOBAL_STATUS);
+ assertEquals("applicationId",
RedisKeyConstants.REDIS_KEY_GLOBAL_APPLICATION_ID);
+ assertEquals("transactionServiceGroup",
RedisKeyConstants.REDIS_KEY_GLOBAL_TRANSACTION_SERVICE_GROUP);
+ assertEquals("transactionName",
RedisKeyConstants.REDIS_KEY_GLOBAL_TRANSACTION_NAME);
+ assertEquals("timeout", RedisKeyConstants.REDIS_KEY_GLOBAL_TIMEOUT);
+ assertEquals("beginTime",
RedisKeyConstants.REDIS_KEY_GLOBAL_BEGIN_TIME);
+ assertEquals("applicationData",
RedisKeyConstants.REDIS_KEY_GLOBAL_APPLICATION_DATA);
+ assertEquals("gmtCreate",
RedisKeyConstants.REDIS_KEY_GLOBAL_GMT_CREATE);
+ assertEquals("gmtModified",
RedisKeyConstants.REDIS_KEY_GLOBAL_GMT_MODIFIED);
+ }
+
+ @Test
+ void testBranchTransactionKeyConstants() {
+ assertEquals("branchId", RedisKeyConstants.REDIS_KEY_BRANCH_BRANCH_ID);
+ assertEquals("xid", RedisKeyConstants.REDIS_KEY_BRANCH_XID);
+ assertEquals("transactionId",
RedisKeyConstants.REDIS_KEY_BRANCH_TRANSACTION_ID);
+ assertEquals("resourceGroupId",
RedisKeyConstants.REDIS_KEY_BRANCH_RESOURCE_GROUP_ID);
+ assertEquals("resourceId",
RedisKeyConstants.REDIS_KEY_BRANCH_RESOURCE_ID);
+ assertEquals("branchType",
RedisKeyConstants.REDIS_KEY_BRANCH_BRANCH_TYPE);
+ assertEquals("status", RedisKeyConstants.REDIS_KEY_BRANCH_STATUS);
+ assertEquals("beginTime",
RedisKeyConstants.REDIS_KEY_BRANCH_BEGIN_TIME);
+ assertEquals("applicationData",
RedisKeyConstants.REDIS_KEY_BRANCH_APPLICATION_DATA);
+ assertEquals("clientId", RedisKeyConstants.REDIS_KEY_BRANCH_CLIENT_ID);
+ assertEquals("gmtCreate",
RedisKeyConstants.REDIS_KEY_BRANCH_GMT_CREATE);
+ assertEquals("gmtModified",
RedisKeyConstants.REDIS_KEY_BRANCH_GMT_MODIFIED);
+ }
+
+ @Test
+ void testLockPrefixConstants() {
+ assertEquals("SEATA_GLOBAL_LOCK",
RedisKeyConstants.DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX);
+ assertEquals("SEATA_ROW_LOCK_",
RedisKeyConstants.DEFAULT_REDIS_SEATA_ROW_LOCK_PREFIX);
+ }
+
+ @Test
+ void testSplitConstant() {
+ assertEquals("^^^", RedisKeyConstants.SPLIT);
+ }
+
+ @Test
+ void testDefaultLogQueryLimit() {
+ assertEquals(100, RedisKeyConstants.DEFAULT_LOG_QUERY_LIMIT);
+ }
+
+ @Test
+ void testConstantsAreNotNull() {
+ assertNotNull(RedisKeyConstants.REDIS_KEY_GLOBAL_XID);
+ assertNotNull(RedisKeyConstants.REDIS_KEY_GLOBAL_TRANSACTION_ID);
+ assertNotNull(RedisKeyConstants.REDIS_KEY_BRANCH_BRANCH_ID);
+
assertNotNull(RedisKeyConstants.DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX);
+ assertNotNull(RedisKeyConstants.SPLIT);
+ }
+
+ @Test
+ void testConstantsAreNotEmpty() {
+ assertFalse(RedisKeyConstants.REDIS_KEY_GLOBAL_XID.isEmpty());
+ assertFalse(RedisKeyConstants.REDIS_KEY_BRANCH_XID.isEmpty());
+
assertFalse(RedisKeyConstants.DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX.isEmpty());
+ assertFalse(RedisKeyConstants.SPLIT.isEmpty());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]