/** * Convenience method to return a WaitStrategy for log messages. * * @param regex the regex pattern to check for * @param times the number of times the pattern is expected * @return LogMessageWaitStrategy */ public static LogMessageWaitStrategy forLogMessage(String regex, int times) { return new LogMessageWaitStrategy().withRegEx(regex).withTimes(times); }
@Override protected void waitUntilReady() { delegateWaitStrategy.waitUntilReady(this.waitStrategyTarget); }
/** * Creates a Testcontainer using a specific docker image. * * @param dockerImageName The docker image to use. */ public Neo4jContainer(String dockerImageName) { super(dockerImageName); WaitStrategy waitForBolt = new LogMessageWaitStrategy() .withRegEx(String.format(".*Bolt enabled on 0\\.0\\.0\\.0:%d\\.\n", DEFAULT_BOLT_PORT)); WaitStrategy waitForHttp = new HttpWaitStrategy() .forPort(DEFAULT_HTTP_PORT) .forStatusCodeMatching(response -> response == HTTP_OK); this.waitStrategy = new WaitAllStrategy() .withStrategy(waitForBolt) .withStrategy(waitForHttp) .withStartupTimeout(Duration.ofMinutes(2)); }
public LogMessageWaitStrategy withTimes(int times) { delegateWaitStrategy.withTimes(times); return this; } }
public LogMessageWaitStrategy withRegEx(String regEx) { delegateWaitStrategy.withRegEx(regEx); return this; }
@Test public void testWaitOnOneOfMultipleStrategiesFailing() { final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml")) .withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(10))) .waitingFor("db_1", Wait.forLogMessage(".*test test test.*\\s", 1).withStartupTimeout(Duration.ofSeconds(10))) .withTailChildContainers(true); VisibleAssertions.assertThrows("waiting on one failing strategy to time out", RuntimeException.class, () -> environment.starting(Description.createTestDescription(Object.class, "name"))); }
@NotNull @Override protected LogMessageWaitStrategy buildWaitStrategy(AtomicBoolean ready) { return new LogMessageWaitStrategy() { @Override protected void waitUntilReady() { super.waitUntilReady(); ready.set(true); } }.withRegEx(pattern).withTimes(2); } }
public LogMessageWaitStrategy withRegEx(String regEx) { delegateWaitStrategy.withRegEx(regEx); return this; }
private GenericContainer<?> getContainer(String image, int port, Network network, String logWaitRegex, int logWaitTimes, boolean matchExposedPort) { GenericContainer<?> container = new GenericContainer<>(image) .withExposedPorts(port) .waitingFor( Wait.forLogMessage(logWaitRegex, logWaitTimes).withStartupTimeout(Duration.ofMinutes(5L)) ); if (network != null) { container.withNetwork(network); } if(matchExposedPort) { container.withCreateContainerCmdModifier( command -> command.withPortBindings(PortBinding.parse(String.format("%d:%d", port, port))) ); } return container; }
/** * Convenience method to return a WaitStrategy for log messages. * * @param regex the regex pattern to check for * @param times the number of times the pattern is expected * @return LogMessageWaitStrategy */ public static LogMessageWaitStrategy forLogMessage(String regex, int times) { return new LogMessageWaitStrategy().withRegEx(regex).withTimes(times); }
@Override protected void waitUntilReady() { super.waitUntilReady(); ready.set(true); } }.withRegEx(pattern).withTimes(2);
public LogMessageWaitStrategy withTimes(int times) { delegateWaitStrategy.withTimes(times); return this; } }
@Override protected void waitUntilReady() { delegateWaitStrategy.waitUntilReady(this.waitStrategyTarget); }