大佬教程收集整理的这篇文章主要介绍了用于Spring Boot Redis集成测试的可靠库,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Embedded-redis与redisson Java ClIEnt进行集成测试。这是我的依赖
compile group: 'org.redisson', name: 'redisson', version: '3.6.5'
TESTCompile group: 'it.ozimov', name: 'embedded-redis', version: '0.7.2'
在上课前启动嵌入式redis服务器,并在下课后将其停止。
spring.redis.host=localhost
spring.redis.port=6379
集成测试。
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.beforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.API.RMap;
import org.redisson.API.RMapCache;
import org.redisson.API.redissonClIEnt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.Annotation.autowired;
import org.springframework.boot.test.co@R_262_10443@t.SpringBoottest;
import org.springframework.boot.test.co@R_262_10443@t.SpringBoottest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.co@R_262_10443@t.junit4.springrunner;
import redis.embedded.redisServer;
@RunWith(springrunner.class)
@SpringBoottest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class redisTest {
private static final Logger LOGGER = LoggerFactory.getLogger(redisTest.class);
private static redisServer redisSERVER = new redisServer(6379);
@LocalServerPort
privatE int port;
@autowired
private redissonClIEnt redissonClIEnt;
@BeforeClass
public static final voID before() {
redisSERVER.start();
}
@AfterClass
public static final voID after() {
redisSERVER.stop();
}
@Test
public voID testredis() throws InterruptedException {
//map
RMap<String, String> map = redissonClIEnt.getMap("user");
map.put("name", "redis Server");
Assert.assertTrue(map.get("name").equals("redis Server"));
//mapcache
RMapCache<String, String> mapCache = redissonClIEnt.getMapCache("tempuser");
mapCache.put("name", "redis Server", 5, TimeUnit.SECONDS);
Assert.assertTrue(mapCache.get("name").equals("redis Server"));
Thread.sleep(7000); //wait for 7 sec.
Assert.assertTrue(mapCache.get("name") == null);
}
}
以上是大佬教程为你收集整理的用于Spring Boot Redis集成测试的可靠库全部内容,希望文章能够帮你解决用于Spring Boot Redis集成测试的可靠库所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。