Search in sources :

Example 1 with Network

use of org.testcontainers.containers.Network in project flink by apache.

the class KafkaTestEnvironmentImpl method startKafkaContainerCluster.

private void startKafkaContainerCluster(int numBrokers) {
    Network network = Network.newNetwork();
    if (numBrokers > 1) {
        zookeeper = createZookeeperContainer(network);
        zookeeper.start();
        LOG.info("Zookeeper container started");
    }
    for (int brokerID = 0; brokerID < numBrokers; brokerID++) {
        KafkaContainer broker = createKafkaContainer(network, brokerID, zookeeper);
        brokers.put(brokerID, broker);
    }
    new ArrayList<>(brokers.values()).parallelStream().forEach(GenericContainer::start);
    LOG.info("{} brokers started", numBrokers);
    brokerConnectionString = brokers.values().stream().map(KafkaContainer::getBootstrapServers).map(server -> server.split("://")[1]).collect(Collectors.joining(","));
}
Also used : Network(org.testcontainers.containers.Network) ArrayList(java.util.ArrayList) GenericContainer(org.testcontainers.containers.GenericContainer) KafkaContainer(org.testcontainers.containers.KafkaContainer)

Example 2 with Network

use of org.testcontainers.containers.Network in project drill by apache.

the class MongoBaseTest method initCluster.

private static String initCluster() throws IOException, InterruptedException {
    Network network = Network.newNetwork();
    initConfigServer(network);
    initShardServers(network);
    String connectionString = initMongos(network);
    shardCollection();
    return connectionString;
}
Also used : Network(org.testcontainers.containers.Network)

Example 3 with Network

use of org.testcontainers.containers.Network in project graylog2-server by Graylog2.

the class ContainerizedGraylogBackend method create.

private void create(SearchVersion esVersion, MongodbServer mongodbVersion, int[] extraPorts, List<URL> mongoDBFixtures, PluginJarsProvider pluginJarsProvider, MavenProjectDirProvider mavenProjectDirProvider) {
    final SearchServerInstanceFactory searchServerInstanceFactory = new SearchServerInstanceFactoryByVersion(esVersion);
    Network network = Network.newNetwork();
    ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("build-es-container-for-api-it").build());
    Future<SearchServerInstance> esFuture = executor.submit(() -> searchServerInstanceFactory.create(network));
    MongoDBInstance mongoDB = MongoDBInstance.createStartedWithUniqueName(network, Lifecycle.CLASS, mongodbVersion);
    mongoDB.dropDatabase();
    mongoDB.importFixtures(mongoDBFixtures);
    try {
        // Wait for ES before starting the Graylog node to avoid any race conditions
        SearchServerInstance esInstance = esFuture.get();
        NodeInstance node = NodeInstance.createStarted(network, MongoDBInstance.internalUri(), esInstance.internalUri(), esInstance.version(), extraPorts, pluginJarsProvider, mavenProjectDirProvider);
        this.network = network;
        this.searchServer = esInstance;
        this.mongodb = mongoDB;
        this.node = node;
        // ensure that all containers and networks will be removed after all tests finish
        // We can't close the resources in an afterAll callback, as the instances are cached and reused
        // so we need a solution that will be triggered only once after all test classes
        Runtime.getRuntime().addShutdownHook(new Thread(this::close));
    } catch (InterruptedException | ExecutionException | ExecutableNotFoundException e) {
        LOG.error("Container creation aborted", e);
        throw new RuntimeException(e);
    } finally {
        executor.shutdown();
    }
}
Also used : SearchServerInstance(org.graylog.testing.elasticsearch.SearchServerInstance) ExecutableNotFoundException(org.graylog.testing.graylognode.ExecutableNotFoundException) Network(org.testcontainers.containers.Network) MongoDBInstance(org.graylog.testing.mongodb.MongoDBInstance) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ExecutionException(java.util.concurrent.ExecutionException) NodeInstance(org.graylog.testing.graylognode.NodeInstance)

Aggregations

Network (org.testcontainers.containers.Network)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 SearchServerInstance (org.graylog.testing.elasticsearch.SearchServerInstance)1 ExecutableNotFoundException (org.graylog.testing.graylognode.ExecutableNotFoundException)1 NodeInstance (org.graylog.testing.graylognode.NodeInstance)1 MongoDBInstance (org.graylog.testing.mongodb.MongoDBInstance)1 GenericContainer (org.testcontainers.containers.GenericContainer)1 KafkaContainer (org.testcontainers.containers.KafkaContainer)1