Skip to content

Commit a3aa11b

Browse files
authored
test : old version(< 0.7.1) client test case for multi-version protocol (apache#6695)
1 parent da9e99b commit a3aa11b

File tree

16 files changed

+748
-2
lines changed

16 files changed

+748
-2
lines changed

changes/en-us/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Add changes here for all PR submitted to the 2.x branch.
4343
- [[#6533](https://github.com/apache/incubator-seata/pull/6533)] increase integration-tx-api module unit test coverage
4444
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] add unit test for sql-parser-core
4545
- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] improve the test case coverage of saga module to 70%
46+
- [[#6695](https://github.com/apache/incubator-seata/pull/6695)] old version(< 0.7.1) client test case for multi-version protocol
4647

4748
Thanks to these contributors for their code commits. Please report an unintended omission.
4849

changes/zh-cn/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- [[#6533](https://github.com/apache/incubator-seata/pull/6533)] 增加 Integration-TX-API 模块单元测试覆盖范围
4646
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] 添加sql-parser-core模块测试用例
4747
- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] 增加saga模块的测试用例覆盖率
48+
- [[#6695](https://github.com/apache/incubator-seata/pull/6695)] 多版本协议的旧版本(< 0.7.1)客户端测试用例
4849

4950

5051

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<module>tcc</module>
6363
<module>test</module>
6464
<module>test-mock-server</module>
65+
<module>test-old-version</module>
6566
<module>tm</module>
6667
<module>metrics</module>
6768
<module>serializer</module>

test-old-version/pom.xml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<parent>
24+
<groupId>org.apache.seata</groupId>
25+
<artifactId>seata-parent</artifactId>
26+
<version>${revision}</version>
27+
</parent>
28+
<modelVersion>4.0.0</modelVersion>
29+
<artifactId>seata-test-old-version</artifactId>
30+
<packaging>jar</packaging>
31+
<name>seata-test-old-version</name>
32+
<description>test for Seata Old Version Client</description>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-deploy-plugin</artifactId>
39+
<configuration>
40+
<skip>true</skip>
41+
</configuration>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
46+
<dependencies>
47+
<dependency>
48+
<groupId>${project.groupId}</groupId>
49+
<artifactId>seata-mock-server</artifactId>
50+
<version>${project.version}</version>
51+
<exclusions>
52+
<exclusion>
53+
<groupId>${project.groupId}</groupId>
54+
<artifactId>seata-spring-autoconfigure-core</artifactId>
55+
</exclusion>
56+
</exclusions>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.seata</groupId>
60+
<artifactId>seata-all</artifactId>
61+
<version>0.6.1</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>io.seata</groupId>
65+
<artifactId>seata-tm</artifactId>
66+
<version>0.6.1</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>io.seata</groupId>
70+
<artifactId>seata-rm</artifactId>
71+
<version>0.6.1</version>
72+
</dependency>
73+
</dependencies>
74+
75+
76+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.seata;
18+
19+
import io.seata.core.rpc.netty.Action1Impl;
20+
import io.seata.core.rpc.netty.ProtocolTestConstants;
21+
import io.seata.core.rpc.netty.RmClientTest;
22+
import io.seata.core.rpc.netty.RmRpcClient;
23+
import io.seata.core.rpc.netty.TmClientTest;
24+
import io.seata.core.rpc.netty.TmRpcClient;
25+
import io.seata.rm.DefaultResourceManager;
26+
import io.seata.core.exception.TransactionException;
27+
import io.seata.core.model.BranchType;
28+
import io.seata.core.model.GlobalStatus;
29+
import io.seata.core.model.TransactionManager;
30+
import org.apache.seata.mockserver.MockCoordinator;
31+
import org.apache.seata.mockserver.MockServer;
32+
import org.junit.jupiter.api.AfterAll;
33+
import org.junit.jupiter.api.Assertions;
34+
import org.junit.jupiter.api.BeforeAll;
35+
import org.junit.jupiter.api.Test;
36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
38+
39+
/**
40+
* the type MockServerTest
41+
*/
42+
public class MockTest {
43+
44+
static String RESOURCE_ID = "mock-action-061";
45+
Logger logger = LoggerFactory.getLogger(MockTest.class);
46+
47+
@BeforeAll
48+
public static void before() {
49+
System.setProperty("server.servicePort", ProtocolTestConstants.MOCK_SERVER_PORT+"");
50+
MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT);
51+
}
52+
53+
@AfterAll
54+
public static void after() {
55+
MockServer.close();
56+
TmRpcClient.getInstance().destroy();
57+
RmRpcClient.getInstance().destroy();
58+
}
59+
60+
@Test
61+
public void testCommit() throws Exception {
62+
String xid = doTestCommit(0);
63+
Assertions.assertEquals(1, Action1Impl.getCommitTimes(xid));
64+
Assertions.assertEquals(0, Action1Impl.getRollbackTimes(xid));
65+
}
66+
67+
@Test
68+
public void testCommitRetry() throws Exception {
69+
String xid = doTestCommit(2);
70+
Assertions.assertEquals(3, Action1Impl.getCommitTimes(xid));
71+
Assertions.assertEquals(0, Action1Impl.getRollbackTimes(xid));
72+
}
73+
74+
@Test
75+
public void testRollback() throws Exception {
76+
String xid = doTestRollback(0);
77+
Assertions.assertEquals(0, Action1Impl.getCommitTimes(xid));
78+
Assertions.assertEquals(1, Action1Impl.getRollbackTimes(xid));
79+
}
80+
81+
@Test
82+
public void testRollbackRetry() throws Exception {
83+
String xid = doTestRollback(2);
84+
Assertions.assertEquals(0, Action1Impl.getCommitTimes(xid));
85+
Assertions.assertEquals(3, Action1Impl.getRollbackTimes(xid));
86+
}
87+
88+
@Test
89+
public void testTm() throws Exception {
90+
TmClientTest.testTm();
91+
}
92+
93+
@Test
94+
public void testRm() throws Exception {
95+
RmClientTest.testRm("testRM01");
96+
}
97+
98+
private String doTestCommit(int times) throws TransactionException, NoSuchMethodException {
99+
TransactionManager tm = TmClientTest.getTm();
100+
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);
101+
102+
String xid = tm.begin(ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test-commit", 60000);
103+
logger.info("doTestCommit(0.6.1) xid:{}", xid);
104+
MockCoordinator.getInstance().setExpectedRetry(xid, times);
105+
Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1");
106+
logger.info("branch register(0.6.1) ok, branchId=" + branchId);
107+
GlobalStatus commit = tm.commit(xid);
108+
Assertions.assertEquals(GlobalStatus.Committed, commit);
109+
return xid;
110+
}
111+
112+
private String doTestRollback(int times) throws TransactionException, NoSuchMethodException {
113+
TransactionManager tm = TmClientTest.getTm();
114+
DefaultResourceManager rm = RmClientTest.getRm(RESOURCE_ID);
115+
116+
String xid = tm.begin(ProtocolTestConstants.APPLICATION_ID, ProtocolTestConstants.SERVICE_GROUP, "test-rollback", 60000);
117+
logger.info("doTestRollback(0.6.1) xid:{}", xid);
118+
MockCoordinator.getInstance().setExpectedRetry(xid, times);
119+
Long branchId = rm.branchRegister(BranchType.TCC, RESOURCE_ID, "1", xid, "{\"mock\":\"mock\"}", "1");
120+
logger.info("branch register(0.6.1) ok, branchId=" + branchId);
121+
GlobalStatus rollback = tm.rollback(xid);
122+
Assertions.assertEquals(GlobalStatus.Rollbacked, rollback);
123+
return xid;
124+
}
125+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.seata.core.rpc.netty;
18+
19+
import io.seata.rm.tcc.api.BusinessActionContext;
20+
import io.seata.rm.tcc.api.BusinessActionContextParameter;
21+
import io.seata.rm.tcc.api.LocalTCC;
22+
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
23+
24+
import java.util.Map;
25+
26+
/**
27+
* The interface Action1.
28+
*
29+
*/
30+
@LocalTCC
31+
public interface Action1 {
32+
33+
@TwoPhaseBusinessAction(name = "mock-action", commitMethod = "commitTcc", rollbackMethod = "cancel"
34+
// , useTCCFence = true
35+
)
36+
String insert(@BusinessActionContextParameter Long reqId,
37+
@BusinessActionContextParameter(paramName = "params") Map<String, String> params
38+
);
39+
40+
41+
boolean commitTcc(BusinessActionContext actionContext);
42+
43+
44+
boolean cancel(BusinessActionContext actionContext);
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.seata.core.rpc.netty;
18+
19+
import io.seata.rm.tcc.api.BusinessActionContext;
20+
import org.springframework.stereotype.Service;
21+
import vlsi.utils.CompactHashMap;
22+
23+
import java.util.Map;
24+
25+
/**
26+
* The type Action1.
27+
*/
28+
@Service
29+
public class Action1Impl implements Action1 {
30+
31+
private static Map<String, Integer> commitMap = new CompactHashMap<>();
32+
private static Map<String, Integer> rollbackMap = new CompactHashMap<>();
33+
34+
@Override
35+
public String insert(Long reqId, Map<String, String> params) {
36+
System.out.println("prepare");
37+
return "prepare";
38+
}
39+
40+
41+
@Override
42+
public boolean commitTcc(BusinessActionContext actionContext) {
43+
String xid = actionContext.getXid();
44+
System.out.println("commitTcc:" + xid + "," + actionContext.getActionContext());
45+
commitMap.compute(xid, (k, v) -> v == null ? 1 : v + 1);
46+
return true;
47+
}
48+
49+
@Override
50+
public boolean cancel(BusinessActionContext actionContext) {
51+
String xid = actionContext.getXid();
52+
System.out.println("cancelTcc:" + xid + "," + actionContext.getActionContext());
53+
rollbackMap.compute(xid, (k, v) -> v == null ? 1 : v + 1);
54+
return true;
55+
}
56+
57+
public static int getCommitTimes(String xid) {
58+
return commitMap.getOrDefault(xid, 0);
59+
}
60+
61+
public static int getRollbackTimes(String xid) {
62+
return rollbackMap.getOrDefault(xid, 0);
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.seata.core.rpc.netty;
18+
19+
/**
20+
* Mock Constants
21+
**/
22+
public class ProtocolTestConstants {
23+
public static final String APPLICATION_ID = "mock_tx_app_id_061";
24+
public static final String SERVICE_GROUP = "mock_tx_group";
25+
public static final int MOCK_SERVER_PORT = 8077;
26+
public static final String MOCK_SERVER_ADDRESS = "0.0.0.0:" + MOCK_SERVER_PORT;
27+
}

0 commit comments

Comments
 (0)