Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test : fix mockserverTest fail cause using same port with seata-server #6325

Merged
merged 33 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,8 @@ public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Excep
}

}

protected void setListenPort(int listenPort){
Bughue marked this conversation as resolved.
Show resolved Hide resolved
this.serverBootstrap.setListenPort(listenPort);
}
}
2 changes: 1 addition & 1 deletion test-mock-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</plugins>
</build>

<dependencies>
<dependencies>
<dependency>
funky-eyes marked this conversation as resolved.
Show resolved Hide resolved
<groupId>org.apache.seata</groupId>
<artifactId>seata-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions test-mock-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
server:
port: 7091
servicePort: 8099

spring:
application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public String insert(Long reqId, Map<String, String> 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;
}

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

}
Expand All @@ -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);
Bughue marked this conversation as resolved.
Show resolved Hide resolved
return xid;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions test/src/test/resources/file.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading