Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Route & server support test #145

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cim-forward-route/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.clever-cloud</groupId>
<artifactId>testcontainers-zookeeper</artifactId>
</dependency>

<dependency>
<groupId>com.redis</groupId>
<artifactId>testcontainers-redis</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand All @@ -29,7 +24,6 @@ public void loadRouteRelated() throws Exception {
Map<Long, CIMServerResVO> longCIMServerResVOMap = accountService.loadRouteRelated();
log.info("longCIMServerResVOMap={},cun={}" , JSON.toJSONString(longCIMServerResVOMap),i);
}
TimeUnit.SECONDS.sleep(10);
}

}
Original file line number Diff line number Diff line change
@@ -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<String,String> redisTemplate ;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions cim-forward-route/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -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


Original file line number Diff line number Diff line change
@@ -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 {

Expand Down