Skip to content

Commit ab5f7a8

Browse files
authored
Merge pull request crossoverJie#145 from crossoverJie/route-test
[test] Route & server support test
2 parents 8bee51e + ebd6190 commit ab5f7a8

File tree

7 files changed

+141
-30
lines changed

7 files changed

+141
-30
lines changed

cim-forward-route/pom.xml

+32
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,38 @@
5454
<scope>test</scope>
5555
</dependency>
5656

57+
<dependency>
58+
<groupId>org.junit.vintage</groupId>
59+
<artifactId>junit-vintage-engine</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>com.clever-cloud</groupId>
71+
<artifactId>testcontainers-zookeeper</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>com.redis</groupId>
76+
<artifactId>testcontainers-redis</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.testcontainers</groupId>
82+
<artifactId>testcontainers</artifactId>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.testcontainers</groupId>
86+
<artifactId>junit-jupiter</artifactId>
87+
</dependency>
88+
5789
<dependency>
5890
<groupId>org.springframework.boot</groupId>
5991
<artifactId>spring-boot-configuration-processor</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.crossoverjie.cim.route.service.impl;
2+
3+
import com.clevercloud.testcontainers.zookeeper.ZooKeeperContainer;
4+
import com.redis.testcontainers.RedisContainer;
5+
import java.time.Duration;
6+
import java.util.List;
7+
import org.junit.After;
8+
import org.junit.jupiter.api.AfterAll;
9+
import org.junit.jupiter.api.BeforeAll;
10+
import org.testcontainers.junit.jupiter.Container;
11+
import org.testcontainers.utility.DockerImageName;
12+
13+
public class AbstractBaseTest {
14+
15+
@Container
16+
static RedisContainer redis = new RedisContainer(DockerImageName.parse("redis:7.4.0"));
17+
18+
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName
19+
.parse("zookeeper")
20+
.withTag("3.9.2");
21+
22+
private static final Duration DEFAULT_STARTUP_TIMEOUT = Duration.ofSeconds(60);
23+
24+
@Container
25+
static final ZooKeeperContainer
26+
zooKeeperContainer = new ZooKeeperContainer(DEFAULT_IMAGE_NAME, DEFAULT_STARTUP_TIMEOUT);
27+
28+
29+
@BeforeAll
30+
public static void before(){
31+
redis.setExposedPorts(List.of(6379));
32+
redis.setPortBindings(List.of("6379:6379"));
33+
redis.start();
34+
35+
zooKeeperContainer.setExposedPorts(List.of(2181));
36+
zooKeeperContainer.setPortBindings(List.of("2181:2181"));
37+
zooKeeperContainer.start();
38+
}
39+
40+
@AfterAll
41+
public static void after(){
42+
redis.stop();
43+
zooKeeperContainer.stop();
44+
}
45+
46+
}

cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImplTest.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
import com.crossoverjie.cim.route.RouteApplication;
55
import com.crossoverjie.cim.route.api.vo.res.CIMServerResVO;
66
import com.crossoverjie.cim.route.service.AccountService;
7+
import java.util.Map;
78
import lombok.extern.slf4j.Slf4j;
8-
import org.junit.Test;
9-
import org.junit.runner.RunWith;
9+
import org.junit.jupiter.api.Test;
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.boot.test.context.SpringBootTest;
12-
import org.springframework.test.context.junit4.SpringRunner;
13-
14-
import java.util.Map;
15-
import java.util.concurrent.TimeUnit;
1612

