feat: 优化单元测试
原因
优化单元测试
修改
优化单元测试
This commit is contained in:
parent
e3c209d15e
commit
e437856a86
@ -1,5 +1,6 @@
|
||||
package cn.axzo.foundation.unittest.support.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import redis.embedded.RedisServer;
|
||||
@ -11,21 +12,29 @@ import javax.annotation.PreDestroy;
|
||||
* redis存在时, 处理相关配置
|
||||
* 1. 启动embedded的redis
|
||||
*/
|
||||
@Slf4j
|
||||
@ConditionalOnClass({RedisTemplate.class})
|
||||
public class RedisConfig {
|
||||
private RedisServer redisServer;
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
redisServer = RedisServer.builder().port(16739).setting("maxheap 128m").build();
|
||||
// redis server会在后台启动一个redis server的进程,默认IP=127.0.0.1
|
||||
redisServer.start();
|
||||
try {
|
||||
redisServer = RedisServer.builder().port(16739).setting("maxheap 128m").build();
|
||||
// redis server会在后台启动一个redis server的进程,默认IP=127.0.0.1
|
||||
redisServer.start();
|
||||
} catch (Exception ex) {
|
||||
redisServer = null;
|
||||
log.error("embedded-redis start failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
// 测试结束后必须调用redisServer.stop(), 否则后台运行的redis server进程会一直存在并占用6379端口
|
||||
redisServer.stop();
|
||||
if (redisServer != null) {
|
||||
// 测试结束后必须调用redisServer.stop(), 否则后台运行的redis server进程会一直存在并占用6379端口
|
||||
redisServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user