/** * 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)); }
/** * Create an Elasticsearch Container by passing the full docker image name * @param dockerImageName Full docker image name, like: docker.elastic.co/elasticsearch/elasticsearch:6.4.1 */ public ElasticsearchContainer(String dockerImageName) { super(dockerImageName); logger().info("Starting an elasticsearch container using [{}]", dockerImageName); withNetworkAliases("elasticsearch-" + Base58.randomString(6)); withEnv("discovery.type", "single-node"); addExposedPorts(ELASTICSEARCH_DEFAULT_PORT, ELASTICSEARCH_DEFAULT_TCP_PORT); setWaitStrategy(new HttpWaitStrategy() .forPort(ELASTICSEARCH_DEFAULT_PORT) .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED) .withStartupTimeout(Duration.ofMinutes(2))); }
public PulsarContainer(String pulsarVersion) { super(TestcontainersConfiguration.getInstance().getPulsarImage() + ":" + pulsarVersion); withExposedPorts(BROKER_PORT, BROKER_HTTP_PORT); withCommand("/pulsar/bin/pulsar", "standalone", "--no-functions-worker", "-nss"); waitingFor(Wait.forHttp(METRICS_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT)); }
/** * Expects the WaitStrategy probing the right port. */ @Test public void testWaitUntilReadyWithSpecificPort() { waitUntilReadyAndSucceed(startContainerWithCommand( createShellCommand("200 OK", GOOD_RESPONSE_BODY, 9090), createHttpWaitStrategy(ready) .forPort(9090), 7070, 8080, 9090 )); }
@BeforeClass public static void setUp() throws Exception { TestUtil.ignoreException(() -> { mongo = new GenericContainer("mongo:3") .withNetworkAliases("mongo-" + Base58.randomString(6)) .withExposedPorts(MONGO_DEFAULT_PORT) .waitingFor(new HttpWaitStrategy() .forPort(MONGO_DEFAULT_PORT) .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED) .withStartupTimeout(Duration.ofMinutes(2))); mongo.start(); }, Exception.class); assumeNotNull(mongo); assumeTrue("Mongo DB must be running", mongo.isRunning()); MongoClient mongoClient = new MongoClient(mongo.getContainerIpAddress(), mongo.getMappedPort(MONGO_DEFAULT_PORT)); HOST = String.format("mongodb://%s:%s", mongo.getContainerIpAddress(), mongo.getMappedPort(MONGO_DEFAULT_PORT)); params = map("host", HOST, "db", "test", "collection", "test"); MongoDatabase database = mongoClient.getDatabase("test"); collection = database.getCollection("test"); collection.deleteMany(new Document()); collection.insertOne(new Document(map("name", "testDocument", "date", currentTime, "longValue", longValue))); db = new TestGraphDatabaseFactory() .newImpermanentDatabaseBuilder() .newGraphDatabase(); TestUtil.registerProcedure(db, MongoDB.class); mongoClient.close(); }
/** * Create an Elasticsearch Container by passing the full docker image name * @param dockerImageName Full docker image name, like: docker.elastic.co/elasticsearch/elasticsearch:6.4.1 */ public ElasticsearchContainer(String dockerImageName) { super(dockerImageName); logger().info("Starting an elasticsearch container using [{}]", dockerImageName); withNetworkAliases("elasticsearch-" + Base58.randomString(6)); withEnv("discovery.type", "single-node"); addExposedPorts(ELASTICSEARCH_DEFAULT_PORT, ELASTICSEARCH_DEFAULT_TCP_PORT); setWaitStrategy(new HttpWaitStrategy() .forPort(ELASTICSEARCH_DEFAULT_PORT) .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED) .withStartupTimeout(Duration.ofMinutes(2))); }
public static GenericContainer<?> createTestContainer(final int testPort) { return new GenericContainer<>("localstack/localstack:latest") .withEnv("DEBUG", "1") .waitingFor(new HttpWaitStrategy().forStatusCode(200).forPort(testPort)); }
private WaitStrategy waitStrategy() { return new WaitAllStrategy() .withStrategy(Wait.forHttp("").forPort(DEFAULT_RABBITMQ_ADMIN_PORT) .withRateLimiter(RateLimiters.TWENTIES_PER_SECOND) .withStartupTimeout(TEN_MINUTES_TIMEOUT)) .withStrategy(new RabbitMQWaitStrategy(this, TEN_MINUTES_TIMEOUT)) .withStartupTimeout(TEN_MINUTES_TIMEOUT); }
public DockerSwiftContainer() { this.swiftContainer = new GenericContainer<>(SWIFT_DOCKER_IMAGE); this.swiftContainer .withExposedPorts(KEYSTONE_ADMIN_PORT) .withExposedPorts(SWIFT_PORT) .withLogConsumer(DockerSwiftContainer::displayDockerLog) .waitingFor( new WaitAllStrategy() .withStrategy( forHttp("/v3") .forPort(KEYSTONE_ADMIN_PORT) .forStatusCode(200) .withRateLimiter(RateLimiters.TWENTIES_PER_SECOND) ).withStrategy( forHttp("/info") .forPort(SWIFT_PORT) .forStatusCode(200) .withRateLimiter(RateLimiters.TWENTIES_PER_SECOND) ) ); }
.waitingFor(Wait.forHttp(path).forPort(giteaPort) .withStartupTimeout(Duration.of(120, ChronoUnit.SECONDS))); Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);