程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了用于Spring Boot Redis集成测试的可靠库大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决用于Spring Boot redis集成测试的可靠库?

开发过程中遇到用于Spring Boot redis集成测试的可靠库的问题如何解决?下面主要结合日常开发的经验,给出你关于用于Spring Boot redis集成测试的可靠库的解决方法建议,希望对你解决用于Spring Boot redis集成测试的可靠库有所启发或帮助;

我正在使用Embedded-redisredisson 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配置,并在可能的情况下针对嵌入式redis缓存进行测试。

我最近来的是这个https://github.com/kstyrc/embedded-
redis

这样做的问题是缺少健壮的日志记录使其难以运行-它在本地运行,但是当我将其推上后,Unix服务器就在构建机器,它失败了,不知道为什么。

如果有人对如何以这种方式运行集成测试有任何想法,那就太好了。

谢谢,

斯特凡

大佬总结

以上是大佬教程为你收集整理的用于Spring Boot Redis集成测试的可靠库全部内容,希望文章能够帮你解决用于Spring Boot Redis集成测试的可靠库所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。