diff --git a/cim-forward-route/pom.xml b/cim-forward-route/pom.xml
index 8807a038..f894b29d 100644
--- a/cim-forward-route/pom.xml
+++ b/cim-forward-route/pom.xml
@@ -54,6 +54,38 @@
test
+
+ org.junit.vintage
+ junit-vintage-engine
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
+
+
+ com.clever-cloud
+ testcontainers-zookeeper
+
+
+
+ com.redis
+ testcontainers-redis
+ test
+
+
+
+ org.testcontainers
+ testcontainers
+
+
+ org.testcontainers
+ junit-jupiter
+
+
org.springframework.boot
spring-boot-configuration-processor
diff --git a/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AbstractBaseTest.java b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AbstractBaseTest.java
new file mode 100644
index 00000000..350cd589
--- /dev/null
+++ b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AbstractBaseTest.java
@@ -0,0 +1,46 @@
+package com.crossoverjie.cim.route.service.impl;
+
+import com.clevercloud.testcontainers.zookeeper.ZooKeeperContainer;
+import com.redis.testcontainers.RedisContainer;
+import java.time.Duration;
+import java.util.List;
+import org.junit.After;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.utility.DockerImageName;
+
+public class AbstractBaseTest {
+
+ @Container
+ static RedisContainer redis = new RedisContainer(DockerImageName.parse("redis:7.4.0"));
+
+ private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName
+ .parse("zookeeper")
+ .withTag("3.9.2");
+
+ private static final Duration DEFAULT_STARTUP_TIMEOUT = Duration.ofSeconds(60);
+
+ @Container
+ static final ZooKeeperContainer
+ zooKeeperContainer = new ZooKeeperContainer(DEFAULT_IMAGE_NAME, DEFAULT_STARTUP_TIMEOUT);
+
+
+ @BeforeAll
+ public static void before(){
+ redis.setExposedPorts(List.of(6379));
+ redis.setPortBindings(List.of("6379:6379"));
+ redis.start();
+
+ zooKeeperContainer.setExposedPorts(List.of(2181));
+ zooKeeperContainer.setPortBindings(List.of("2181:2181"));
+ zooKeeperContainer.start();
+ }
+
+ @AfterAll
+ public static void after(){
+ redis.stop();
+ zooKeeperContainer.stop();
+ }
+
+}
diff --git a/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImplTest.java b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImplTest.java
index ef43b38e..5046d8df 100644
--- a/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImplTest.java
+++ b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImplTest.java
@@ -4,20 +4,15 @@
import com.crossoverjie.cim.route.RouteApplication;
import com.crossoverjie.cim.route.api.vo.res.CIMServerResVO;
import com.crossoverjie.cim.route.service.AccountService;
+import java.util.Map;
import lombok.extern.slf4j.Slf4j;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
@Slf4j
@SpringBootTest(classes = RouteApplication.class)
-@RunWith(SpringRunner.class)
-public class AccountServiceRedisImplTest {
+public class AccountServiceRedisImplTest extends AbstractBaseTest{
@Autowired
private AccountService accountService ;
@@ -29,7 +24,6 @@ public void loadRouteRelated() throws Exception {
Map longCIMServerResVOMap = accountService.loadRouteRelated();
log.info("longCIMServerResVOMap={},cun={}" , JSON.toJSONString(longCIMServerResVOMap),i);
}
- TimeUnit.SECONDS.sleep(10);
}
}
\ No newline at end of file
diff --git a/cim-forward-route/src/test/java/RedisTest.java b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/RedisTest.java
similarity index 62%
rename from cim-forward-route/src/test/java/RedisTest.java
rename to cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/RedisTest.java
index 63b1b05b..2b437438 100644
--- a/cim-forward-route/src/test/java/RedisTest.java
+++ b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/RedisTest.java
@@ -1,21 +1,15 @@
+package com.crossoverjie.cim.route.service.impl;
+
import com.crossoverjie.cim.route.RouteApplication;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.test.context.junit4.SpringRunner;
-/**
- * Function:
- *
- * @author crossoverJie
- * Date: 2018/12/23 21:40
- * @since JDK 1.8
- */
+
@SpringBootTest(classes = RouteApplication.class)
-@RunWith(SpringRunner.class)
-public class RedisTest {
+public class RedisTest extends AbstractBaseTest {
@Autowired
private RedisTemplate redisTemplate ;
@@ -24,6 +18,6 @@ public class RedisTest {
public void test(){
redisTemplate.opsForValue().set("test","test") ;
String test = redisTemplate.opsForValue().get("test");
- System.out.println("====" + test);
+ Assertions.assertEquals("test",test);
}
}
diff --git a/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/UserInfoCacheServiceImplTest.java b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/UserInfoCacheServiceImplTest.java
index b71ea2ef..0217f8da 100644
--- a/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/UserInfoCacheServiceImplTest.java
+++ b/cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/UserInfoCacheServiceImplTest.java
@@ -4,19 +4,15 @@
import com.crossoverjie.cim.common.pojo.CIMUserInfo;
import com.crossoverjie.cim.route.RouteApplication;
import com.crossoverjie.cim.route.service.UserInfoCacheService;
+import java.util.Set;
import lombok.extern.slf4j.Slf4j;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import java.util.Set;
@Slf4j
@SpringBootTest(classes = RouteApplication.class)
-@RunWith(SpringRunner.class)
-public class UserInfoCacheServiceImplTest {
+public class UserInfoCacheServiceImplTest extends AbstractBaseTest{
@Autowired
private UserInfoCacheService userInfoCacheService;
diff --git a/cim-forward-route/src/test/resources/application.yaml b/cim-forward-route/src/test/resources/application.yaml
new file mode 100644
index 00000000..f2007e1d
--- /dev/null
+++ b/cim-forward-route/src/test/resources/application.yaml
@@ -0,0 +1,49 @@
+spring:
+ application:
+ name: cim-forward-route
+ data:
+ redis:
+ host: 127.0.0.1
+ port: 6379
+ jedis:
+ pool:
+ max-active: 100
+ max-idle: 100
+ max-wait: 1000
+ min-idle: 10
+# web port
+server:
+ port: 8083
+
+logging:
+ level:
+ root: info
+
+ # enable swagger
+springdoc:
+ swagger-ui:
+ enabled: true
+
+app:
+ zk:
+ addr: 127.0.0.1:2181
+ connect:
+ timeout: 30000
+ root: /route
+
+ # route strategy
+ #app.route.way=com.crossoverjie.cim.common.route.algorithm.loop.LoopHandle
+
+ # route strategy
+ #app.route.way=com.crossoverjie.cim.common.route.algorithm.random.RandomHandle
+
+ # route strategy
+ route:
+ way:
+ handler: com.crossoverjie.cim.common.route.algorithm.consistenthash.ConsistentHashHandle
+
+ #app.route.way.consitenthash=com.crossoverjie.cim.common.route.algorithm.consistenthash.SortArrayMapConsistentHash
+
+ consitenthash: com.crossoverjie.cim.common.route.algorithm.consistenthash.TreeMapConsistentHash
+
+
diff --git a/cim-server/src/test/com/crossoverjie/cim/server/util/NettyAttrUtilTest.java b/cim-server/src/test/com/crossoverjie/cim/server/util/NettyAttrUtilTest.java
index 4401dae4..d2c9318f 100644
--- a/cim-server/src/test/com/crossoverjie/cim/server/util/NettyAttrUtilTest.java
+++ b/cim-server/src/test/com/crossoverjie/cim/server/util/NettyAttrUtilTest.java
@@ -1,9 +1,9 @@
package com.crossoverjie.cim.server.util;
-import org.junit.Test;
import java.util.concurrent.TimeUnit;
+import org.junit.jupiter.api.Test;
public class NettyAttrUtilTest {