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 f9345e00fc test: fix JUnit test method access modifiers and 
annotations (#7635)
f9345e00fc is described below

commit f9345e00fc768c99134f59887095a922890477da
Author: contrueCT <[email protected]>
AuthorDate: Sun Nov 2 00:34:21 2025 +0800

    test: fix JUnit test method access modifiers and annotations (#7635)
---
 changes/en-us/2.x.md                               |   2 +
 changes/zh-cn/2.x.md                               |   2 +
 discovery/seata-discovery-etcd3/pom.xml            |   5 +
 .../etcd3/EtcdRegistryServiceImplTest.java         | 106 ++++++++++++++-------
 .../seata/rm/datasource/undo/BaseH2Test.java       |   2 +-
 .../apache/seata/server/ParameterParserTest.java   |   2 +-
 .../at/ATModeSupportDataBaseDataTypeTest.java      |   6 +-
 .../seata/at/oracle/SupportOracleDataTypeTest.java |   1 -
 8 files changed, 83 insertions(+), 43 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 3178235a75..2f57452e03 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -84,6 +84,7 @@ Add changes here for all PR submitted to the 2.x branch.
 
 ### test:
 
+- [[#7635](https://github.com/apache/incubator-seata/pull/7635)] fix JUnit 
test method access modifiers and annotations
 - [[#7541](https://github.com/seata/seata/pull/7541)] fix jakarta UT failed in 
jdk17+
 - [[#7540](https://github.com/seata/seata/pull/7540)] fix port of mock server
 - [[#7580](https://github.com/seata/seata/pull/7580)]  fix the exception 
caused by the disorder of test case execution order
@@ -133,6 +134,7 @@ Thanks to these contributors for their code commits. Please 
report an unintended
 - [WangzJi](https://github.com/WangzJi)
 - [unifolio0](https://github.com/unifolio0)
 - [Asuka-star](https://github.com/Asuka-star)
+- [contrueCT](https://github.com/contrueCT)
 - [YoWuwuuuw](https://github.com/YoWuwuuuw)
 - [yougecn](https://github.com/yougecn)
 - [jongmin-chung](https://github.com/jongmin-chung)
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index d721c718e1..2b964858b9 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -82,6 +82,7 @@
 
 ### test:
 
+- [[#7635](https://github.com/apache/incubator-seata/pull/7635)] 修正 JUnit 5 
测试方法的访问修饰符及注解使用规范
 - [[#7541](https://github.com/seata/seata/pull/7541)] 修复 jakarta 依赖在 jdk17+ 
单测失败问题
 - [[#7540](https://github.com/seata/seata/pull/7540)] 修复mock server端口冲突问题
 - [[#7578](https://github.com/seata/seata/pull/7578)]  
zstd解压由jni改为ZstdInputStream
@@ -130,6 +131,7 @@
 - [WangzJi](https://github.com/WangzJi)
 - [unifolio0](https://github.com/unifolio0)
 - [Asuka-star](https://github.com/Asuka-star)
+- [contrueCT](https://github.com/contrueCT)
 - [YoWuwuuuw](https://github.com/YoWuwuuuw)
 - [yougecn](https://github.com/yougecn)
 - [jongmin-chung](https://github.com/jongmin-chung)
diff --git a/discovery/seata-discovery-etcd3/pom.xml 
b/discovery/seata-discovery-etcd3/pom.xml
index 53a68488c5..d2c175bb2e 100644
--- a/discovery/seata-discovery-etcd3/pom.xml
+++ b/discovery/seata-discovery-etcd3/pom.xml
@@ -64,5 +64,10 @@
             <artifactId>native-lib-loader</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/discovery/seata-discovery-etcd3/src/test/java/org/apache/seata/discovery/registry/etcd3/EtcdRegistryServiceImplTest.java
 
b/discovery/seata-discovery-etcd3/src/test/java/org/apache/seata/discovery/registry/etcd3/EtcdRegistryServiceImplTest.java
index bfa9159821..e0829b385f 100644
--- 
a/discovery/seata-discovery-etcd3/src/test/java/org/apache/seata/discovery/registry/etcd3/EtcdRegistryServiceImplTest.java
+++ 
b/discovery/seata-discovery-etcd3/src/test/java/org/apache/seata/discovery/registry/etcd3/EtcdRegistryServiceImplTest.java
@@ -18,19 +18,23 @@ package org.apache.seata.discovery.registry.etcd3;
 
 import io.etcd.jetcd.ByteSequence;
 import io.etcd.jetcd.Client;
+import io.etcd.jetcd.KV;
 import io.etcd.jetcd.Watch;
-import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
+import io.etcd.jetcd.launcher.EtcdCluster;
+import io.etcd.jetcd.launcher.EtcdClusterFactory;
 import io.etcd.jetcd.options.DeleteOption;
 import io.etcd.jetcd.options.GetOption;
 import io.etcd.jetcd.watch.WatchResponse;
 import org.apache.seata.discovery.registry.RegistryService;
-import org.junit.Rule;
 import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.net.InetSocketAddress;
+import java.net.URI;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -42,34 +46,54 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class EtcdRegistryServiceImplTest {
     private static final String REGISTRY_KEY_PREFIX = "registry-seata-";
     private static final String CLUSTER_NAME = "default";
-
-    @Rule
-    private static final EtcdClusterResource etcd = new 
EtcdClusterResource(CLUSTER_NAME, 1);
-
-    private final Client client =
-            Client.builder().endpoints(etcd.getClientEndpoints()).build();
     private static final String HOST = "127.0.0.1";
     private static final int PORT = 8091;
 
+    private static EtcdCluster etcd;
+    private static Client client;
+    private static List<URI> clientEndpoints;
+
     @BeforeAll
-    public static void beforeClass() throws Exception {
-        System.setProperty(
-                EtcdRegistryServiceImpl.TEST_ENDPONT,
-                etcd.getClientEndpoints().get(0).toString());
+    public static void beforeAll() {
+        etcd = EtcdClusterFactory.buildCluster(CLUSTER_NAME, 1, false);
+        etcd.start();
+        clientEndpoints = etcd.getClientEndpoints();
+        client = Client.builder().endpoints(clientEndpoints).build();
     }
 
     @AfterAll
-    public static void afterClass() throws Exception {
-        System.setProperty(EtcdRegistryServiceImpl.TEST_ENDPONT, "");
+    public static void afterAll() {
+        if (client != null) {
+            client.close();
+        }
+        if (etcd != null) {
+            etcd.close();
+        }
+        System.clearProperty(EtcdRegistryServiceImpl.TEST_ENDPONT);
+    }
+
+    @BeforeEach
+    public void setUp() {
+        String endpoint = clientEndpoints.get(0).toString();
+        System.setProperty(EtcdRegistryServiceImpl.TEST_ENDPONT, endpoint);
+    }
+
+    @AfterEach
+    public void tearDown() throws Exception {
+        KV kvClient = client.getKVClient();
+        ByteSequence keyPrefix = buildRegistryKeyPrefix();
+        DeleteOption deleteOption =
+                DeleteOption.newBuilder().withPrefix(keyPrefix).build();
+        kvClient.delete(keyPrefix, deleteOption).get();
     }
 
     @Test
     public void testRegister() throws Exception {
         RegistryService registryService = new EtcdRegistryProvider().provide();
         InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, 
PORT);
-        // 1.register
+        // 1. Register the service instance.
         registryService.register(inetSocketAddress);
-        // 2.get instance information
+        // 2. Verify the registration by directly querying etcd.
         GetOption getOption =
                 
GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build();
         long count = client.getKVClient().get(buildRegistryKeyPrefix(), 
getOption).get().getKvs().stream()
@@ -87,7 +111,7 @@ public class EtcdRegistryServiceImplTest {
         InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, 
PORT);
         // 1.register
         registryService.register(inetSocketAddress);
-        // 2.get instance information
+        // 2. Verify it was registered successfully.
         GetOption getOption =
                 
GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build();
         long count = client.getKVClient().get(buildRegistryKeyPrefix(), 
getOption).get().getKvs().stream()
@@ -97,10 +121,9 @@ public class EtcdRegistryServiceImplTest {
                 })
                 .count();
         assertThat(count).isEqualTo(1);
-        // 3.unregister
+        // 3. Unregister the instance.
         registryService.unregister(inetSocketAddress);
-        // 4.again get instance information
-        getOption = 
GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build();
+        // 4. Verify it was successfully removed from etcd.
         count = client.getKVClient().get(buildRegistryKeyPrefix(), 
getOption).get().getKvs().stream()
                 .filter(keyValue -> {
                     String[] instanceInfo = 
keyValue.getValue().toString(UTF_8).split(":");
@@ -118,8 +141,8 @@ public class EtcdRegistryServiceImplTest {
         registryService.register(inetSocketAddress);
         // 2.subscribe
         EtcdListener etcdListener = new EtcdListener();
-        registryService.subscribe(CLUSTER_NAME, etcdListener);
-        // 3.delete instance,see if the listener can be notified
+        registryService.subscribe(DEFAULT_TX_GROUP, etcdListener);
+        // 3. Delete the instance key and verify the listener is notified.
         DeleteOption deleteOption =
                 
DeleteOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build();
         client.getKVClient().delete(buildRegistryKeyPrefix(), 
deleteOption).get();
@@ -134,14 +157,14 @@ public class EtcdRegistryServiceImplTest {
         registryService.register(inetSocketAddress);
         // 2.subscribe
         EtcdListener etcdListener = new EtcdListener();
-        registryService.subscribe(CLUSTER_NAME, etcdListener);
+        registryService.subscribe(DEFAULT_TX_GROUP, etcdListener);
         // 3.delete instance,see if the listener can be notified
         DeleteOption deleteOption =
                 
DeleteOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build();
         client.getKVClient().delete(buildRegistryKeyPrefix(), 
deleteOption).get();
         assertThat(etcdListener.isNotified()).isTrue();
         // 4.unsubscribe
-        registryService.unsubscribe(CLUSTER_NAME, etcdListener);
+        registryService.unsubscribe(DEFAULT_TX_GROUP, etcdListener);
         // 5.reset
         etcdListener.reset();
         // 6.put instance,the listener should not be notified
@@ -159,23 +182,26 @@ public class EtcdRegistryServiceImplTest {
         registryService.register(inetSocketAddress);
         // 2.lookup
         List<InetSocketAddress> inetSocketAddresses = 
registryService.lookup(DEFAULT_TX_GROUP);
-        assertThat(inetSocketAddresses).size().isEqualTo(1);
+        // 3.Verify that the correct instance is returned.
+        assertThat(inetSocketAddresses).hasSize(1);
+        
assertThat(inetSocketAddresses.get(0).getAddress().getHostAddress()).isEqualTo(HOST);
+        assertThat(inetSocketAddresses.get(0).getPort()).isEqualTo(PORT);
     }
 
     /**
-     * build registry key prefix
-     *
-     * @return
+     * Builds the etcd key prefix for a given service group.
+     * The key prefix includes the transaction service group as is standard in 
Seata.
+     * @return ByteSequence of the prefix
      */
     private ByteSequence buildRegistryKeyPrefix() {
-        return ByteSequence.from(REGISTRY_KEY_PREFIX, UTF_8);
+        return ByteSequence.from(REGISTRY_KEY_PREFIX + DEFAULT_TX_GROUP, 
UTF_8);
     }
 
     /**
-     * etcd listener
+     * Listener implementation for testing subscription notifications.
      */
     private static class EtcdListener implements Watch.Listener {
-        private boolean notified = false;
+        private volatile boolean notified = false;
 
         @Override
         public void onNext(WatchResponse response) {
@@ -183,23 +209,29 @@ public class EtcdRegistryServiceImplTest {
         }
 
         @Override
-        public void onError(Throwable throwable) {}
+        public void onError(Throwable throwable) {
+            // No-op for this test
+        }
 
         @Override
-        public void onCompleted() {}
+        public void onCompleted() {
+            // No-op for this test
+        }
 
         /**
-         * @return
+         * Waits for a short period to allow the async notification to arrive.
+         * @return true if a notification was received.
          */
         public boolean isNotified() throws InterruptedException {
-            TimeUnit.SECONDS.sleep(3);
+            // Give some time for the watch event to be processed
+            TimeUnit.SECONDS.sleep(1);
             return notified;
         }
 
         /**
-         * reset
+         * Resets the notification flag for subsequent assertions.
          */
-        private void reset() {
+        public void reset() {
             this.notified = false;
         }
     }
diff --git 
a/rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/BaseH2Test.java
 
b/rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/BaseH2Test.java
index d7debd86f3..c4b94e922a 100644
--- 
a/rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/BaseH2Test.java
+++ 
b/rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/BaseH2Test.java
@@ -77,7 +77,7 @@ public abstract class BaseH2Test {
     }
 
     @BeforeEach
-    private void prepareTable() {
+    public void prepareTable() {
         execSQL("DROP TABLE IF EXISTS table_name");
         execSQL("CREATE TABLE table_name ( `id` int(8), `name` varchar(64), 
PRIMARY KEY (`id`))");
     }
diff --git 
a/server/src/test/java/org/apache/seata/server/ParameterParserTest.java 
b/server/src/test/java/org/apache/seata/server/ParameterParserTest.java
index e632c5e91c..88ce103654 100644
--- a/server/src/test/java/org/apache/seata/server/ParameterParserTest.java
+++ b/server/src/test/java/org/apache/seata/server/ParameterParserTest.java
@@ -32,7 +32,7 @@ public class ParameterParserTest extends BaseSpringBootTest {
      * init
      */
     @BeforeEach
-    private void init() {
+    public void init() {
         String[] args = new String[] {"-h", "127.0.0.1", "-p", "8088", "-m", 
"file", "-e", "test"};
         parameterParser = new ParameterParser(args);
     }
diff --git 
a/test/src/test/java/org/apache/seata/at/ATModeSupportDataBaseDataTypeTest.java 
b/test/src/test/java/org/apache/seata/at/ATModeSupportDataBaseDataTypeTest.java
index 4a2307883c..d760d35f9c 100644
--- 
a/test/src/test/java/org/apache/seata/at/ATModeSupportDataBaseDataTypeTest.java
+++ 
b/test/src/test/java/org/apache/seata/at/ATModeSupportDataBaseDataTypeTest.java
@@ -91,7 +91,6 @@ public class ATModeSupportDataBaseDataTypeTest {
         testTypeSql(sqlType, globalCommit, sqlClass.getInsertSql(), 
sqlClass.getTableName(), sqlClass.getUpdateSql());
     }
 
-    @Test
     public void testTypeSql(int sqlType, boolean globalCommit, String 
insertSql, String tableName, String updateSql)
             throws Throwable {
         doExecute(sqlType, insertSql);
@@ -249,12 +248,13 @@ public class ATModeSupportDataBaseDataTypeTest {
                     case 3:
                         sqlClass.setInsertSql(TEST_DATE_TYPE_INSERT_SQL);
                         sqlClass.setTableName(DATE_TABLE_NAME);
-                        sqlClass.setTableName(TEST_DATE_TYPE_UPDATE_SQL);
+                        sqlClass.setUpdateSql(TEST_DATE_TYPE_UPDATE_SQL);
                         break;
                     case 4:
                         sqlClass.setInsertSql(TEST_BINARY_TYPE_INSERT_SQL);
                         sqlClass.setTableName(BINARY_TABLE_NAME);
-                        sqlClass.setTableName(TEST_BINARY_TYPE_UPDATE_SQL);
+                        sqlClass.setUpdateSql(TEST_BINARY_TYPE_UPDATE_SQL);
+                        break;
                     default:
                 }
                 break;
diff --git 
a/test/src/test/java/org/apache/seata/at/oracle/SupportOracleDataTypeTest.java 
b/test/src/test/java/org/apache/seata/at/oracle/SupportOracleDataTypeTest.java
index 9e3be3e6f5..a6805c0a14 100644
--- 
a/test/src/test/java/org/apache/seata/at/oracle/SupportOracleDataTypeTest.java
+++ 
b/test/src/test/java/org/apache/seata/at/oracle/SupportOracleDataTypeTest.java
@@ -110,7 +110,6 @@ public class SupportOracleDataTypeTest {
         testTypeSql(ORACLE, globalCommit, insertSql, tableName, updateSql);
     }
 
-    @Test
     public void testTypeSql(int sqlType, boolean globalCommit, String 
insertSql, String tableName, String updateSql)
             throws Throwable {
         doExecute(sqlType, insertSql);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to