使用SSL/TLS的测试容器RabbitMq无法等待容器启动

ngynwnxp  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(1)|浏览(165)

我在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)

我错过了什么?我希望至少测试容器的等待策略是有效的。

hc8w905p

hc8w905p1#

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

相关问题