Skip to content

Commit

Permalink
OpenSearch tests to use explicitly versioned Docker image, fixes #1147
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Nioche <[email protected]>
  • Loading branch information
jnioche committed Feb 21, 2024
1 parent 32eab34 commit 4b9a8a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,17 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

public class IndexerBoltTest {

@Rule public Timeout globalTimeout = Timeout.seconds(120);
public class IndexerBoltTest extends AbstractOpenSearchTest {

private IndexerBolt bolt;
protected TestOutputCollector output;

private static final Logger LOG = LoggerFactory.getLogger(IndexerBoltTest.class);

private static ExecutorService executorService;

@BeforeClass
Expand All @@ -65,14 +60,6 @@ public static void afterClass() {
executorService = null;
}

@Rule
public GenericContainer opensearchContainer =
new GenericContainer(DockerImageName.parse("opensearchproject/opensearch:latest"))
.withExposedPorts(9200)
.withEnv("plugins.security.disabled", "true")
.withEnv("discovery.type", "single-node")
.withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m");

@Before
public void setupIndexerBolt() {

Expand All @@ -96,6 +83,7 @@ public void setupIndexerBolt() {
@After
public void close() {
LOG.info("Closing indexer bolt and Opensearch container");
super.close();
bolt.cleanup();
output = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.opensearch.action.get.GetRequest;
import org.opensearch.action.get.GetResponse;
import org.opensearch.client.RequestOptions;
Expand All @@ -51,10 +49,8 @@
import org.opensearch.client.RestHighLevelClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

public class StatusBoltTest {
public class StatusBoltTest extends AbstractOpenSearchTest {

private StatusUpdaterBolt bolt;
protected TestOutputCollector output;
Expand All @@ -64,16 +60,6 @@ public class StatusBoltTest {
private static final Logger LOG = LoggerFactory.getLogger(StatusBoltTest.class);
private static ExecutorService executorService;

@Rule public Timeout globalTimeout = Timeout.seconds(60);

@Rule
public final GenericContainer container =
new GenericContainer(DockerImageName.parse("opensearchproject/opensearch:latest"))
.withExposedPorts(9200)
.withEnv("plugins.security.disabled", "true")
.withEnv("discovery.type", "single-node")
.withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m");

@BeforeClass
public static void beforeClass() {
executorService = Executors.newFixedThreadPool(2);
Expand All @@ -92,7 +78,9 @@ public void setupStatusBolt() throws IOException {

RestClientBuilder builder =
RestClient.builder(
new HttpHost(container.getHost(), container.getMappedPort(9200)));
new HttpHost(
opensearchContainer.getHost(),
opensearchContainer.getMappedPort(9200)));

client = new RestHighLevelClient(builder);

Expand All @@ -103,7 +91,7 @@ public void setupStatusBolt() throws IOException {

conf.put(
"opensearch.status.addresses",
container.getHost() + ":" + container.getFirstMappedPort());
opensearchContainer.getHost() + ":" + opensearchContainer.getFirstMappedPort());

conf.put("scheduler.class", "com.digitalpebble.stormcrawler.persistence.DefaultScheduler");

Expand All @@ -119,8 +107,8 @@ public void setupStatusBolt() throws IOException {
@After
public void close() {
LOG.info("Closing updater bolt and Opensearch container");
super.close();
bolt.cleanup();
container.close();
output = null;
try {
client.close();
Expand Down

0 comments on commit 4b9a8a6

Please sign in to comment.