@Test public void testExternalZookeeperWithKafkaNetwork() throws Exception { try ( KafkaContainer kafka = new KafkaContainer() .withExternalZookeeper("zookeeper:2181"); GenericContainer zookeeper = new GenericContainer("confluentinc/cp-zookeeper:4.0.0") .withNetwork(kafka.getNetwork()) .withNetworkAliases("zookeeper") .withEnv("ZOOKEEPER_CLIENT_PORT", "2181"); ) { Stream.of(kafka, zookeeper).parallel().forEach(GenericContainer::start); testKafkaFunctionality(kafka.getBootstrapServers()); } }
@Test public void testExternalZookeeperWithExternalNetwork() throws Exception { try ( Network network = Network.newNetwork(); KafkaContainer kafka = new KafkaContainer() .withNetwork(network) .withExternalZookeeper("zookeeper:2181"); GenericContainer zookeeper = new GenericContainer("confluentinc/cp-zookeeper:4.0.0") .withNetwork(network) .withNetworkAliases("zookeeper") .withEnv("ZOOKEEPER_CLIENT_PORT", "2181"); ) { Stream.of(kafka, zookeeper).parallel().forEach(GenericContainer::start); testKafkaFunctionality(kafka.getBootstrapServers()); } }
@Test public void testNetworkSupport() throws Exception { try ( Network network = newNetwork(); GenericContainer foo = new GenericContainer() .withNetwork(network) .withNetworkAliases("foo") .withCommand("/bin/sh", "-c", "while true ; do printf 'HTTP/1.1 200 OK\\n\\nyay' | nc -l -p 8080; done"); GenericContainer bar = new GenericContainer() .withNetwork(network) .withCommand("top") ) { foo.start(); bar.start(); String response = bar.execInContainer("wget", "-O", "-", "http://foo:8080").getStdout(); assertEquals("received response", "yay", response); } }
@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(); }