【发布时间】:2021-10-24 16:11:53
【问题描述】:
我正在使用测试容器对 micronaut 应用程序进行集成测试和端到端测试。
这里是测试容器的配置
@Testcontainers
public abstract class TestContainerFixture {
protected static final GenericContainer mongoDBContainer;
protected static final Map<String, Object> properties;
static {
mongoDBContainer = new GenericContainer(DockerImageName.parse("mongo:4.0.10"))
.withExposedPorts(27017)
.withReuse(true);
mongoDBContainer.start();
properties = Map.of("mongodb.uri",
String.format("mongodb://%s:%s", mongoDBContainer.getContainerIpAddress(), mongoDBContainer.getMappedPort(27017)));
}
protected ApplicationContext applicationContext;
}
扩展测试容器的类
public class DiscountUpdateListenerTest extends TestContainerFixture {
}
因为我使用.withReuse(true); 为所有其他测试类重用测试容器。如果我在集成测试运行时禁用每个类上的.withReuse(false),则会创建容器,这需要更长的时间来执行测试。
所以,为了重用同一个容器,我使用了 .withReuse(true) 功能。由于容器在那里停留的时间更长。所以我想每 1-2 小时移除一次容器
【问题讨论】:
-
“所以我想每隔 1-2 小时删除一次容器” - 您是否想要一个脚本或每隔 1-2 小时运行一次的东西来删除某些容器?
-
@JeffScottBrown 我不确定如何处理这个问题。如果我长时间不使用,我只是要移除容器
标签: java junit micronaut testcontainers testcontainers-junit5