@Override @Deprecated protected void finished(Description description) { this.stop(); }
@Override public void stop() { if (driver != null) { try { driver.quit(); } catch (Exception e) { LOGGER.debug("Failed to quit the driver", e); } } if (vncRecordingContainer != null) { try { vncRecordingContainer.stop(); } catch (Exception e) { LOGGER.debug("Failed to stop vncRecordingContainer", e); } } super.stop(); }
public static void main(String[] args) { Thread mainThread = Thread.currentThread(); GenericContainer genericContainer = null; try { genericContainer = new GenericContainer().withCommand("top"); genericContainer.start(); Set<Thread> threads = new HashSet<>(Thread.getAllStackTraces().keySet()); threads.remove(mainThread); Set<Thread> nonDaemonThreads = threads.stream().filter(it -> !it.isDaemon()).collect(Collectors.toSet()); if (nonDaemonThreads.isEmpty()) { VisibleAssertions.pass("All threads marked as daemon"); } else { String nonDaemonThreadNames = nonDaemonThreads.stream() .map(Thread::getName) .collect(Collectors.joining("\n", "\n", "")); VisibleAssertions.fail("Expected all threads to be daemons but the following are not:\n" + nonDaemonThreadNames); } } finally { if (genericContainer != null) { genericContainer.stop(); } } }
protected void verifyImage(ImageFromDockerfile image) { GenericContainer container = new GenericContainer(image); try { container.start(); pass("Should start from Dockerfile"); } finally { container.stop(); } } }
@SneakyThrows protected void assertResponse(GenericContainer container) { try { container.start(); String response = container.execInContainer("wget", "-O", "-", "http://host.testcontainers.internal:" + server.getAddress().getPort()).getStdout(); assertEquals("received response", "Hello World!", response); } finally { container.stop(); } } }
@Test @Ignore //TODO investigate intermittent failures public void failFastWhenContainerHaltsImmediately() throws Exception { long startingTimeMs = System.currentTimeMillis(); final GenericContainer failsImmediately = new GenericContainer("alpine:3.2") .withCommand("/bin/sh", "-c", "return false") .withMinimumRunningDuration(Duration.ofMillis(100)); try { assertThrows( "When we start a container that halts immediately, an exception is thrown", RetryCountExceededException.class, () -> { failsImmediately.start(); return null; }); // Check how long it took, to verify that we ARE bailing out early. // Want to strike a balance here; too short and this test will fail intermittently // on slow systems and/or due to GC variation, too long and we won't properly test // what we're intending to test. int allowedSecondsToFailure = GenericContainer.CONTAINER_RUNNING_TIMEOUT_SEC / 2; long completedTimeMs = System.currentTimeMillis(); assertTrue("container should not take long to start up", completedTimeMs - startingTimeMs < 1000L * allowedSecondsToFailure); } finally { failsImmediately.stop(); } }
@Test public void testFixedHostPortMapping() throws IOException { // first find a free port on the docker host that will work for testing GenericContainer portDiscoveryRedis = new GenericContainer("redis:3.0.2").withExposedPorts(REDIS_PORT); portDiscoveryRedis.start(); Integer freePort = portDiscoveryRedis.getMappedPort(REDIS_PORT); portDiscoveryRedis.stop(); // Set up a FixedHostPortGenericContainer as if this were a @Rule FixedHostPortGenericContainer redis = new FixedHostPortGenericContainer("redis:3.0.2").withFixedExposedPort(freePort, REDIS_PORT); redis.start(); // Config redisConfig = new Config(); // redisConfig.useSingleServer().setAddress(redis.getContainerIpAddress() + ":" + freePort); // Redisson redisson = Redisson.create(redisConfig); // // redisson.getBucket("test").set("foo"); // // assertEquals("The bucket content was successfully set", "foo", redisson.getBucket("test").get()); // assertEquals("The container returns the fixed port from getMappedPort(...)", freePort, redis.getMappedPort(REDIS_PORT)); } }
container.stop();
@AfterClass public static void tearDown() { if (mongo != null) { mongo.stop(); db.shutdown(); } }
@Override @Deprecated protected void finished(Description description) { this.stop(); }
@AfterClass void after() { if (gitlab != null) { gitlab.stop(); gitlab = null; } }
@AfterClass void after() { if (gitea != null) { gitea.stop(); gitea = null; } } }
@Override public void evaluate() throws Throwable { try { container.start(); statement.evaluate(); } finally { container.stop(); } } };
@AfterClass public static void stopContainer() { if (container != null) { container.stop(); } }
private void restartContainer() { iterationsBeforeRestart.set(iterationsBetweenRestart); container.stop(); container.start(); }
private void restartContainer() { iterationsBeforeRestart.set(iterationsBetweenRestart); container.stop(); container.start(); }
public void stop() { if (cassandraContainer.isRunning()) { cassandraContainer.stop(); } }
public void stop() { if (cassandraContainer.isRunning()) { cassandraContainer.stop(); } }