valkey / redis testContainerconfig

问题描述 投票:0回答:0
@ActiveProfiles("integration-test") @Testcontainers @SpringBootTest @AutoConfigureMockMvc @Slf4j public abstract class BaseIntegrationTest { @Autowired protected MockMvc mockMvc; @Autowired protected IntegrationTestDataConfig integrationTestDataConfig; @Container @ServiceConnection static final PostgreSQLContainer<?> POSTGRES_CONTAINER = new PostgreSQLContainer<>("postgres:latest") .withDatabaseName("testdb") .withUsername("test") .withPassword("test"); @Container static final GenericContainer<?> valkeyContainer = new GenericContainer<>("valkey/valkey:8.0.0") .withExposedPorts(6379) .withCommand("valkey-server", "/etc/valkey/valkey.conf") .withClasspathResourceMapping("config/valkey.conf", "/etc/valkey/valkey.conf", BindMode.READ_ONLY) .waitingFor(Wait.forLogMessage(".*Ready to accept connections.*\\n", 1)); @DynamicPropertySource static void registerValkeyProperties(DynamicPropertyRegistry registry) { registry.add("spring.data.redis.host", valkeyContainer::getHost); registry.add("spring.data.redis.port", () -> valkeyContainer.getMappedPort(6379)); } }

您可以使用通用审查器,我不确定是否正在使用正确的comand来复制配置文件,或者是否使用此不确定的alltogether

这是conf file

bind 0.0.0.0 -::1 protected-mode no
这些是应在测试环境中覆盖的.yml属性:

spring: data: redis: host: ${VALKEY_HOST:<censored>} port: ${VALKEY_PORT:<censored>} password: ${VALKEY_PASSWORD:<censored>}

目前,测试容器开始正常,但是我的生菜连接工厂似乎无法解析地址和端口
2025-02-25T11:35:11.159+01:00  INFO 15996 --- [xecutorLoop-1-2] i.l.core.protocol.ConnectionWatchdog     : Reconnecting, last destination was localhost/127.0.0.1:52306
2025-02-25T11:35:11.168+01:00  WARN 15996 --- [ioEventLoop-6-2] i.l.core.protocol.ConnectionWatchdog     : Cannot reconnect to [localhost/<unresolved>:52306]: Connection closed prematurely

I通过日志确认,随机映射的端口(例如52306)与valkeyContainer.getMappedport(6379)相同,但是连接几乎立即失败。我不确定我是否使用正确的命令(valkey-server /etc/valkey/valkey.conf),是否正确,是否正确,或者是否有valkey所需的其他环境变量。

AM我正确使用通用牙本质,或者我应该使用redis或valkey特定的容器?

我的congig文件正确吗?
我使用.yml文件中的正确属性?

    我应该切换到旧版本的redis或其他键值存储(当前使用valkey用于长表格的自动车辆功能)吗?
  1. 我很难找到好的文档或指南,在哪里可以找到有关Valkey TestContainers及其设置的更多信息?

  2. 我试图使用重新介绍剂,但是TestContainer甚至都不会启动
  3. 使用不同的绑定config如
  4. bind 127.0.0.1 -::1

  5. 10秒的启动启动时间
  6. 不想,这只是一个春季构曲蛋白问题。与这个问题相同:

    测试后的连接丧失了一些测试 我缺少@dirtiescontesxt Annotation
java spring testing redis valkey
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.