带有SSL/TLS的Testcontainers RabbitMq无法等待容器启动



我在Testcontainers中使用RabbitMq进行了一个测试。测试使用HTTP

@Container private static final RabbitMQContainer RABBITMQ_CONTAINER =
new RabbitMQContainer()
.withLogConsumer(new Slf4jLogConsumer(LOG))
.withStartupTimeout(Duration.of(5, ChronoUnit.MINUTES))
.waitingFor(Wait.forHttp("/api/vhosts")
.forPort(15672)
.withBasicCredentials("guest", "guest"));

当我切换到HTTPS 时失败

@Container private static final RabbitMQContainer RABBITMQ_CONTAINER =
new RabbitMQContainer()
.withLogConsumer(new Slf4jLogConsumer(LOG))
.withStartupTimeout(Duration.of(5, ChronoUnit.MINUTES))
.waitingFor(Wait.forHttp("/api/vhosts")
.usingTls()
.forPort(15671)
.withBasicCredentials("guest", "guest"))
.withSSL(forClasspathResource("/certs/server_key.pem", 0644),
forClasspathResource("/certs/server_certificate.pem", 0644),
forClasspathResource("/certs/ca_certificate.pem", 0644),
VERIFY_NONE,
false);

在日志中,我看到容器无法启动:

...
18:53:21.274 [main] INFO  - /brave_swirles: Waiting for 60 seconds for URL: https://localhost:50062/api/vhosts (where port 50062 maps to container port 15671)
...
18:54:21.302 [main] ERROR - Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for URL to be accessible (https://localhost:50062/api/vhosts should return HTTP 200)

我想念什么?我希望至少Testcontainers的等待策略有效。

RabbitMQContainer与自定义SSL证书一起使用会使HttpWaitStrategy也难以使用。在这种情况下,您可能需要配置整个JVM来信任那些SSL证书。

或者,只需继续使用默认的等待策略(将是LogMessageWaitStrategy(。

有关进一步的示例,只需查看Testcontainers本身中的RabbitMQContainer测试即可:https://github.com/testcontainers/testcontainers-java/blob/c3f53b3a63e6b0bc800a7f0fbce91ce95a8986b3/modules/rabbitmq/src/test/java/org/testcontainers/containers/RabbitMQContainerTest.java#L237-L264

相关内容

最新更新