Skip to content
Open
Show file tree
Hide file tree
Changes from 13 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
32 changes: 18 additions & 14 deletions common/src/test/java/org/apache/seata/common/io/FileLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ public void testLoadException() {
@Test
public void testLoadWhenDirectPath() throws Exception {
Path tempFile = Paths.get("direct-test-file.txt");
Files.createFile(tempFile);

File result = FileLoader.load("direct-test-file.txt");

Assertions.assertNotNull(result);
Assertions.assertTrue(result.exists());

Files.deleteIfExists(tempFile);
Files.createFile(tempFile);
try {
File result = FileLoader.load("direct-test-file.txt");

Assertions.assertNotNull(result);
Assertions.assertTrue(result.exists());
} finally {
Files.deleteIfExists(tempFile);
}
}

@Test
Expand All @@ -62,14 +64,16 @@ public void testLoadWhenSpecial() throws Exception {
String decodedName = "测试 文件.txt";

Path tempFile = Paths.get(decodedName);
Files.createFile(tempFile);

File result = FileLoader.load(encodedName);

Assertions.assertNotNull(result);
Assertions.assertTrue(result.exists());

Files.deleteIfExists(tempFile);
Files.createFile(tempFile);
try {
File result = FileLoader.load(encodedName);

Assertions.assertNotNull(result);
Assertions.assertTrue(result.exists());
} finally {
Files.deleteIfExists(tempFile);
}
}

@Test
Expand Down
8 changes: 8 additions & 0 deletions compatible/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>4</forkCount>
<reuseForks>true</reuseForks>
</configuration>
</plugin>
</plugins>
</build>
</project>
8 changes: 8 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>4</forkCount>
<reuseForks>true</reuseForks>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
Expand All @@ -39,14 +40,24 @@

class HttpTest {

private static final String HOST = "http://127.0.0.1:8081";
private static final int PORT = findAvailablePort();
private static final String HOST = "http://127.0.0.1:" + PORT;
private static final String TEST_EXCEPTION = "/testException";
private static final String GET_PATH = "/testGet";
private static final String POST_PATH = "/testPost";
public static final String XID = "127.0.0.1:8081:87654321";
public static final String XID = "127.0.0.1:" + PORT + ":87654321";
private static final int PARAM_TYPE_MAP = 1;
private static final int PARAM_TYPE_BEAN = 2;

private static int findAvailablePort() {
try (ServerSocket socket = new ServerSocket(0)) {
socket.setReuseAddress(true);
return socket.getLocalPort();
} catch (IOException e) {
return 8081;
}
Comment on lines +56 to +58
}

@Test
void testGetProviderXID() {
RootContext.bind(XID);
Expand Down Expand Up @@ -75,7 +86,7 @@ void testGetExceptionRemoveXID() {
}

public void providerStart() {
new MockWebServer().start(8081);
new MockWebServer().start(PORT);
}

public static class Person {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,33 @@ public class MockCoordinator implements TCInboundHandler, TransactionMessageHand

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

RemotingServer remotingServer;
private static final String ALL_BEGIN_FAIL_XID = "0";

private static MockCoordinator coordinator;
private RemotingServer remotingServer;

private static String AllBeginFailXid = "0";
private final Map<String, GlobalStatus> globalStatusMap;
private final Map<String, ResultCode> expectedResultMap;
private final Map<String, Integer> expectRetryTimesMap;
private final Map<String, List<MockBranchSession>> branchMap;

private Map<String, GlobalStatus> globalStatusMap;
private Map<String, ResultCode> expectedResultMap;
private Map<String, Integer> expectRetryTimesMap;
private Map<String, List<MockBranchSession>> branchMap;
public MockCoordinator() {
this.globalStatusMap = new ConcurrentHashMap<>();
this.expectedResultMap = new ConcurrentHashMap<>();
this.expectRetryTimesMap = new ConcurrentHashMap<>();
this.branchMap = new ConcurrentHashMap<>();
}

private MockCoordinator() {}
private static volatile MockCoordinator defaultInstance;

public static MockCoordinator getInstance() {
if (coordinator == null) {
if (defaultInstance == null) {
synchronized (MockCoordinator.class) {
if (coordinator == null) {
coordinator = new MockCoordinator();
coordinator.expectedResultMap = new ConcurrentHashMap<>();
coordinator.globalStatusMap = new ConcurrentHashMap<>();
coordinator.expectRetryTimesMap = new ConcurrentHashMap<>();
coordinator.branchMap = new ConcurrentHashMap<>();
if (defaultInstance == null) {
defaultInstance = new MockCoordinator();
}
}
}
return coordinator;
return defaultInstance;
}

@Override
Expand Down Expand Up @@ -155,7 +156,7 @@ private <T extends AbstractTransactionResponse> T handleException(
public GlobalBeginResponse handle(GlobalBeginRequest request, RpcContext rpcContext) {
GlobalBeginResponse response = new GlobalBeginResponse();
try {
checkMockActionFail(AllBeginFailXid);
checkMockActionFail(ALL_BEGIN_FAIL_XID);
} catch (TransactionException e) {
return handleException(e, response, ResultCode.Failed, "MockBeginException");
}
Expand Down Expand Up @@ -220,7 +221,6 @@ public GlobalRollbackResponse handle(GlobalRollbackRequest request, RpcContext r
CallRm.branchRollback(remotingServer, branch);
IntStream.range(0, retry).forEach(i -> CallRm.branchRollback(remotingServer, branch));
if (Version.isV0(rpcContext.getVersion())) {
// test MsgVersionHelper and skip
CallRm.deleteUndoLog(remotingServer, branch);
}
});
Expand All @@ -240,7 +240,6 @@ public BranchRegisterResponse handle(BranchRegisterRequest request, RpcContext r
MockBranchSession branchSession = new MockBranchSession(request.getBranchType());
String xid = request.getXid();
branchSession.setXid(xid);
// branchSession.setTransactionId(request.getTransactionId());
branchSession.setBranchId(UUIDGenerator.generateUUID());
branchSession.setResourceId(request.getResourceId());
branchSession.setLockKey(request.getLockKey());
Expand Down
Loading
Loading