Search in sources :

Example 1 with NodeInstance

use of org.graylog.testing.graylognode.NodeInstance 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

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)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 Network (org.testcontainers.containers.Network)1