Skip to content

Commit 34627cb

Browse files
committed
GH-5498 initial test container commit
1 parent 089a4b0 commit 34627cb

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

compliance/elasticsearch/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
<version>${testcontainers.version}</version>
111111
<scope>test</scope>
112112
</dependency>
113+
<dependency>
114+
<groupId>org.testcontainers</groupId>
115+
<artifactId>junit-jupiter</artifactId>
116+
<version>${testcontainers.version}</version>
117+
<scope>test</scope>
118+
</dependency>
113119
<dependency>
114120
<groupId>org.apache.logging.log4j</groupId>
115121
<artifactId>log4j-core</artifactId>

compliance/elasticsearch/src/test/java/org/eclipse/rdf4j/sail/elasticsearch/AbstractElasticsearchTest.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@
2222
import org.elasticsearch.common.transport.TransportAddress;
2323
import org.elasticsearch.core.TimeValue;
2424
import org.elasticsearch.transport.client.PreBuiltTransportClient;
25-
import org.junit.AfterClass;
26-
import org.junit.Assume;
27-
import org.junit.BeforeClass;
25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.Assumptions;
27+
import org.junit.jupiter.api.BeforeAll;
2828
import org.testcontainers.containers.GenericContainer;
29+
import org.testcontainers.junit.jupiter.Container;
30+
import org.testcontainers.junit.jupiter.Testcontainers;
2931
import org.testcontainers.utility.DockerImageName;
3032

33+
@Testcontainers(disabledWithoutDocker = true)
3134
public abstract class AbstractElasticsearchTest {
3235

3336
protected static final String CLUSTER_NAME = "test";
3437

38+
@Container
3539
public static final GenericContainer<?> elasticsearch = new GenericContainer<>(dockerImageName())
3640
.withEnv("discovery.type", "single-node")
3741
.withEnv("cluster.name", CLUSTER_NAME)
@@ -45,22 +49,15 @@ public abstract class AbstractElasticsearchTest {
4549

4650
protected static TransportClient client;
4751

48-
@BeforeClass
52+
@BeforeAll
4953
public static void setUpCluster() throws Exception {
5054
System.out.println("Setting up elasticsearch cluster");
5155
if (client != null) {
5256
return;
5357
}
5458

55-
try {
56-
elasticsearch.start();
57-
} catch (IllegalStateException e) {
58-
Assume.assumeTrue("Docker is required to run Elasticsearch compliance tests:\n" + safeLogs(), false);
59-
}
60-
61-
if (!elasticsearch.isRunning()) {
62-
Assume.assumeTrue("Elasticsearch test container failed to stay running:\n" + safeLogs(), false);
63-
}
59+
Assumptions.assumeTrue(elasticsearch.isRunning(),
60+
"Elasticsearch test container failed to start:\n" + safeLogs());
6461

6562
Settings settings = Settings.builder().put("cluster.name", CLUSTER_NAME).build();
6663

@@ -75,15 +72,12 @@ public static void setUpCluster() throws Exception {
7572
client = transportClient;
7673
}
7774

78-
@AfterClass
75+
@AfterAll
7976
public static void tearDownCluster() {
8077
if (client != null) {
8178
client.close();
8279
client = null;
8380
}
84-
if (elasticsearch != null && elasticsearch.isRunning()) {
85-
elasticsearch.stop();
86-
}
8781
}
8882

8983
private static DockerImageName dockerImageName() {

0 commit comments

Comments
 (0)