diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 9ca96285374..4290e986ad9 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设计器 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 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..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,23 +196,20 @@ 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 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); } @@ -224,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); 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..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 @@ -24,6 +24,7 @@ import org.apache.seata.common.XID; import org.apache.seata.common.thread.NamedThreadFactory; import org.apache.seata.common.util.NetUtil; +import org.apache.seata.server.ParameterParser; import org.apache.seata.server.UUIDGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +42,10 @@ public class MockServer { private static ThreadPoolExecutor workingThreads; private static MockNettyRemotingServer nettyRemotingServer; + private static volatile boolean inited = false; + + public static final int DEFAULT_PORT = 8091; + /** * The entry point of application. * @@ -48,32 +53,51 @@ 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() : DEFAULT_PORT; + start(port); } - 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); - - // set registry - XID.setIpAddress(NetUtil.getLocalIp()); - XID.setPort(8092); - // init snowflake for transactionId, branchId - UUIDGenerator.init(1L); - - MockCoordinator coordinator = MockCoordinator.getInstance(); - coordinator.setRemotingServer(nettyRemotingServer); - nettyRemotingServer.setHandler(coordinator); - nettyRemotingServer.init(); - - LOGGER.info("pid info: " + ManagementFactory.getRuntimeMXBean().getName()); + public static void start(int port) { + 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); + + // set registry + XID.setIpAddress(NetUtil.getLocalIp()); + XID.setPort(port); + // init snowflake for transactionId, branchId + UUIDGenerator.init(1L); + + MockCoordinator coordinator = MockCoordinator.getInstance(); + coordinator.setRemotingServer(nettyRemotingServer); + nettyRemotingServer.setHandler(coordinator); + nettyRemotingServer.init(); + + LOGGER.info("pid info: " + ManagementFactory.getRuntimeMXBean().getName()); + } + } + } + + } public static void close() { - workingThreads.shutdown(); - nettyRemotingServer.destroy(); + if (inited) { + synchronized (MockServer.class) { + if (inited) { + inited = false; + workingThreads.shutdown(); + nettyRemotingServer.destroy(); + } + } + } } } 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..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 @@ -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); @@ -98,8 +97,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.setBranchType(BranchType.TCC); - // todo AT SAGA + request.setApplicationData(branchSession.getApplicationData()); + 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 062444485bf..473af449775 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: 8091 spring: application: 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..308d7211f3b --- /dev/null +++ b/test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.common; + +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 + **/ +public class ConfigurationTestHelper { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationTestHelper.class); + private static final long PUT_CONFIG_TIMEOUT = 60000L; + + public static void removeConfig(String dataId) { + putConfig(dataId, null); + } + + public static void putConfig(String dataId, String content) { + 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); + return; + } + + System.setProperty(dataId, content); + ConfigurationFactory.getInstance().putConfig(dataId, content); + + try { + 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); + } + + } +} 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/TmNettyClientTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/TmNettyClientTest.java index 0c457b7a669..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 @@ -16,33 +16,46 @@ */ 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.ConfigurationTestHelper; import org.apache.seata.common.XID; import org.apache.seata.common.util.NetUtil; 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.BeforeAll; 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); + @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() { return new ThreadPoolExecutor(100, 500, 500, TimeUnit.SECONDS, 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/MockServerTest.java b/test/src/test/java/org/apache/seata/core/rpc/netty/mockserver/MockServerTest.java index a34966bd48e..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 @@ -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; @@ -28,46 +30,61 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +/** + * the type MockServerTest + */ public class MockServerTest { static String RESOURCE_ID = "mock-action"; @BeforeAll public static void before() { - MockServer.start(); + 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 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)); + } + + @Test + public void testTm() throws Exception { + TmClientTest.testTm(); + } + + @Test + public void testRm() throws Exception { + RmClientTest.testRm(); } private static String doTestCommit(int times) throws TransactionException { @@ -76,9 +93,9 @@ 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, "{\"mock\":\"mock\"}", "1"); GlobalStatus commit = tm.commit(xid); - Assertions.assertEquals(commit, GlobalStatus.Committed); + Assertions.assertEquals(GlobalStatus.Committed, commit); return xid; } @@ -89,9 +106,9 @@ 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, "{\"mock\":\"mock\"}", "1"); GlobalStatus rollback = tm.rollback(xid); - Assertions.assertEquals(rollback, GlobalStatus.Rollbacked); + 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 e8433ab91ff..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 @@ -18,10 +18,10 @@ /** * Mock Constants - * **/ 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 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 ef974a9b227..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 @@ -16,9 +16,9 @@ */ package org.apache.seata.core.rpc.netty.mockserver; -import java.util.concurrent.ConcurrentMap; - 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; @@ -37,26 +37,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ConcurrentMap; + /** * rm client test **/ public class RmClientTest { - protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class); - @BeforeAll - public static void before() { - MockServer.start(); - } - - @AfterAll - public static void after() { - MockServer.close(); - } - - @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 f39d95c8de4..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 @@ -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; @@ -40,19 +42,7 @@ public class TmClientTest { protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTest.class); - @BeforeAll - public static void before() { - MockServer.start(); - } - - @AfterAll - public static void after() { - MockServer.close(); - } - - @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 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 }