Skip to content

Commit

Permalink
bugfix: fix test case fail (#4535)
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes committed Apr 9, 2022
1 parent 4a69bde commit 53d65bf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
1 change: 1 addition & 0 deletions changes/1.5.0.md
Expand Up @@ -109,6 +109,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#4471](https://github.com/seata/seata/pull/4471)] 修复develop分支下,运行时切换事务分组对应集群引起的错误
- [[#4474](https://github.com/seata/seata/pull/4474)] 修复Mysql多位Bit类型字段回滚错误
- [[#4228](https://github.com/seata/seata/pull/4228)] 修复tc获取不同ip的rm连接导致的xa模式资源悬挂问题
- [[#4535](https://github.com/seata/seata/pull/4535)] 修复FileSessionManagerTest单测错误

### optimize:
- [[#4163](https://github.com/seata/seata/pull/4163)] 完善开发者奉献文档
Expand Down
1 change: 1 addition & 0 deletions changes/en-us/1.5.0.md
Expand Up @@ -112,6 +112,7 @@
- [[#4459](https://github.com/seata/seata/pull/4459)] fix the failure to obtain before image and after image on oracle and pgsql of the develop branch
- [[#4471](https://github.com/seata/seata/pull/4471)] in branch 'develop', fix the error when service.vgroupMapping change
- [[#4474](https://github.com/seata/seata/pull/4474)] fix Mysql multi-bit Bit type field rollback error
- [[#4535](https://github.com/seata/seata/pull/4535)] fix FileSessionManagerTest fail



Expand Down
Expand Up @@ -15,10 +15,7 @@
*/
package io.seata.server.coordinator;

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.ExecutorService;
Expand Down Expand Up @@ -49,6 +46,7 @@
import io.seata.server.metrics.MetricsManager;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionHolder;
import io.seata.server.util.StoreUtil;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand All @@ -63,9 +61,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

import static io.seata.server.session.SessionHolder.DEFAULT_SESSION_STORE_FILE_DIR;

/**
* The type DefaultCoordinator test.
*
Expand Down Expand Up @@ -97,9 +92,6 @@ public class DefaultCoordinatorTest {

private static final Configuration CONFIG = ConfigurationFactory.getInstance();

private static String sessionStorePath = CONFIG.getConfig(ConfigurationKeys.STORE_FILE_DIR,
DEFAULT_SESSION_STORE_FILE_DIR);

@BeforeAll
public static void beforeClass(ApplicationContext context) throws Exception {
EnhancedServiceLoader.unload(AbstractCore.class);
Expand Down Expand Up @@ -237,21 +229,11 @@ public static void afterClass() throws Exception {
@AfterEach
public void tearDown() throws IOException {
MetricsManager.get().getRegistry().clearUp();
deleteDataFile();
}

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

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

Expand Down
Expand Up @@ -27,6 +27,7 @@
import javax.annotation.Resource;

import io.seata.common.XID;
import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.console.result.PageResult;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
Expand All @@ -36,6 +37,7 @@
import io.seata.server.console.service.GlobalSessionService;
import io.seata.server.console.vo.GlobalSessionVO;
import io.seata.server.storage.file.session.FileSessionManager;
import io.seata.server.util.StoreUtil;
import org.apache.commons.lang.time.DateUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -46,7 +48,6 @@
import org.springframework.context.ApplicationContext;

import static io.seata.common.DefaultValues.DEFAULT_TX_GROUP;

/**
* The type File based session manager test.
*
Expand All @@ -57,16 +58,18 @@
public class FileSessionManagerTest {


private static List<SessionManager> sessionManagerList;
private static volatile List<SessionManager> sessionManagerList;

@Resource(type = GlobalSessionService.class)
private GlobalSessionService globalSessionService;

@BeforeAll
public static void setUp(ApplicationContext context) {
StoreUtil.deleteDataFile();
try {
sessionManagerList = Arrays.asList(new FileSessionManager("root.data", "."),
new FileSessionManager("test", null));
EnhancedServiceLoader.unloadAll();
sessionManagerList =
Arrays.asList(new FileSessionManager("root.data", "."), new FileSessionManager("test", null));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -575,4 +578,5 @@ static Stream<Arguments> branchSessionProvider() {
Arguments.of(globalSession, branchSession)
);
}

}
48 changes: 48 additions & 0 deletions server/src/test/java/io/seata/server/util/StoreUtil.java
@@ -0,0 +1,48 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.server.util;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import io.seata.config.ConfigurationFactory;
import io.seata.core.constants.ConfigurationKeys;

import static io.seata.server.session.SessionHolder.DEFAULT_SESSION_STORE_FILE_DIR;

public class StoreUtil {

private static String sessionStorePath =
ConfigurationFactory.getInstance().getConfig(ConfigurationKeys.STORE_FILE_DIR, DEFAULT_SESSION_STORE_FILE_DIR);

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

}

0 comments on commit 53d65bf

Please sign in to comment.