Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 与testcontainers和redis的连接超时_Spring Boot_Redis_Junit5_Testcontainers_Testcontainers Junit5 - Fatal编程技术网

Spring boot 与testcontainers和redis的连接超时

Spring boot 与testcontainers和redis的连接超时,spring-boot,redis,junit5,testcontainers,testcontainers-junit5,Spring Boot,Redis,Junit5,Testcontainers,Testcontainers Junit5,我使用SpringBoot、TestContainers、redis和JUnit5进行集成测试。 我面临着一种奇怪的行为,当我完成所有集成测试时,我一直让这个日志显示: 无法重新连接到[localhost:55133]:连接被拒绝:localhost/127.0.0.1:55133 这个例外是: org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuc

我使用SpringBoot、TestContainers、redis和JUnit5进行集成测试。 我面临着一种奇怪的行为,当我完成所有集成测试时,我一直让这个日志显示:

无法重新连接到[localhost:55133]:连接被拒绝:localhost/127.0.0.1:55133

这个例外是:

org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 1 minute(s)

at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:70)
但是我单独运行测试,我没有这种行为

我使用Junit5和Junit5扩展来启动和停止我的redis容器:

public class RedisTestContainerExtension implements BeforeAllCallback, AfterAllCallback {

    private GenericContainer<?> redis;

    @Override
    public void beforeAll(ExtensionContext extensionContext) throws Exception {
        redis = new GenericContainer<>(DockerImageName.parse("redis:5.0.3-alpine"))
                .withCommand("redis-server","--requirepass", "password")
                .waitingFor(Wait.forListeningPort())
                .withStartupTimeout(Duration.ofMinutes(2))
                .withExposedPorts(6379);
        redis.start();
        System.setProperty("APP_REDIS_CONVERSATIONS_HOST",redis.getHost());
        System.setProperty("APP_REDIS_CONVERSATIONS_PORT",redis.getFirstMappedPort().toString());
        System.setProperty("APP_REDIS_CONVERSATIONS_PASSWORD","password");
        System.setProperty("APP_REDIS_CONVERSATIONS_TTL","600m");
    }

    @Override
    public void afterAll(ExtensionContext extensionContext) throws Exception {
        if(redis != null){
            redis.stop();
        }
    }
}
有人能帮我解决这个问题吗

@ExtendWith({SpringExtension.class, RedisTestContainerExtension.class})
@SpringBootTest(classes = ConversationsApplication.class)
class MyIntegrationTest {
 ...
 }