Skip to content

Commit

Permalink
bugfix: fix DefaultCoordinatorTest failed in Windows OS (apache#2237)
Browse files Browse the repository at this point in the history
  • Loading branch information
booogu committed Feb 11, 2020
1 parent 0fa55cb commit b95b850
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
23 changes: 15 additions & 8 deletions server/src/main/java/io/seata/server/session/SessionHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package io.seata.server.session;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import io.seata.common.exception.ShouldNeverHappenException;
import io.seata.common.exception.StoreException;
import io.seata.common.loader.EnhancedServiceLoader;
Expand All @@ -29,6 +25,9 @@
import io.seata.core.exception.TransactionException;
import io.seata.core.model.GlobalStatus;
import io.seata.core.store.StoreMode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -271,9 +270,17 @@ public static GlobalSession findGlobalSession(String xid, boolean withBranchSess
}

public static void destroy() {
ROOT_SESSION_MANAGER.destroy();
ASYNC_COMMITTING_SESSION_MANAGER.destroy();
RETRY_COMMITTING_SESSION_MANAGER.destroy();
RETRY_ROLLBACKING_SESSION_MANAGER.destroy();
if (ROOT_SESSION_MANAGER != null) {
ROOT_SESSION_MANAGER.destroy();
}
if (ASYNC_COMMITTING_SESSION_MANAGER != null) {
ASYNC_COMMITTING_SESSION_MANAGER.destroy();
}
if (RETRY_COMMITTING_SESSION_MANAGER != null) {
RETRY_COMMITTING_SESSION_MANAGER.destroy();
}
if (RETRY_ROLLBACKING_SESSION_MANAGER != null) {
RETRY_ROLLBACKING_SESSION_MANAGER.destroy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@
*/
package io.seata.server.coordinator;

import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

import io.netty.channel.Channel;
import io.seata.common.XID;
import io.seata.common.exception.ShouldNeverHappenException;
import io.seata.common.util.DurationUtil;
import io.seata.common.util.NetUtil;
import io.seata.common.util.ReflectionUtil;
Expand All @@ -43,6 +36,15 @@
import io.seata.core.store.StoreMode;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionHolder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -220,28 +222,30 @@ public static void afterClass() throws Exception {
for (GlobalSession globalSession : globalSessions) {
globalSession.closeAndClean();
}

SessionHolder.destroy();
}

@AfterEach
public void tearDown() {
public void tearDown() throws IOException {
SessionHolder.destroy();
deleteDataFile();
}

private static void deleteDataFile() {
private static void deleteDataFile() throws IOException {
File directory = new File(sessionStorePath);
File[] files = directory.listFiles();
for (File file : files) {
file.delete();
if (files != null && files.length > 0) {
for (File file : files) {
Files.delete(Paths.get(file.getPath()));
}
}
}

private static void deleteAndCreateDataFile() throws IOException {
SessionHolder.destroy();
deleteDataFile();
SessionHolder.init(StoreMode.FILE.name());
}


static Stream<Arguments> xidAndBranchIdProviderForRollback() throws Exception {
String xid = core.begin(applicationId, txServiceGroup, txName, timeout);
Long branchId = core.branchRegister(BranchType.AT, resourceId, clientId, xid, applicationData, lockKeys_2);
Expand Down

0 comments on commit b95b850

Please sign in to comment.