From 4dfe7daecab02c7bf43ea689ccf724fb5597a48d Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Fri, 2 Feb 2024 18:22:39 +0800 Subject: [PATCH 01/32] fix mocktest --- .../rpc/netty/mockserver/MockServerTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index a34966bd48e..4ec24de66fd 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -45,29 +45,29 @@ public static void after() { @Test public void testCommit() throws TransactionException { String xid = doTestCommit(0); - Assertions.assertEquals(Action1Impl.getCommitTimes(xid), 1); - Assertions.assertEquals(Action1Impl.getRollbackTimes(xid), 0); + Assertions.assertEquals(1, Action1Impl.getCommitTimes(xid)); + Assertions.assertEquals(0, Action1Impl.getRollbackTimes(xid)); } @Test public void testCommitRetry() throws TransactionException { String xid = doTestCommit(2); - Assertions.assertEquals(Action1Impl.getCommitTimes(xid), 3); - Assertions.assertEquals(Action1Impl.getRollbackTimes(xid), 0); + Assertions.assertEquals(3, Action1Impl.getCommitTimes(xid)); + Assertions.assertEquals(0, Action1Impl.getRollbackTimes(xid)); } @Test public void testRollback() throws TransactionException { String xid = doTestRollback(0); - Assertions.assertEquals(Action1Impl.getCommitTimes(xid), 0); - Assertions.assertEquals(Action1Impl.getRollbackTimes(xid), 1); + Assertions.assertEquals(0, Action1Impl.getCommitTimes(xid)); + Assertions.assertEquals(1, Action1Impl.getRollbackTimes(xid)); } @Test public void testRollbackRetry() throws TransactionException { String xid = doTestRollback(2); - Assertions.assertEquals(Action1Impl.getCommitTimes(xid), 0); - Assertions.assertEquals(Action1Impl.getRollbackTimes(xid), 3); + Assertions.assertEquals(0, Action1Impl.getCommitTimes(xid)); + Assertions.assertEquals(3, Action1Impl.getRollbackTimes(xid)); } private static String doTestCommit(int times) throws TransactionException { @@ -78,7 +78,7 @@ private static String doTestCommit(int times) throws TransactionException { MockCoordinator.getInstance().setExpectedRetry(xid, times); Long branchId = rm.branchRegister(BranchType.AT, RESOURCE_ID, "1", xid, "1", "1"); GlobalStatus commit = tm.commit(xid); - Assertions.assertEquals(commit, GlobalStatus.Committed); + Assertions.assertTrue(commit == GlobalStatus.Committed || commit == GlobalStatus.Finished); return xid; } @@ -91,7 +91,7 @@ private static String doTestRollback(int times) throws TransactionException { MockCoordinator.getInstance().setExpectedRetry(xid, times); Long branchId = rm.branchRegister(BranchType.AT, RESOURCE_ID, "1", xid, "1", "1"); GlobalStatus rollback = tm.rollback(xid); - Assertions.assertEquals(rollback, GlobalStatus.Rollbacked); + Assertions.assertTrue(rollback == GlobalStatus.Rollbacked || rollback == GlobalStatus.Finished); return xid; } From cf5a58ec26a06d139292607f86f304979c2fd0a5 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 13:14:22 +0800 Subject: [PATCH 02/32] mock test --- .../netty/AbstractNettyRemotingServer.java | 4 ++ test-mock-server/pom.xml | 67 +++++++++++++++++++ .../mockserver/MockNettyRemotingServer.java | 3 +- .../apache/seata/mockserver/MockServer.java | 4 +- .../apache/seata/mockserver/call/CallRm.java | 2 +- .../src/main/resources/application.yml | 1 + .../rpc/netty/mockserver/Action1Impl.java | 5 +- .../mockserver/ProtocolTestConstants.java | 5 +- test/src/test/resources/file.conf | 2 + 9 files changed, 84 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 16758d5ad1c..3e0d0a6fc94 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -268,4 +268,8 @@ public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Excep } } + + protected void setListenPort(int listenPort){ + this.serverBootstrap.setListenPort(listenPort); + } } diff --git a/test-mock-server/pom.xml b/test-mock-server/pom.xml index 466f42f2af2..f49b08dcccc 100644 --- a/test-mock-server/pom.xml +++ b/test-mock-server/pom.xml @@ -31,6 +31,12 @@ seata-mock-server ${project.version} Seata mock server + + 2.7.17 + 5.3.30 + 2.0 + + @@ -39,8 +45,69 @@ + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + + + org.springframework + spring-framework-bom + ${spring-framework-for-server.version} + pom + import + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-for-server.version} + + + org.springframework + spring-framework-bom + + + org.yaml + snakeyaml + + + pom + import + + + org.yaml + snakeyaml + ${snakeyaml-for-server.version} + + + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-for-server.version} + + + log4j-to-slf4j + org.apache.logging.log4j + + + + + org.springframework.boot + spring-boot + ${spring-boot-for-server.version} + org.apache.seata seata-server diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java index 3a871cb93e0..5be230de512 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java @@ -55,8 +55,9 @@ public void init() { * * @param messageExecutor the message executor */ - public MockNettyRemotingServer(ThreadPoolExecutor messageExecutor) { + public MockNettyRemotingServer(ThreadPoolExecutor messageExecutor,int port) { super(messageExecutor, new NettyServerConfig()); + setListenPort(port); } @Override diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index 04196094826..067a1728cd7 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -56,11 +56,11 @@ public static void start() { 50, 500, TimeUnit.SECONDS, new LinkedBlockingQueue<>(20000), new NamedThreadFactory("ServerHandlerThread", 500), new ThreadPoolExecutor.CallerRunsPolicy()); - nettyRemotingServer = new MockNettyRemotingServer(workingThreads); + nettyRemotingServer = new MockNettyRemotingServer(workingThreads, 8099); // set registry XID.setIpAddress(NetUtil.getLocalIp()); - XID.setPort(8092); + XID.setPort(8099); // init snowflake for transactionId, branchId UUIDGenerator.init(1L); diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java index a016022aca6..181ff20d568 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java @@ -98,7 +98,7 @@ private static void setReq(AbstractBranchEndRequest request, BranchSession branc request.setXid(branchSession.getXid()); request.setBranchId(branchSession.getBranchId()); request.setResourceId(branchSession.getResourceId()); - request.setApplicationData("{\"k\":\"v\"}"); + request.setApplicationData("{\"actionContext\":{\"mock\":\"mock\"}}"); request.setBranchType(BranchType.TCC); // todo AT SAGA } diff --git a/test-mock-server/src/main/resources/application.yml b/test-mock-server/src/main/resources/application.yml index 062444485bf..c5565e224ef 100644 --- a/test-mock-server/src/main/resources/application.yml +++ b/test-mock-server/src/main/resources/application.yml @@ -16,6 +16,7 @@ # server: port: 7091 + servicePort: 8099 spring: application: diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/Action1Impl.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/Action1Impl.java index 609debff38e..2aeeaf1d7f0 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/Action1Impl.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/Action1Impl.java @@ -41,7 +41,7 @@ public String insert(Long reqId, Map params) { @Override public boolean commitTcc(BusinessActionContext actionContext) { String xid = actionContext.getXid(); - System.out.println("commitTcc:" + xid); + System.out.println("commitTcc:" + xid + "," + actionContext.getActionContext()); commitMap.compute(xid, (k, v) -> v == null ? 1 : v + 1); return true; } @@ -49,9 +49,8 @@ public boolean commitTcc(BusinessActionContext actionContext) { @Override public boolean cancel(BusinessActionContext actionContext) { String xid = actionContext.getXid(); - System.out.println("commitTcc:" + xid); + System.out.println("cancelTcc:" + xid + "," + actionContext.getActionContext()); rollbackMap.compute(xid, (k, v) -> v == null ? 1 : v + 1); - System.out.println("cancel"); return true; } diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java index e8433ab91ff..ab5a48fac50 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java @@ -22,6 +22,7 @@ **/ public class ProtocolTestConstants { public static final String APPLICATION_ID = "my_app_test"; - public static final String SERVICE_GROUP = "default_tx_group"; - public static final String SERVER_ADDRESS = "0.0.0.0:8091"; + public static final String SERVICE_GROUP = "mock_tx_group"; + public static final String SERVER_PORT = "8099"; + public static final String SERVER_ADDRESS = "0.0.0.0:" + SERVER_PORT; } diff --git a/test/src/test/resources/file.conf b/test/src/test/resources/file.conf index 7cb83399689..94863827468 100644 --- a/test/src/test/resources/file.conf +++ b/test/src/test/resources/file.conf @@ -55,8 +55,10 @@ transport { service { #transaction service group mapping vgroupMapping.default_tx_group = "default" + vgroupMapping.mock_tx_group = "mock" #only support when registry.type=file, please don't set multiple addresses default.grouplist = "127.0.0.1:8091" + mock.grouplist = "127.0.0.1:8099" #disable seata disableGlobalTransaction = false } From c6b7b973742c89109cf9c0f1cd80e6223c870dec Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 13:16:07 +0800 Subject: [PATCH 03/32] rollback pom --- test-mock-server/pom.xml | 69 +--------------------------------------- 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/test-mock-server/pom.xml b/test-mock-server/pom.xml index f49b08dcccc..4eed690de3d 100644 --- a/test-mock-server/pom.xml +++ b/test-mock-server/pom.xml @@ -31,12 +31,6 @@ seata-mock-server ${project.version} Seata mock server - - 2.7.17 - 5.3.30 - 2.0 - - @@ -45,69 +39,8 @@ - - - - - org.junit - junit-bom - ${junit-jupiter.version} - pom - import - - - - - org.springframework - spring-framework-bom - ${spring-framework-for-server.version} - pom - import - - - - - org.springframework.boot - spring-boot-dependencies - ${spring-boot-for-server.version} - - - org.springframework - spring-framework-bom - - - org.yaml - snakeyaml - - - pom - import - - - org.yaml - snakeyaml - ${snakeyaml-for-server.version} - - - - - - org.springframework.boot - spring-boot-starter-web - ${spring-boot-for-server.version} - - - log4j-to-slf4j - org.apache.logging.log4j - - - - - org.springframework.boot - spring-boot - ${spring-boot-for-server.version} - + org.apache.seata seata-server From a333430946d7e4df27d796b1e4df0546c073d5c7 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 14:06:30 +0800 Subject: [PATCH 04/32] style --- .../seata/core/rpc/netty/AbstractNettyRemotingServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 3e0d0a6fc94..ad55df5952d 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -269,7 +269,7 @@ public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Excep } - protected void setListenPort(int listenPort){ + protected void setListenPort(int listenPort) { this.serverBootstrap.setListenPort(listenPort); } } From 9fbe973a644b88e296bfe1f1156f443b5d31d21f Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 16:56:42 +0800 Subject: [PATCH 05/32] style --- .../apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java index ad55df5952d..2c9472adb67 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -268,7 +268,6 @@ public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Excep } } - protected void setListenPort(int listenPort) { this.serverBootstrap.setListenPort(listenPort); } From 64377e11fddede0a3a0d78f70ef3c974b96091f1 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 17:13:22 +0800 Subject: [PATCH 06/32] changes --- changes/en-us/2.x.md | 1 + changes/zh-cn/2.x.md | 1 + 2 files changed, 2 insertions(+) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 9ca96285374..47dd9e35c9b 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -88,6 +88,7 @@ Add changes here for all PR submitted to the 2.x branch. - [[#6125](https://github.com/apache/incubator-seata/pull/6125)] unbind xid in TransactionTemplateTest - [[#6157](https://github.com/apache/incubator-seata/pull/6157)] increase common module unit test coverage - [[#6250](https://github.com/apache/incubator-seata/pull/6250)] increase seata-core module unit test coverage +- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] fix mockserverTest fail cause using same port with seata-server ### refactor: - [[#6280](https://github.com/apache/incubator-seata/pull/6280)] refactor Saga designer using diagram-js diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index b3c090aee16..bb4560050db 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -86,6 +86,7 @@ - [[#6125](https://github.com/apache/incubator-seata/pull/6125)] TransactionTemplateTest单测unbind xid - [[#6157](https://github.com/apache/incubator-seata/pull/6157)] 增加common模块单测覆盖率 - [[#6250](https://github.com/apache/incubator-seata/pull/6250)] 增加seata-core模块单测覆盖率 +- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] 修复mock-server相关测试用例 ### refactor: - [[#6280](https://github.com/apache/incubator-seata/pull/6280)] 使用diagram-js重构Saga设计器 From 2910eb22dc12a168cd6e01ba75acf360382b8085 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 17:16:04 +0800 Subject: [PATCH 07/32] changes --- changes/en-us/2.x.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 47dd9e35c9b..4290e986ad9 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -88,7 +88,7 @@ Add changes here for all PR submitted to the 2.x branch. - [[#6125](https://github.com/apache/incubator-seata/pull/6125)] unbind xid in TransactionTemplateTest - [[#6157](https://github.com/apache/incubator-seata/pull/6157)] increase common module unit test coverage - [[#6250](https://github.com/apache/incubator-seata/pull/6250)] increase seata-core module unit test coverage -- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] fix mockserverTest fail cause using same port with seata-server +- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] fix mockServerTest fail cause using same port with seata-server ### refactor: - [[#6280](https://github.com/apache/incubator-seata/pull/6280)] refactor Saga designer using diagram-js From fe00da562aba6468301020c4583f3fdcf5a6f40c Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 18:17:13 +0800 Subject: [PATCH 08/32] resolve conflict --- .../seata/core/rpc/netty/mockserver/MockServerTest.java | 5 ----- .../apache/seata/core/rpc/netty/mockserver/RmClientTest.java | 5 +---- .../apache/seata/core/rpc/netty/mockserver/TmClientTest.java | 4 ---- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 4ec24de66fd..8493d3d16b4 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -37,11 +37,6 @@ public static void before() { MockServer.start(); } - @AfterAll - public static void after() { - MockServer.close(); - } - @Test public void testCommit() throws TransactionException { String xid = doTestCommit(0); diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index ef974a9b227..381936a9e79 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -50,10 +50,7 @@ public static void before() { MockServer.start(); } - @AfterAll - public static void after() { - MockServer.close(); - } + @Test public void testRm() throws TransactionException { diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index f39d95c8de4..459c27499d0 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -45,10 +45,6 @@ public static void before() { MockServer.start(); } - @AfterAll - public static void after() { - MockServer.close(); - } @Test public void testTm() throws Exception { From 35ba3c82df902a3b8fbabb983a943f2f4e206910 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 18:25:34 +0800 Subject: [PATCH 09/32] fix test --- .../core/rpc/netty/mockserver/MockServerTest.java | 15 ++++++++++++++- .../core/rpc/netty/mockserver/RmClientTest.java | 7 +------ .../core/rpc/netty/mockserver/TmClientTest.java | 7 +------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 8493d3d16b4..2c28a0f1386 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -32,9 +32,22 @@ public class MockServerTest { static String RESOURCE_ID = "mock-action"; + private static volatile boolean inited = false; + @BeforeAll public static void before() { - MockServer.start(); + startMockServer(); + } + + public static void startMockServer() { + if (!inited) { + synchronized (MockServerTest.class) { + if (!inited) { + MockServer.start(); + inited = true; + } + } + } } @Test diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index 381936a9e79..a0dcfa13526 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -45,15 +45,10 @@ public class RmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class); - @BeforeAll - public static void before() { - MockServer.start(); - } - - @Test public void testRm() throws TransactionException { + MockServerTest.startMockServer(); String resourceId = "mock-action"; String xid = "1111"; diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index 459c27499d0..f12708c1801 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -40,15 +40,10 @@ public class TmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTest.class); - @BeforeAll - public static void before() { - MockServer.start(); - } - @Test public void testTm() throws Exception { - + MockServerTest.startMockServer(); TransactionManager tm = getTm(); //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 From 17832956b12a5999090dfa5b7d2994c5be313573 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Sun, 4 Feb 2024 18:40:47 +0800 Subject: [PATCH 10/32] fix test --- .../apache/seata/mockserver/MockServer.java | 41 ++++++++++++------- .../rpc/netty/mockserver/MockServerTest.java | 14 ++----- .../rpc/netty/mockserver/RmClientTest.java | 4 +- .../rpc/netty/mockserver/TmClientTest.java | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index 067a1728cd7..a4858843b19 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -41,6 +41,8 @@ public class MockServer { private static ThreadPoolExecutor workingThreads; private static MockNettyRemotingServer nettyRemotingServer; + private static volatile boolean inited = false; + /** * The entry point of application. * @@ -52,24 +54,33 @@ public static void main(String[] args) { } public static void start() { - workingThreads = new ThreadPoolExecutor(50, - 50, 500, TimeUnit.SECONDS, - new LinkedBlockingQueue<>(20000), - new NamedThreadFactory("ServerHandlerThread", 500), new ThreadPoolExecutor.CallerRunsPolicy()); - nettyRemotingServer = new MockNettyRemotingServer(workingThreads, 8099); + if (!inited) { + synchronized (MockServer.class) { + if (!inited) { + inited = true; + workingThreads = new ThreadPoolExecutor(50, + 50, 500, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(20000), + new NamedThreadFactory("ServerHandlerThread", 500), new ThreadPoolExecutor.CallerRunsPolicy()); + nettyRemotingServer = new MockNettyRemotingServer(workingThreads, 8099); + + // set registry + XID.setIpAddress(NetUtil.getLocalIp()); + XID.setPort(8099); + // init snowflake for transactionId, branchId + UUIDGenerator.init(1L); + + MockCoordinator coordinator = MockCoordinator.getInstance(); + coordinator.setRemotingServer(nettyRemotingServer); + nettyRemotingServer.setHandler(coordinator); + nettyRemotingServer.init(); - // set registry - XID.setIpAddress(NetUtil.getLocalIp()); - XID.setPort(8099); - // init snowflake for transactionId, branchId - UUIDGenerator.init(1L); + LOGGER.info("pid info: " + ManagementFactory.getRuntimeMXBean().getName()); + } + } + } - MockCoordinator coordinator = MockCoordinator.getInstance(); - coordinator.setRemotingServer(nettyRemotingServer); - nettyRemotingServer.setHandler(coordinator); - nettyRemotingServer.init(); - LOGGER.info("pid info: " + ManagementFactory.getRuntimeMXBean().getName()); } public static void close() { diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 2c28a0f1386..45ea94627e9 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -36,18 +36,12 @@ public class MockServerTest { @BeforeAll public static void before() { - startMockServer(); + MockServer.start(); } - public static void startMockServer() { - if (!inited) { - synchronized (MockServerTest.class) { - if (!inited) { - MockServer.start(); - inited = true; - } - } - } +// @AfterAll + public static void after() { + MockServer.close(); } @Test diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index a0dcfa13526..4343498a4ea 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -30,9 +30,7 @@ import org.apache.seata.mockserver.MockServer; import org.apache.seata.rm.DefaultResourceManager; import org.apache.seata.rm.RMClient; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +46,7 @@ public class RmClientTest { @Test public void testRm() throws TransactionException { - MockServerTest.startMockServer(); + MockServer.start(); String resourceId = "mock-action"; String xid = "1111"; diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index f12708c1801..f7fd821a68b 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -43,7 +43,7 @@ public class TmClientTest { @Test public void testTm() throws Exception { - MockServerTest.startMockServer(); + MockServer.start(); TransactionManager tm = getTm(); //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 From 74731e2386db70d8c19ef2f5d056d8d91ab3a6ec Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 12:06:29 +0800 Subject: [PATCH 11/32] config cache --- .../netty/AbstractNettyRemotingServer.java | 3 -- .../mockserver/MockNettyRemotingServer.java | 3 +- .../apache/seata/mockserver/MockServer.java | 31 +++++++++++++++---- .../core/rpc/netty/TmNettyClientTest.java | 21 +++++++++---- .../rpc/netty/mockserver/MockServerTest.java | 18 +++++------ .../mockserver/ProtocolTestConstants.java | 2 +- .../rpc/netty/mockserver/RmClientTest.java | 15 +++++++-- .../rpc/netty/mockserver/TmClientTest.java | 10 +++++- 8 files changed, 72 insertions(+), 31 deletions(-) diff --git a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java index 2c9472adb67..16758d5ad1c 100644 --- a/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java +++ b/core/src/main/java/org/apache/seata/core/rpc/netty/AbstractNettyRemotingServer.java @@ -268,7 +268,4 @@ public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Excep } } - protected void setListenPort(int listenPort) { - this.serverBootstrap.setListenPort(listenPort); - } } diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java index 5be230de512..3a871cb93e0 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockNettyRemotingServer.java @@ -55,9 +55,8 @@ public void init() { * * @param messageExecutor the message executor */ - public MockNettyRemotingServer(ThreadPoolExecutor messageExecutor,int port) { + public MockNettyRemotingServer(ThreadPoolExecutor messageExecutor) { super(messageExecutor, new NettyServerConfig()); - setListenPort(port); } @Override diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index a4858843b19..037f1b7f6d0 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -21,9 +21,14 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.common.XID; import org.apache.seata.common.thread.NamedThreadFactory; import org.apache.seata.common.util.NetUtil; +import org.apache.seata.config.ConfigurationCache; +import org.apache.seata.config.ConfigurationChangeEvent; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.server.ParameterParser; import org.apache.seata.server.UUIDGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,23 +55,28 @@ public class MockServer { */ public static void main(String[] args) { SpringApplication.run(MockServer.class, args); - start(); + + ParameterParser parameterParser = new ParameterParser(args); + int port = parameterParser.getPort() > 0 ? parameterParser.getPort() : 8099; + start(port); } - public static void start() { + public static void start(int port) { if (!inited) { synchronized (MockServer.class) { if (!inited) { inited = true; + System.setProperty(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(port)); + ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(port))); workingThreads = new ThreadPoolExecutor(50, 50, 500, TimeUnit.SECONDS, new LinkedBlockingQueue<>(20000), new NamedThreadFactory("ServerHandlerThread", 500), new ThreadPoolExecutor.CallerRunsPolicy()); - nettyRemotingServer = new MockNettyRemotingServer(workingThreads, 8099); + nettyRemotingServer = new MockNettyRemotingServer(workingThreads); // set registry XID.setIpAddress(NetUtil.getLocalIp()); - XID.setPort(8099); + XID.setPort(port); // init snowflake for transactionId, branchId UUIDGenerator.init(1L); @@ -84,7 +94,16 @@ public static void start() { } public static void close() { - workingThreads.shutdown(); - nettyRemotingServer.destroy(); + if (inited) { + synchronized (MockServer.class) { + if (inited) { + inited = false; + System.clearProperty(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); + ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, null)); + workingThreads.shutdown(); + nettyRemotingServer.destroy(); + } + } + } } } diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java index 0c457b7a669..9848550b9dc 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java @@ -16,15 +16,12 @@ */ package org.apache.seata.core.rpc.netty; -import java.lang.management.ManagementFactory; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - import io.netty.channel.Channel; +import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.common.XID; import org.apache.seata.common.util.NetUtil; +import org.apache.seata.config.ConfigurationCache; +import org.apache.seata.config.ConfigurationChangeEvent; import org.apache.seata.core.protocol.ResultCode; import org.apache.seata.core.protocol.transaction.BranchRegisterRequest; import org.apache.seata.core.protocol.transaction.BranchRegisterResponse; @@ -33,16 +30,28 @@ import org.apache.seata.server.coordinator.DefaultCoordinator; import org.apache.seata.server.session.SessionHolder; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.management.ManagementFactory; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + /** */ public class TmNettyClientTest extends AbstractServerTest { private static final Logger LOGGER = LoggerFactory.getLogger(TmNettyClientTest.class); + @BeforeEach + public void init(){ + System.setProperty(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, "8091"); + ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, "8091")); + } public static ThreadPoolExecutor initMessageExecutor() { return new ThreadPoolExecutor(100, 500, 500, TimeUnit.SECONDS, diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 45ea94627e9..521caabf19d 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -23,9 +23,9 @@ import org.apache.seata.mockserver.MockCoordinator; import org.apache.seata.mockserver.MockServer; import org.apache.seata.rm.DefaultResourceManager; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MockServerTest { @@ -34,13 +34,13 @@ public class MockServerTest { private static volatile boolean inited = false; - @BeforeAll - public static void before() { - MockServer.start(); + @BeforeEach + public void before() { + MockServer.start(ProtocolTestConstants.SERVER_PORT); } -// @AfterAll - public static void after() { + @AfterEach + public void after() { MockServer.close(); } @@ -80,7 +80,7 @@ private static String doTestCommit(int times) throws TransactionException { MockCoordinator.getInstance().setExpectedRetry(xid, times); Long branchId = rm.branchRegister(BranchType.AT, RESOURCE_ID, "1", xid, "1", "1"); GlobalStatus commit = tm.commit(xid); - Assertions.assertTrue(commit == GlobalStatus.Committed || commit == GlobalStatus.Finished); + Assertions.assertEquals(GlobalStatus.Committed, commit); return xid; } @@ -93,7 +93,7 @@ private static String doTestRollback(int times) throws TransactionException { MockCoordinator.getInstance().setExpectedRetry(xid, times); Long branchId = rm.branchRegister(BranchType.AT, RESOURCE_ID, "1", xid, "1", "1"); GlobalStatus rollback = tm.rollback(xid); - Assertions.assertTrue(rollback == GlobalStatus.Rollbacked || rollback == GlobalStatus.Finished); + Assertions.assertEquals(GlobalStatus.Rollbacked, rollback); return xid; } diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java index ab5a48fac50..da0c21d1e4b 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java @@ -23,6 +23,6 @@ public class ProtocolTestConstants { public static final String APPLICATION_ID = "my_app_test"; public static final String SERVICE_GROUP = "mock_tx_group"; - public static final String SERVER_PORT = "8099"; + public static final int SERVER_PORT = 8099; public static final String SERVER_ADDRESS = "0.0.0.0:" + SERVER_PORT; } diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index 4343498a4ea..d3d3b9a5d0b 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -16,8 +16,6 @@ */ package org.apache.seata.core.rpc.netty.mockserver; -import java.util.concurrent.ConcurrentMap; - import io.netty.channel.Channel; import org.apache.seata.core.context.RootContext; import org.apache.seata.core.exception.TransactionException; @@ -30,11 +28,15 @@ import org.apache.seata.mockserver.MockServer; import org.apache.seata.rm.DefaultResourceManager; import org.apache.seata.rm.RMClient; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ConcurrentMap; + /** * rm client test **/ @@ -43,10 +45,17 @@ public class RmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class); + @BeforeAll + public static void before() { + MockServer.start(ProtocolTestConstants.SERVER_PORT); + } + @AfterAll + public static void after() { + MockServer.close(); + } @Test public void testRm() throws TransactionException { - MockServer.start(); String resourceId = "mock-action"; String xid = "1111"; diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index f7fd821a68b..39a0b860af8 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -40,10 +40,17 @@ public class TmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTest.class); + @BeforeAll + public static void before() { + MockServer.start(ProtocolTestConstants.SERVER_PORT); + } + @AfterAll + public static void after() { + MockServer.close(); + } @Test public void testTm() throws Exception { - MockServer.start(); TransactionManager tm = getTm(); //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 @@ -77,6 +84,7 @@ public void testTm() throws Exception { GlobalStatus rollback2 = tm.rollback(xid); LOGGER.info("globalRollback ok:" + rollback2); // TODO expected response fail , but DefaultTransactionManager ignore resultCode + MockServer.close(); } @NotNull From 745b8842bcdb042d6b9d5b332726952f00c7206a Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 12:08:49 +0800 Subject: [PATCH 12/32] config cache --- .../core/rpc/netty/mockserver/MockServerTest.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 521caabf19d..9e583e1f98e 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -23,24 +23,22 @@ import org.apache.seata.mockserver.MockCoordinator; import org.apache.seata.mockserver.MockServer; import org.apache.seata.rm.DefaultResourceManager; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; public class MockServerTest { static String RESOURCE_ID = "mock-action"; - private static volatile boolean inited = false; - - @BeforeEach - public void before() { + @BeforeAll + public static void before() { MockServer.start(ProtocolTestConstants.SERVER_PORT); } - @AfterEach - public void after() { + @AfterAll + public static void after() { MockServer.close(); } From 7fa224787058a203a623e4c3ba9ca6d9ce4ceea0 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 12:15:39 +0800 Subject: [PATCH 13/32] style --- .../src/main/java/org/apache/seata/mockserver/MockServer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index 037f1b7f6d0..e69e2885088 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -27,7 +27,6 @@ import org.apache.seata.common.util.NetUtil; import org.apache.seata.config.ConfigurationCache; import org.apache.seata.config.ConfigurationChangeEvent; -import org.apache.seata.config.ConfigurationFactory; import org.apache.seata.server.ParameterParser; import org.apache.seata.server.UUIDGenerator; import org.slf4j.Logger; From 8d71daf08e7244aee4ee4b1dbbe3a9dedc1009be Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 14:09:30 +0800 Subject: [PATCH 14/32] style --- .../src/main/java/org/apache/seata/mockserver/MockServer.java | 4 +++- .../core/rpc/netty/mockserver/ProtocolTestConstants.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index e69e2885088..37bce7def20 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -47,6 +47,8 @@ public class MockServer { private static volatile boolean inited = false; + public static final int DEFAULT_PORT = 8099; + /** * The entry point of application. * @@ -56,7 +58,7 @@ public static void main(String[] args) { SpringApplication.run(MockServer.class, args); ParameterParser parameterParser = new ParameterParser(args); - int port = parameterParser.getPort() > 0 ? parameterParser.getPort() : 8099; + int port = parameterParser.getPort() > 0 ? parameterParser.getPort() : DEFAULT_PORT; start(port); } diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java index da0c21d1e4b..cf52311bf6d 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java @@ -16,6 +16,8 @@ */ package org.apache.seata.core.rpc.netty.mockserver; +import org.apache.seata.mockserver.MockServer; + /** * Mock Constants * @@ -23,6 +25,6 @@ public class ProtocolTestConstants { public static final String APPLICATION_ID = "my_app_test"; public static final String SERVICE_GROUP = "mock_tx_group"; - public static final int SERVER_PORT = 8099; + public static final int SERVER_PORT = MockServer.DEFAULT_PORT; public static final String SERVER_ADDRESS = "0.0.0.0:" + SERVER_PORT; } From f57c2600fdf16d929e6ab864ee4350e1631fc046 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 14:54:00 +0800 Subject: [PATCH 15/32] style --- .../apache/seata/core/rpc/netty/mockserver/MockServerTest.java | 3 +++ .../seata/core/rpc/netty/mockserver/ProtocolTestConstants.java | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 9e583e1f98e..dfae18bb89a 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -28,6 +28,9 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +/** + * the type MockServerTest + */ public class MockServerTest { static String RESOURCE_ID = "mock-action"; diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java index cf52311bf6d..8576a976389 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java @@ -20,7 +20,6 @@ /** * Mock Constants - * **/ public class ProtocolTestConstants { public static final String APPLICATION_ID = "my_app_test"; From aafda5141df01fc070c2a5ea90fdb540f9ef2597 Mon Sep 17 00:00:00 2001 From: funkye <364176773@qq.com> Date: Mon, 5 Feb 2024 15:15:06 +0800 Subject: [PATCH 16/32] Update test-mock-server/pom.xml --- test-mock-server/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-mock-server/pom.xml b/test-mock-server/pom.xml index 4eed690de3d..466f42f2af2 100644 --- a/test-mock-server/pom.xml +++ b/test-mock-server/pom.xml @@ -40,7 +40,7 @@ - + org.apache.seata seata-server From 042fa88183587810190ddfd16df2e0f475d85cfa Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 17:30:49 +0800 Subject: [PATCH 17/32] config helper --- .../apache/seata/mockserver/MockServer.java | 17 ++----- .../seata/common/ConfigurationTestHelper.java | 49 +++++++++++++++++++ .../core/rpc/netty/TmNettyClientTest.java | 18 ++++--- .../rpc/netty/mockserver/MockServerTest.java | 4 ++ .../rpc/netty/mockserver/RmClientTest.java | 4 ++ .../rpc/netty/mockserver/TmClientTest.java | 4 ++ 6 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index 37bce7def20..df859d26993 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -16,17 +16,9 @@ */ package org.apache.seata.mockserver; -import java.lang.management.ManagementFactory; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.common.XID; import org.apache.seata.common.thread.NamedThreadFactory; import org.apache.seata.common.util.NetUtil; -import org.apache.seata.config.ConfigurationCache; -import org.apache.seata.config.ConfigurationChangeEvent; import org.apache.seata.server.ParameterParser; import org.apache.seata.server.UUIDGenerator; import org.slf4j.Logger; @@ -34,6 +26,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.lang.management.ManagementFactory; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + /** * The type Mock Server. */ @@ -67,8 +64,6 @@ public static void start(int port) { synchronized (MockServer.class) { if (!inited) { inited = true; - System.setProperty(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(port)); - ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(port))); workingThreads = new ThreadPoolExecutor(50, 50, 500, TimeUnit.SECONDS, new LinkedBlockingQueue<>(20000), @@ -99,8 +94,6 @@ public static void close() { synchronized (MockServer.class) { if (inited) { inited = false; - System.clearProperty(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); - ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, null)); workingThreads.shutdown(); nettyRemotingServer.destroy(); } diff --git a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java new file mode 100644 index 00000000000..9d929a5404a --- /dev/null +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -0,0 +1,49 @@ +package org.apache.seata.common; + +import org.apache.commons.lang.ObjectUtils; +import org.apache.seata.config.ConfigurationCache; +import org.apache.seata.config.ConfigurationFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * the type ConfigurationTestHelper + **/ +public class ConfigurationTestHelper { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationTestHelper.class); + + + private static final long PUT_CONFIG_TIMEOUT = 30000L; + private static final long PUT_CONFIG_CHECK_GAP = 500L; + + public static void removeConfig(String dataId) { + putConfig(dataId, null); + } + + public static void putConfig(String dataId, String content) { + ConfigurationCache.addConfigListener(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); + if (content == null) { + System.clearProperty(dataId); + ConfigurationFactory.getInstance().removeConfig(dataId); + return; + } + + System.setProperty(dataId, content); + ConfigurationFactory.getInstance().putConfig(dataId, content); + + long start = System.currentTimeMillis(); + while (!ObjectUtils.equals(content, ConfigurationFactory.getInstance().getConfig(dataId))) { + if (PUT_CONFIG_TIMEOUT < System.currentTimeMillis() - start) { + LOGGER.error("putConfig timeout, dataId={}, timeout={}ms", dataId, PUT_CONFIG_TIMEOUT); + return; + } + try { + Thread.sleep(PUT_CONFIG_CHECK_GAP); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + LOGGER.info("putConfig ok, dataId={}, cost {}ms", dataId, System.currentTimeMillis() - start); + } +} diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java index 9848550b9dc..532198e1aeb 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java @@ -18,19 +18,20 @@ import io.netty.channel.Channel; import org.apache.seata.common.ConfigurationKeys; +import org.apache.seata.common.ConfigurationTestHelper; import org.apache.seata.common.XID; import org.apache.seata.common.util.NetUtil; -import org.apache.seata.config.ConfigurationCache; -import org.apache.seata.config.ConfigurationChangeEvent; import org.apache.seata.core.protocol.ResultCode; import org.apache.seata.core.protocol.transaction.BranchRegisterRequest; import org.apache.seata.core.protocol.transaction.BranchRegisterResponse; +import org.apache.seata.mockserver.MockServer; import org.apache.seata.saga.engine.db.AbstractServerTest; import org.apache.seata.server.UUIDGenerator; import org.apache.seata.server.coordinator.DefaultCoordinator; import org.apache.seata.server.session.SessionHolder; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,10 +48,13 @@ public class TmNettyClientTest extends AbstractServerTest { private static final Logger LOGGER = LoggerFactory.getLogger(TmNettyClientTest.class); - @BeforeEach - public void init(){ - System.setProperty(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, "8091"); - ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, "8091")); + @BeforeAll + public static void init(){ + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, "8091"); + } + @AfterAll + public static void after() { + ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); } public static ThreadPoolExecutor initMessageExecutor() { diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index dfae18bb89a..74713489f0d 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -16,6 +16,8 @@ */ package org.apache.seata.core.rpc.netty.mockserver; +import org.apache.seata.common.ConfigurationKeys; +import org.apache.seata.common.ConfigurationTestHelper; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.BranchType; import org.apache.seata.core.model.GlobalStatus; @@ -37,12 +39,14 @@ public class MockServerTest { @BeforeAll public static void before() { + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.SERVER_PORT)); MockServer.start(ProtocolTestConstants.SERVER_PORT); } @AfterAll public static void after() { MockServer.close(); + ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); } @Test diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index d3d3b9a5d0b..8f84c5c1374 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -17,6 +17,8 @@ package org.apache.seata.core.rpc.netty.mockserver; import io.netty.channel.Channel; +import org.apache.seata.common.ConfigurationKeys; +import org.apache.seata.common.ConfigurationTestHelper; import org.apache.seata.core.context.RootContext; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.BranchStatus; @@ -47,12 +49,14 @@ public class RmClientTest { @BeforeAll public static void before() { + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.SERVER_PORT)); MockServer.start(ProtocolTestConstants.SERVER_PORT); } @AfterAll public static void after() { MockServer.close(); + ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); } @Test public void testRm() throws TransactionException { diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index 39a0b860af8..09cf7e8c3ad 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -17,6 +17,8 @@ package org.apache.seata.core.rpc.netty.mockserver; import io.netty.channel.Channel; +import org.apache.seata.common.ConfigurationKeys; +import org.apache.seata.common.ConfigurationTestHelper; import org.apache.seata.core.model.GlobalStatus; import org.apache.seata.core.model.TransactionManager; import org.apache.seata.core.protocol.ResultCode; @@ -42,12 +44,14 @@ public class TmClientTest { @BeforeAll public static void before() { + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.SERVER_PORT)); MockServer.start(ProtocolTestConstants.SERVER_PORT); } @AfterAll public static void after() { MockServer.close(); + ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); } @Test public void testTm() throws Exception { From c7588399456e968a72f4947a6331c9b7e8132a9f Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 17:34:01 +0800 Subject: [PATCH 18/32] style --- test-mock-server/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/test-mock-server/pom.xml b/test-mock-server/pom.xml index 466f42f2af2..f409dc5d1d2 100644 --- a/test-mock-server/pom.xml +++ b/test-mock-server/pom.xml @@ -58,5 +58,4 @@ - From 3c4d1f90ed70505031f2b42a14e075801513f002 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 17:35:15 +0800 Subject: [PATCH 19/32] style --- test-mock-server/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/test-mock-server/pom.xml b/test-mock-server/pom.xml index f409dc5d1d2..466f42f2af2 100644 --- a/test-mock-server/pom.xml +++ b/test-mock-server/pom.xml @@ -58,4 +58,5 @@ + From 940d5a2308635e1b5f29c3c24a6db140c3fb2581 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Mon, 5 Feb 2024 17:38:38 +0800 Subject: [PATCH 20/32] style --- .../seata/common/ConfigurationTestHelper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java index 9d929a5404a..20a8bb523ea 100644 --- a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -1,3 +1,19 @@ +/* + * 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.common; import org.apache.commons.lang.ObjectUtils; From 3e883aa82f6aa2a4754b6b6033c9b426ed99d1e2 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 6 Feb 2024 14:23:12 +0800 Subject: [PATCH 21/32] style --- .../java/org/apache/seata/mockserver/MockServer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index df859d26993..9fc545d5b22 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -16,6 +16,11 @@ */ package org.apache.seata.mockserver; +import java.lang.management.ManagementFactory; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + import org.apache.seata.common.XID; import org.apache.seata.common.thread.NamedThreadFactory; import org.apache.seata.common.util.NetUtil; @@ -26,11 +31,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import java.lang.management.ManagementFactory; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - /** * The type Mock Server. */ From c0de496936ae3a4e43a8df490c1e1d226ae58cbe Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 6 Feb 2024 15:05:57 +0800 Subject: [PATCH 22/32] branch type & default port --- .../main/java/org/apache/seata/mockserver/MockServer.java | 2 +- .../main/java/org/apache/seata/mockserver/call/CallRm.java | 4 +--- test-mock-server/src/main/resources/application.yml | 2 +- .../seata/core/rpc/netty/ChannelManagerTestHelper.java | 2 +- .../seata/core/rpc/netty/mockserver/MockServerTest.java | 4 ++-- .../core/rpc/netty/mockserver/ProtocolTestConstants.java | 6 ++---- .../seata/core/rpc/netty/mockserver/RmClientTest.java | 4 ++-- .../seata/core/rpc/netty/mockserver/TmClientTest.java | 4 ++-- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java index 9fc545d5b22..36e95b7b751 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockServer.java @@ -44,7 +44,7 @@ public class MockServer { private static volatile boolean inited = false; - public static final int DEFAULT_PORT = 8099; + public static final int DEFAULT_PORT = 8091; /** * The entry point of application. diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java index 181ff20d568..c58b201ba09 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java @@ -45,7 +45,6 @@ public class CallRm { public static BranchStatus branchCommit(RemotingServer remotingServer, BranchSession branchSession) { BranchCommitRequest request = new BranchCommitRequest(); setReq(request, branchSession); - try { BranchCommitResponse response = (BranchCommitResponse) remotingServer.sendSyncRequest( branchSession.getResourceId(), branchSession.getClientId(), request, false); @@ -99,7 +98,6 @@ private static void setReq(AbstractBranchEndRequest request, BranchSession branc request.setBranchId(branchSession.getBranchId()); request.setResourceId(branchSession.getResourceId()); request.setApplicationData("{\"actionContext\":{\"mock\":\"mock\"}}"); - request.setBranchType(BranchType.TCC); - // todo AT SAGA + request.setBranchType(branchSession.getBranchType()); } } diff --git a/test-mock-server/src/main/resources/application.yml b/test-mock-server/src/main/resources/application.yml index c5565e224ef..473af449775 100644 --- a/test-mock-server/src/main/resources/application.yml +++ b/test-mock-server/src/main/resources/application.yml @@ -16,7 +16,7 @@ # server: port: 7091 - servicePort: 8099 + servicePort: 8091 spring: application: diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/ChannelManagerTestHelper.java b/test/src/test/java/org/apache/seata/core/rpc/netty/ChannelManagerTestHelper.java index 59786b8d88f..0ed3179eccc 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/ChannelManagerTestHelper.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/ChannelManagerTestHelper.java @@ -32,7 +32,7 @@ public static ConcurrentMap getChannelConcurrentMap(AbstractNet public static Channel getChannel(TmNettyRemotingClient client) { return getChannelManager(client) - .acquireChannel(ProtocolTestConstants.SERVER_ADDRESS); + .acquireChannel(ProtocolTestConstants.MOCK_SERVER_ADDRESS); } private static NettyClientChannelManager getChannelManager(AbstractNettyRemotingClient remotingClient) { return remotingClient.getClientChannelManager(); diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 74713489f0d..887c7274f36 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -39,8 +39,8 @@ public class MockServerTest { @BeforeAll public static void before() { - ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.SERVER_PORT)); - MockServer.start(ProtocolTestConstants.SERVER_PORT); + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); + MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT); } @AfterAll diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java index 8576a976389..d848fd890d3 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/ProtocolTestConstants.java @@ -16,14 +16,12 @@ */ package org.apache.seata.core.rpc.netty.mockserver; -import org.apache.seata.mockserver.MockServer; - /** * Mock Constants **/ public class ProtocolTestConstants { public static final String APPLICATION_ID = "my_app_test"; public static final String SERVICE_GROUP = "mock_tx_group"; - public static final int SERVER_PORT = MockServer.DEFAULT_PORT; - public static final String SERVER_ADDRESS = "0.0.0.0:" + SERVER_PORT; + public static final int MOCK_SERVER_PORT = 8099; + public static final String MOCK_SERVER_ADDRESS = "0.0.0.0:" + MOCK_SERVER_PORT; } diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index 8f84c5c1374..d3fc8b4b380 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -49,8 +49,8 @@ public class RmClientTest { @BeforeAll public static void before() { - ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.SERVER_PORT)); - MockServer.start(ProtocolTestConstants.SERVER_PORT); + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); + MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT); } @AfterAll diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index 09cf7e8c3ad..df0f02f3b73 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -44,8 +44,8 @@ public class TmClientTest { @BeforeAll public static void before() { - ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.SERVER_PORT)); - MockServer.start(ProtocolTestConstants.SERVER_PORT); + ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); + MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT); } @AfterAll From c5e4a8da731282f019f8f65ebcbf486ac343b164 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 6 Feb 2024 15:09:13 +0800 Subject: [PATCH 23/32] branch type & default port --- .../seata/core/rpc/netty/mockserver/MockServerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 887c7274f36..2e8c568f9bc 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -83,7 +83,7 @@ private static String doTestCommit(int times) throws TransactionException { String xid = tm.begin(ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test", 60000); MockCoordinator.getInstance().setExpectedRetry(xid, times); - Long branchId = rm.branchRegister(BranchType.AT, RESOURCE_ID, "1", xid, "1", "1"); + Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "1", "1"); GlobalStatus commit = tm.commit(xid); Assertions.assertEquals(GlobalStatus.Committed, commit); return xid; @@ -96,7 +96,7 @@ private static String doTestRollback(int times) throws TransactionException { String xid = tm.begin(ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test", 60000); MockCoordinator.getInstance().setExpectedRetry(xid, times); - Long branchId = rm.branchRegister(BranchType.AT, RESOURCE_ID, "1", xid, "1", "1"); + Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "1", "1"); GlobalStatus rollback = tm.rollback(xid); Assertions.assertEquals(GlobalStatus.Rollbacked, rollback); return xid; From 5af943243041c87816df4d57d931b81a1eced4dc Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 7 Feb 2024 11:28:07 +0800 Subject: [PATCH 24/32] maven build --- test-mock-server/pom.xml | 69 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/test-mock-server/pom.xml b/test-mock-server/pom.xml index 466f42f2af2..cb4483f24d8 100644 --- a/test-mock-server/pom.xml +++ b/test-mock-server/pom.xml @@ -32,14 +32,79 @@ Seata mock server + seata-mock-server - org.apache.maven.plugins - maven-deploy-plugin + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + org.apache.seata.mockserver.MockServer + + false + + + + + repackage + + + + + 2.7.17 + 5.3.30 + 2.0 + + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + + + org.springframework + spring-framework-bom + ${spring-framework-for-server.version} + pom + import + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-for-server.version} + + + org.springframework + spring-framework-bom + + + org.yaml + snakeyaml + + + pom + import + + + org.yaml + snakeyaml + ${snakeyaml-for-server.version} + + + + org.apache.seata From 9fd4f630f644773fd11e3b0553e3d10a7b57fdf6 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 7 Feb 2024 15:20:55 +0800 Subject: [PATCH 25/32] branch report --- .../org/apache/seata/mockserver/MockCoordinator.java | 9 +++++++++ .../java/org/apache/seata/mockserver/call/CallRm.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java index f53387c1940..231e07c88ea 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java @@ -209,6 +209,15 @@ protected void doBranchRegister(BranchRegisterRequest request, BranchRegisterRes @Override protected void doBranchReport(BranchReportRequest request, BranchReportResponse response, RpcContext rpcContext) throws TransactionException { checkMockActionFail(request.getXid()); + String xid = request.getXid(); + branchMap.compute(xid, (key, val) -> { + if (val != null) { + val.stream().filter(branch -> branch.getBranchId() == request.getBranchId()).forEach(branch -> { + branch.setApplicationData(request.getApplicationData()); + }); + } + return val; + }); response.setResultCode(ResultCode.Success); } diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java index c58b201ba09..ffee3c7f969 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/call/CallRm.java @@ -97,7 +97,7 @@ private static void setReq(AbstractBranchEndRequest request, BranchSession branc request.setXid(branchSession.getXid()); request.setBranchId(branchSession.getBranchId()); request.setResourceId(branchSession.getResourceId()); - request.setApplicationData("{\"actionContext\":{\"mock\":\"mock\"}}"); + request.setApplicationData(branchSession.getApplicationData()); request.setBranchType(branchSession.getBranchType()); } } From 244c9036b46f17960f2ab61b309ed747ca1819aa Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 7 Feb 2024 15:30:33 +0800 Subject: [PATCH 26/32] branch report --- .../seata/mockserver/MockCoordinator.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java index 231e07c88ea..727d32e824d 100644 --- a/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java +++ b/test-mock-server/src/main/java/org/apache/seata/mockserver/MockCoordinator.java @@ -147,6 +147,8 @@ protected void doGlobalCommit(GlobalCommitRequest request, GlobalCommitResponse IntStream.range(0, retry).forEach(i -> CallRm.branchCommit(remotingServer, branch)); }); + branchMap.remove(request.getXid()); + globalStatusMap.remove(request.getXid()); } @Override @@ -167,6 +169,8 @@ protected void doGlobalRollback(GlobalRollbackRequest request, GlobalRollbackRes IntStream.range(0, retry).forEach(i -> CallRm.branchRollback(remotingServer, branch)); }); + branchMap.remove(request.getXid()); + globalStatusMap.remove(request.getXid()); } @Override @@ -192,18 +196,6 @@ protected void doBranchRegister(BranchRegisterRequest request, BranchRegisterRes response.setBranchId(branchSession.getBranchId()); response.setResultCode(ResultCode.Success); - -// Thread thread = new Thread(() -> { -// try { -// Thread.sleep(1000); -// if (ProtocolConstants.VERSION_0 != Version.calcProtocolVersion(rpcContext.getVersion())) { -// CallRm.deleteUndoLog(remotingServer, resourceId, clientId); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } -// }); -// thread.start(); } @Override @@ -233,7 +225,7 @@ protected void doGlobalStatus(GlobalStatusRequest request, GlobalStatusResponse checkMockActionFail(request.getXid()); GlobalStatus globalStatus = globalStatusMap.get(request.getXid()); if (globalStatus == null) { - globalStatus = GlobalStatus.UnKnown; + globalStatus = GlobalStatus.Finished; } response.setGlobalStatus(globalStatus); response.setResultCode(ResultCode.Success); From 9260a9f8ef760b7a5f6167dfb7ff9bc085078025 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 7 Feb 2024 16:44:47 +0800 Subject: [PATCH 27/32] app data --- .../seata/core/rpc/netty/mockserver/MockServerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index 2e8c568f9bc..b8b6fa5ce4a 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -83,7 +83,7 @@ private static String doTestCommit(int times) throws TransactionException { String xid = tm.begin(ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test", 60000); MockCoordinator.getInstance().setExpectedRetry(xid, times); - Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "1", "1"); + Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1"); GlobalStatus commit = tm.commit(xid); Assertions.assertEquals(GlobalStatus.Committed, commit); return xid; @@ -96,7 +96,7 @@ private static String doTestRollback(int times) throws TransactionException { String xid = tm.begin(ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test", 60000); MockCoordinator.getInstance().setExpectedRetry(xid, times); - Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "1", "1"); + Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1"); GlobalStatus rollback = tm.rollback(xid); Assertions.assertEquals(GlobalStatus.Rollbacked, rollback); return xid; From 45aa8cc90af2f99624eacd0c53e88e6541d58f29 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 7 Feb 2024 16:55:20 +0800 Subject: [PATCH 28/32] style --- .../org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java | 1 - .../org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index d3fc8b4b380..70b0eb46b97 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -44,7 +44,6 @@ **/ public class RmClientTest { - protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class); @BeforeAll diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index df0f02f3b73..ca9afd968ad 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -41,7 +41,6 @@ public class TmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTest.class); - @BeforeAll public static void before() { ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); From 1ee0980b2bc419760747dd1fe52879082bb13406 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 7 Feb 2024 17:04:25 +0800 Subject: [PATCH 29/32] style --- .../java/org/apache/seata/common/ConfigurationTestHelper.java | 2 -- .../apache/seata/core/rpc/netty/mockserver/RmClientTest.java | 1 - 2 files changed, 3 deletions(-) diff --git a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java index 20a8bb523ea..c5c231c3702 100644 --- a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -28,8 +28,6 @@ public class ConfigurationTestHelper { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationTestHelper.class); - - private static final long PUT_CONFIG_TIMEOUT = 30000L; private static final long PUT_CONFIG_CHECK_GAP = 500L; diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index 70b0eb46b97..5d7b90fe699 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -45,7 +45,6 @@ public class RmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class); - @BeforeAll public static void before() { ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); From 3029b08ead18853ef571e4ec2470338ca2c5aadb Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 20 Feb 2024 16:12:24 +0800 Subject: [PATCH 30/32] countDownlatch --- .../seata/common/ConfigurationTestHelper.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java index c5c231c3702..acc18a4af71 100644 --- a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -16,12 +16,14 @@ */ package org.apache.seata.common; -import org.apache.commons.lang.ObjectUtils; import org.apache.seata.config.ConfigurationCache; import org.apache.seata.config.ConfigurationFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + /** * the type ConfigurationTestHelper **/ @@ -29,14 +31,14 @@ public class ConfigurationTestHelper { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationTestHelper.class); private static final long PUT_CONFIG_TIMEOUT = 30000L; - private static final long PUT_CONFIG_CHECK_GAP = 500L; public static void removeConfig(String dataId) { putConfig(dataId, null); } public static void putConfig(String dataId, String content) { - ConfigurationCache.addConfigListener(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); + CountDownLatch countDownLatch = new CountDownLatch(1); + ConfigurationCache.addConfigListener(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, event -> countDownLatch.countDown()); if (content == null) { System.clearProperty(dataId); ConfigurationFactory.getInstance().removeConfig(dataId); @@ -46,18 +48,12 @@ public static void putConfig(String dataId, String content) { System.setProperty(dataId, content); ConfigurationFactory.getInstance().putConfig(dataId, content); - long start = System.currentTimeMillis(); - while (!ObjectUtils.equals(content, ConfigurationFactory.getInstance().getConfig(dataId))) { - if (PUT_CONFIG_TIMEOUT < System.currentTimeMillis() - start) { - LOGGER.error("putConfig timeout, dataId={}, timeout={}ms", dataId, PUT_CONFIG_TIMEOUT); - return; - } - try { - Thread.sleep(PUT_CONFIG_CHECK_GAP); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + try { + countDownLatch.await(PUT_CONFIG_TIMEOUT, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); } - LOGGER.info("putConfig ok, dataId={}, cost {}ms", dataId, System.currentTimeMillis() - start); + + LOGGER.info("putConfig ok, dataId={}", dataId); } } From 266d17e0ea2b8a508c24f60aa9a723a8e25cf265 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Tue, 20 Feb 2024 17:19:49 +0800 Subject: [PATCH 31/32] test --- .../seata/common/ConfigurationTestHelper.java | 2 +- .../core/rpc/netty/mockserver/MockServerTest.java | 10 ++++++++++ .../core/rpc/netty/mockserver/RmClientTest.java | 13 +------------ .../core/rpc/netty/mockserver/TmClientTest.java | 14 +------------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java index acc18a4af71..42006a1bfc0 100644 --- a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -30,7 +30,7 @@ public class ConfigurationTestHelper { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationTestHelper.class); - private static final long PUT_CONFIG_TIMEOUT = 30000L; + private static final long PUT_CONFIG_TIMEOUT = 60000L; public static void removeConfig(String dataId) { putConfig(dataId, null); diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index b8b6fa5ce4a..3d926e769a0 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java @@ -77,6 +77,16 @@ public void testRollbackRetry() throws TransactionException { Assertions.assertEquals(3, Action1Impl.getRollbackTimes(xid)); } + @Test + public void testTm() throws Exception { + TmClientTest.testTm(); + } + + @Test + public void testRm() throws Exception { + RmClientTest.testRm(); + } + private static String doTestCommit(int times) throws TransactionException { TransactionManager tm = TmClientTest.getTm(); DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID); diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java index 5d7b90fe699..fcfb0a90524 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/RmClientTest.java @@ -45,19 +45,8 @@ public class RmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class); - @BeforeAll - public static void before() { - ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); - MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT); - } - @AfterAll - public static void after() { - MockServer.close(); - ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); - } - @Test - public void testRm() throws TransactionException { + public static void testRm() throws TransactionException { String resourceId = "mock-action"; String xid = "1111"; diff --git a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java index ca9afd968ad..b204b0da816 100644 --- a/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java +++ b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/TmClientTest.java @@ -41,19 +41,8 @@ public class TmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTest.class); - @BeforeAll - public static void before() { - ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT)); - MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT); - } - @AfterAll - public static void after() { - MockServer.close(); - ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); - } - @Test - public void testTm() throws Exception { + public static void testTm() throws Exception { TransactionManager tm = getTm(); //globalBegin:TYPE_GLOBAL_BEGIN = 1 , TYPE_GLOBAL_BEGIN_RESULT = 2 @@ -87,7 +76,6 @@ public void testTm() throws Exception { GlobalStatus rollback2 = tm.rollback(xid); LOGGER.info("globalRollback ok:" + rollback2); // TODO expected response fail , but DefaultTransactionManager ignore resultCode - MockServer.close(); } @NotNull From 557e34c02f7ebc83eaefcfbb1eec3c60e3490344 Mon Sep 17 00:00:00 2001 From: "minghua.xie" Date: Wed, 21 Feb 2024 10:47:37 +0800 Subject: [PATCH 32/32] test --- .../org/apache/seata/common/ConfigurationTestHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java index 42006a1bfc0..308d7211f3b 100644 --- a/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -49,11 +49,15 @@ public static void putConfig(String dataId, String content) { ConfigurationFactory.getInstance().putConfig(dataId, content); try { - countDownLatch.await(PUT_CONFIG_TIMEOUT, TimeUnit.MILLISECONDS); + boolean await = countDownLatch.await(PUT_CONFIG_TIMEOUT, TimeUnit.MILLISECONDS); + if(await){ + LOGGER.info("putConfig ok, dataId={}", dataId); + }else { + LOGGER.error("putConfig fail, dataId={}", dataId); + } } catch (InterruptedException e) { throw new RuntimeException(e); } - LOGGER.info("putConfig ok, dataId={}", dataId); } }