Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7584](https://github.com/apache/incubator-seata/pull/7584)] deflake ConsulConfigurationTest#testInitSeataConfig with short await/retry to absorb CI timing delay
- [[#7610](https://github.com/apache/incubator-seata/pull/7610)] Enable Nacos integration tests when nacosCaseEnabled is true
- [[#7672](https://github.com/apache/incubator-seata/pull/7672)] Add unit tests for the `seata-common` module
- [[#7679](https://github.com/apache/incubator-seata/pull/7679)] fix old version connect timeout

### refactor:

Expand Down
2 changes: 1 addition & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
- [[#7584](https://github.com/seata/seata/pull/7584)] 修复 ConsulConfigurationTest#testInitSeataConfig 在 CI 中由于等待/重试时间过短导致的不稳定问题
- [[#7610](https://github.com/apache/incubator-seata/pull/7610)] 当nacosCaseEnabled为true时启用nacos集成测试
- [[#7672](https://github.com/apache/incubator-seata/pull/7672)] 增加 `seata-common` 模块的测试用例

- [[#7679](https://github.com/apache/incubator-seata/pull/7679)] 修复旧版本协议测试超时问题

### refactor:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void initChannel(SocketChannel ch) {
public void shutdown() {
try {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Shutting server down, the listen port: {}", XID.getPort());
LOGGER.info("Shutting server down, the listen port: {}", getListenPort());
}
if (initialized.get()) {
for (RegistryService registryService : MultiRegistryFactory.getInstances()) {
Expand Down
81 changes: 56 additions & 25 deletions test-old-version/src/test/java/io/seata/MockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MockTest {

protected static final Logger LOGGER = LoggerFactory.getLogger(MockTest.class);

static String RESOURCE_ID = "mock-action-061";
Logger logger = LoggerFactory.getLogger(MockTest.class);

Expand Down Expand Up @@ -101,38 +103,67 @@ public void testTm() throws Exception {
@Test
@Order(6)
public void testRm() throws Exception {
RmClientTest.testRm("testRM01");
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);
Assertions.assertNotNull(rm);
}

private String doTestCommit(int times) throws TransactionException, NoSuchMethodException {
TransactionManager tm = TmClientTest.getTm();
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);
int retry = 0;
do {
try {
TransactionManager tm = TmClientTest.getTm();
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);

String xid = tm.begin(
ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test-commit", 60000);
logger.info("doTestCommit(0.6.1) xid:{}", xid);
MockCoordinator.getInstance().setExpectedRetry(xid, times);
Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1");
logger.info("branch register(0.6.1) ok, branchId=" + branchId);
GlobalStatus commit = tm.commit(xid);
Assertions.assertEquals(GlobalStatus.Committed, commit);
logger.info("branch commit(0.6.1) ok, branchId=" + branchId);
return xid;
String xid = tm.begin(
ProtocolTestConstants.APPLICATION_ID,
ProtocolTestConstants.SERVICE_GROUP,
"test-commit",
60000);
logger.info("doTestCommit(0.6.1) xid:{}", xid);
MockCoordinator.getInstance().setExpectedRetry(xid, times);
Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1");
logger.info("branch register(0.6.1) ok, branchId=" + branchId);
GlobalStatus commit = tm.commit(xid);
Assertions.assertEquals(GlobalStatus.Committed, commit);
logger.info("branch commit(0.6.1) ok, branchId=" + branchId + "xid=" + xid);
return xid;
} catch (TransactionException e) {
if (retry >= 2) {
throw e;
}
LOGGER.warn("doTestCommit failed, retry times " + retry, e);
}
retry++;
} while (true);
}

private String doTestRollback(int times) throws TransactionException, NoSuchMethodException {
TransactionManager tm = TmClientTest.getTm();
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);
int retry = 0;
do {
try {
TransactionManager tm = TmClientTest.getTm();
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);

String xid = tm.begin(
ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test-rollback", 60000);
logger.info("doTestRollback(0.6.1) xid:{}", xid);
MockCoordinator.getInstance().setExpectedRetry(xid, times);
Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1");
logger.info("branch register(0.6.1) ok, branchId=" + branchId);
GlobalStatus rollback = tm.rollback(xid);
Assertions.assertEquals(GlobalStatus.Rollbacked, rollback);
logger.info("branch rollback(0.6.1) ok, branchId=" + branchId);
return xid;
String xid = tm.begin(
ProtocolTestConstants.APPLICATION_ID,
ProtocolTestConstants.SERVICE_GROUP,
"test-rollback",
60000);
logger.info("doTestRollback(0.6.1) xid:{}", xid);
MockCoordinator.getInstance().setExpectedRetry(xid, times);
Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1");
logger.info("branch register(0.6.1) ok, branchId=" + branchId);
GlobalStatus rollback = tm.rollback(xid);
Assertions.assertEquals(GlobalStatus.Rollbacked, rollback);
logger.info("branch rollback(0.6.1) ok, branchId=" + branchId + "xid=" + xid);
return xid;
} catch (TransactionException e) {
if (retry >= 2) {
throw e;
}
LOGGER.warn("doTestRollback failed, retry times " + retry, e);
}
retry++;
} while (true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ public class ProtocolTestConstants {
public static final String APPLICATION_ID = "mock_tx_app_id_061";
public static final String SERVICE_GROUP = "mock_tx_group";
public static final int MOCK_SERVER_PORT = 8077;
public static final String MOCK_SERVER_ADDRESS = "0.0.0.0:" + MOCK_SERVER_PORT;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
package io.seata.core.rpc.netty;

import io.seata.common.util.ReflectionUtil;
import io.seata.core.exception.TransactionException;
import io.seata.core.model.BranchType;
import io.seata.rm.DefaultResourceManager;
import io.seata.rm.RMClient;
import io.seata.rm.tcc.TCCResource;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,21 +35,7 @@ public class RmClientTest {
protected static final Logger LOGGER = LoggerFactory.getLogger(RmClientTest.class);
private static volatile DefaultResourceManager rm = null;

public static void testRm(String resourceId) throws TransactionException, NoSuchMethodException {
String xid = "1111";

DefaultResourceManager rm = getRm(resourceId);

// branchRegister:TYPE_BRANCH_REGISTER = 11 , TYPE_BRANCH_REGISTER_RESULT = 12
Long branchId = rm.branchRegister(BranchType.AT, resourceId, "1", xid, "1", "1");
Assertions.assertTrue(branchId > 0);

// (not support)branchReport:TYPE_BRANCH_STATUS_REPORT = 13 , TYPE_BRANCH_STATUS_REPORT_RESULT = 14
// (not support)lockQuery:TYPE_GLOBAL_LOCK_QUERY = 21 , TYPE_GLOBAL_LOCK_QUERY_RESULT = 22

}

public static DefaultResourceManager getRm(String resourceId) throws NoSuchMethodException {
private static DefaultResourceManager doGetRm(String resourceId) throws NoSuchMethodException {
if (rm == null) {
synchronized (RmClientTest.class) {
if (rm == null) {
Expand All @@ -65,6 +49,7 @@ public static DefaultResourceManager getRm(String resourceId) throws NoSuchMetho
.clear();

rm = resourceManager;
LOGGER.info("(0.6.1)RM init");
}
}
}
Expand All @@ -80,7 +65,22 @@ public static DefaultResourceManager getRm(String resourceId) throws NoSuchMetho
tccResource.setRollbackMethod(
ReflectionUtil.getMethod(Action1.class, "cancel", new Class[] {BusinessActionContext.class}));
rm.registerResource(tccResource);
LOGGER.info("registerResource ok");
LOGGER.info("(0.6.1)registerResource ok");
return rm;
}

public static DefaultResourceManager getRm(String resourceId) throws NoSuchMethodException {
int retry = 0;
do {
try {
return doGetRm(resourceId);
} catch (Exception e) {
if (retry >= 2) {
throw e;
}
LOGGER.warn(" failed, retry times " + retry, e);
}
retry++;
} while (true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class TmClientTest {

protected static final Logger LOGGER = LoggerFactory.getLogger(TmClientTest.class);
private static TransactionManager tm = null;
private static volatile TransactionManager tm = null;

public static void testTm() throws Exception {
TransactionManager tm = getTm();
Expand Down Expand Up @@ -68,6 +68,7 @@ public static TransactionManager getTm() {
ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP);
tmRpcClient.init();
tm = new DefaultTransactionManager();
LOGGER.info("(0.6.1)TM init");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void before() throws MQClientException {

@AfterAll
public static void after() {
MockServer.close();
// MockServer.close();
ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL);
producer.shutdown();
}
Expand Down
Loading