/** * Wait until the container has started. * * @param container the container for which to wait */ default void waitUntilReady(GenericContainer container) { this.waitUntilReady((WaitStrategyTarget)container); }
/** * Convenience method to return a WaitStrategy for an HTTP endpoint. * * @param path the path to check * @return the WaitStrategy * @see HttpWaitStrategy */ public static HttpWaitStrategy forHttp(String path) { return new HttpWaitStrategy() .forPath(path); }
/** */ public BrowserWebDriverContainer() { final WaitStrategy logWaitStrategy = new LogMessageWaitStrategy() .withRegEx(".*(RemoteWebDriver instances should connect to|Selenium Server is up and running).*\n") .withStartupTimeout(Duration.of(15, SECONDS)); this.waitStrategy = new WaitAllStrategy() .withStrategy(logWaitStrategy) .withStrategy(new HostPortWaitStrategy()) .withStartupTimeout(Duration.of(15, SECONDS)); this.withRecordingFileFactory(new DefaultRecordingFileFactory()); }
public PostgreSQLContainer(final String dockerImageName) { super(dockerImageName); this.waitStrategy = new LogMessageWaitStrategy() .withRegEx(".*database system is ready to accept connections.*\\s") .withTimes(2) .withStartupTimeout(Duration.of(60, SECONDS)); }
/** * 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 configure() { withExposedPorts(HTTP_PORT, NATIVE_PORT); waitingFor( new HttpWaitStrategy() .forStatusCode(200) .forResponsePredicate(responseBody -> "Ok.".equals(responseBody)) .withStartupTimeout(Duration.ofMinutes(1)) ); }
@Test public void appliesOuterTimeout() { final WaitStrategy underTest = new WaitAllStrategy() .withStrategy(strategy1) .withStartupTimeout(Duration.ofMillis(10)); doAnswer(invocation -> { Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); return null; }).when(strategy1).waitUntilReady(eq(container)); assertThrows("The outer strategy timeout applies", TimeoutException.class, () -> { underTest.waitUntilReady(container); }); } }
@Test public void simpleTest() { final WaitStrategy underTest = new WaitAllStrategy() .withStrategy(strategy1) .withStrategy(strategy2); doNothing().when(strategy1).waitUntilReady(eq(container)); doNothing().when(strategy2).waitUntilReady(eq(container)); underTest.waitUntilReady(container); InOrder inOrder = inOrder(strategy1, strategy2); inOrder.verify(strategy1).waitUntilReady(any()); inOrder.verify(strategy2).waitUntilReady(any()); }
/** * Convenience method to return a WaitStrategy for an exposed or mapped port. * * @return the WaitStrategy * @see HostPortWaitStrategy */ public static HostPortWaitStrategy forListeningPort() { return new HostPortWaitStrategy(); }
/** * Convenience method to return the default WaitStrategy. * * @return a WaitStrategy */ public static WaitStrategy defaultWaitStrategy() { return forListeningPort(); }
@Override protected void waitUntilReady() { // execute select version query until success or timeout try { retryUntilSuccess((int) startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> { getRateLimiter().doWhenReady(() -> { try (DatabaseDelegate databaseDelegate = getDatabaseDelegate()) { databaseDelegate.execute(SELECT_VERSION_QUERY, "", 1, false, false); } }); return true; }); } catch (TimeoutException e) { throw new ContainerLaunchException(TIMEOUT_ERROR); } }
@Test public void testCassandraQueryWaitStrategy() { try ( CassandraContainer cassandraContainer = new CassandraContainer<>() .waitingFor(new CassandraQueryWaitStrategy()) ) { cassandraContainer.start(); ResultSet resultSet = performQuery(cassandraContainer, "SELECT release_version FROM system.local"); assertTrue("Query was not applied", resultSet.wasApplied()); } }
/** * 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); } }
/** * Convenience method to return a WaitStrategy for an HTTP endpoint. * * @param path the path to check * @return the WaitStrategy * @see HttpWaitStrategy */ public static HttpWaitStrategy forHttp(String path) { return new HttpWaitStrategy() .forPath(path); }
/** * Convenience method to return a WaitStrategy for an exposed or mapped port. * * @return the WaitStrategy * @see HostPortWaitStrategy */ public static HostPortWaitStrategy forListeningPort() { return new HostPortWaitStrategy(); }
@Override public void waitUntilReady(GenericContainer container) { Timeouts.doWithTimeout((int) timeout.toMillis(), TimeUnit.MILLISECONDS, () -> { for (WaitStrategy strategy : strategies) { strategy.waitUntilReady(container); } }); }
/** * Convenience method to return the default WaitStrategy. * * @return a WaitStrategy */ public static WaitStrategy defaultWaitStrategy() { return forListeningPort(); }
/** * Wait until the container has started. * * @param container the container for which to wait */ default void waitUntilReady(GenericContainer container) { this.waitUntilReady((WaitStrategyTarget)container); }