Search in sources :

Example 1 with SearchServerInstance

use of org.graylog.testing.elasticsearch.SearchServerInstance in project graylog2-server by Graylog2.

the class SearchServerInstanceFactoryByVersion method doCreate.

private SearchServerInstance doCreate(final String cName, final SearchVersion version, final Network network) {
    try {
        Class<?> clazz = Class.forName(cName);
        Method method = clazz.getMethod("create", SearchVersion.class, Network.class);
        return (SearchServerInstance) method.invoke(null, version, network);
    } catch (Exception ex) {
        throw new NotImplementedException("Could not create Search instance.", ex);
    }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Method(java.lang.reflect.Method) SearchServerInstance(org.graylog.testing.elasticsearch.SearchServerInstance) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 2 with SearchServerInstance

use of org.graylog.testing.elasticsearch.SearchServerInstance 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

SearchServerInstance (org.graylog.testing.elasticsearch.SearchServerInstance)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Method (java.lang.reflect.Method)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)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