2021-01-14 17:09:34 +08:00
|
|
|
package we.stats.ratelimit;
|
|
|
|
|
|
2021-01-18 15:25:12 +08:00
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
2021-01-14 17:09:34 +08:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.test.context.TestPropertySource;
|
|
|
|
|
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
2021-01-18 15:25:12 +08:00
|
|
|
import redis.embedded.RedisServer;
|
2021-01-14 17:09:34 +08:00
|
|
|
import we.redis.RedisProperties;
|
|
|
|
|
import we.redis.RedisServerConfiguration;
|
2021-01-15 19:20:09 +08:00
|
|
|
import we.redis.RedisTemplateConfiguration;
|
2021-01-14 17:09:34 +08:00
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
2021-01-15 19:20:09 +08:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
|
2021-01-14 17:09:34 +08:00
|
|
|
/**
|
|
|
|
|
* @author hongqiaowei
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@TestPropertySource("/application.properties")
|
|
|
|
|
@SpringJUnitConfig(classes = {RedisProperties.class, RedisTemplateConfiguration.class, RedisServerConfiguration.class})
|
|
|
|
|
// @ActiveProfiles("unittest")
|
|
|
|
|
public class ResourceRateLimitConfigServiceTests {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private RedisProperties redisProperties;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
2021-01-18 15:25:12 +08:00
|
|
|
ResourceRateLimitConfigService resourceRateLimitConfigService;
|
|
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
|
void beforeAllTests() {
|
|
|
|
|
resourceRateLimitConfigService = new ResourceRateLimitConfigService();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 17:09:34 +08:00
|
|
|
@Test
|
2021-01-15 19:20:09 +08:00
|
|
|
void initTest() throws InterruptedException {
|
2021-01-14 17:09:34 +08:00
|
|
|
System.err.println(redisProperties);
|
|
|
|
|
System.err.println(stringRedisTemplate);
|
2021-01-15 19:20:09 +08:00
|
|
|
stringRedisTemplate.opsForValue().set("name", "F-22");
|
|
|
|
|
Thread.sleep(2000);
|
|
|
|
|
String name = stringRedisTemplate.opsForValue().get("name");
|
|
|
|
|
assertEquals(name, "F-22");
|
|
|
|
|
System.err.println(name);
|
2021-01-14 17:09:34 +08:00
|
|
|
}
|
|
|
|
|
}
|