1713
@Slf4j
1814
@SpringBootTest(classes = RouteApplication.class)
19-
@RunWith(SpringRunner.class)
20-
public class AccountServiceRedisImplTest {
15+
public class AccountServiceRedisImplTest extends AbstractBaseTest{
2116

2217
@Autowired
2318
private AccountService accountService ;
@@ -29,7 +24,6 @@ public void loadRouteRelated() throws Exception {
2924
Map<Long, CIMServerResVO> longCIMServerResVOMap = accountService.loadRouteRelated();
3025
log.info("longCIMServerResVOMap={},cun={}" , JSON.toJSONString(longCIMServerResVOMap),i);
3126
}
32-
TimeUnit.SECONDS.sleep(10);
3327
}
3428

3529
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1+
package com.crossoverjie.cim.route.service.impl;
2+
13
import com.crossoverjie.cim.route.RouteApplication;
2-
import org.junit.Test;
3-
import org.junit.runner.RunWith;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
46
import org.springframework.beans.factory.annotation.Autowired;
57
import org.springframework.boot.test.context.SpringBootTest;
68
import org.springframework.data.redis.core.RedisTemplate;
7-
import org.springframework.test.context.junit4.SpringRunner;
89

9-
/**
10-
* Function:
11-
*
12-
* @author crossoverJie
13-
* Date: 2018/12/23 21:40
14-
* @since JDK 1.8
15-
*/
10+
1611
@SpringBootTest(classes = RouteApplication.class)
17-
@RunWith(SpringRunner.class)
18-
public class RedisTest {
12+
public class RedisTest extends AbstractBaseTest {
1913

2014
@Autowired
2115
private RedisTemplate<String,String> redisTemplate ;
@@ -24,6 +18,6 @@ public class RedisTest {
2418
public void test(){
2519
redisTemplate.opsForValue().set("test","test") ;
2620
String test = redisTemplate.opsForValue().get("test");
27-
System.out.println("====" + test);
21+
Assertions.assertEquals("test",test);
2822
}
2923
}

cim-forward-route/src/test/java/com/crossoverjie/cim/route/service/impl/UserInfoCacheServiceImplTest.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
import com.crossoverjie.cim.common.pojo.CIMUserInfo;
55
import com.crossoverjie.cim.route.RouteApplication;
66
import com.crossoverjie.cim.route.service.UserInfoCacheService;
7+
import java.util.Set;
78
import lombok.extern.slf4j.Slf4j;
8-
import org.junit.Test;
9-
import org.junit.runner.RunWith;
9+
import org.junit.jupiter.api.Test;
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.boot.test.context.SpringBootTest;
12-
import org.springframework.test.context.junit4.SpringRunner;
13-
14-
import java.util.Set;
1512

1613
@Slf4j
1714
@SpringBootTest(classes = RouteApplication.class)
18-
@RunWith(SpringRunner.class)
19-
public class UserInfoCacheServiceImplTest {
15+
public class UserInfoCacheServiceImplTest extends AbstractBaseTest{
2016

2117
@Autowired
2218
private UserInfoCacheService userInfoCacheService;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
spring:
2+
application:
3+
name: cim-forward-route
4+
data:
5+
redis:
6+
host: 127.0.0.1
7+
port: 6379
8+
jedis:
9+
pool:
10+
max-active: 100
11+
max-idle: 100
12+
max-wait: 1000
13+
min-idle: 10
14+
# web port
15+
server:
16+
port: 8083
17+
18+
logging:
19+
level:
20+
root: info
21+
22+
# enable swagger
23+
springdoc:
24+
swagger-ui:
25+
enabled: true
26+
27+
app:
28+
zk:
29+
addr: 127.0.0.1:2181
30+
connect:
31+
timeout: 30000
32+
root: /route
33+
34+
# route strategy
35+
#app.route.way=com.crossoverjie.cim.common.route.algorithm.loop.LoopHandle
36+
37+
# route strategy
38+
#app.route.way=com.crossoverjie.cim.common.route.algorithm.random.RandomHandle
39+
40+
# route strategy
41+
route:
42+
way:
43+
handler: com.crossoverjie.cim.common.route.algorithm.consistenthash.ConsistentHashHandle
44+
45+
#app.route.way.consitenthash=com.crossoverjie.cim.common.route.algorithm.consistenthash.SortArrayMapConsistentHash
46+
47+
consitenthash: com.crossoverjie.cim.common.route.algorithm.consistenthash.TreeMapConsistentHash
48+
49+

cim-server/src/test/com/crossoverjie/cim/server/util/NettyAttrUtilTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.crossoverjie.cim.server.util;
22

33

4-
import org.junit.Test;
54

65
import java.util.concurrent.TimeUnit;
6+
import org.junit.jupiter.api.Test;
77

88
public class NettyAttrUtilTest {
99

0 commit comments

Comments
 (0)