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();
}
}
Aggregations