Skip to content

Commit

Permalink
fix: ci EsEmbeddedServer integration & acceptance test
Browse files Browse the repository at this point in the history
there has been a change in circle CI: port is bound on localhost
so there was a "Address already in use" error with the Embedded tests
  • Loading branch information
bamthomas committed Dec 3, 2024
1 parent 601ef75 commit 5adb411
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
name: acceptance test for embedded mode
command: |
VERSION=$(head pom.xml | grep '<version>[0-9.]\+' | sed 's/<version>\([0-9.]\+\)<\/version>/\1/g' | tr -d '[:space:]')
DS_ELASTICSEARCH_DATA_PATH=$HOME java -cp datashare-dist/target/datashare-dist-${VERSION}-all.jar org.icij.datashare.text.indexing.elasticsearch.EsEmbeddedServer -- 5
DS_ELASTICSEARCH_DATA_PATH=$HOME DS_ELASTICSEARCH_HTTP_PORT=9222 DS_ELASTICSEARCH_TRANSPORT_PORT=9333 java -cp datashare-dist/target/datashare-dist-${VERSION}-all.jar org.icij.datashare.text.indexing.elasticsearch.EsEmbeddedServer -- 5
- save_cache:
paths:
- ~/.m2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.concurrent.Executors;

import static java.util.Arrays.asList;
import static java.util.Optional.ofNullable;

/**
* inspired by :
* https://github.com/elastic/elasticsearch-hadoop/blob/fefcf8b191d287aca93a04144c67b803c6c81db5/mr/src/itest/java/org/elasticsearch/hadoop/EsEmbeddedServer.java
Expand All @@ -29,6 +31,10 @@ public class EsEmbeddedServer implements Closeable {
private final Node node;

public EsEmbeddedServer(String clusterName, String homePath, String dataPath, String httpPort) {
this(clusterName, homePath, dataPath, httpPort, "9300");
}

public EsEmbeddedServer(String clusterName, String homePath, String dataPath, String httpPort, String transportPort) {
Settings settings = Settings.builder()
.put("transport.type", "netty4")
.put("http.type", "netty4")
Expand All @@ -39,6 +45,7 @@ public EsEmbeddedServer(String clusterName, String homePath, String dataPath, St
.put("path.home", homePath)
.put("path.data", dataPath)
.put("http.port", httpPort)
.put("transport.port", transportPort)
.put("cluster.name", clusterName).build();
try {
node = createNode(settings);
Expand All @@ -52,9 +59,10 @@ public EsEmbeddedServer(String clusterName, String homePath, String dataPath, St
}
}

public void start() {
public EsEmbeddedServer start() {
try {
node.start();
return this;
} catch (Exception e) {
throw new RuntimeException("Encountered exception during embedded node startup", e);
}
Expand Down Expand Up @@ -90,8 +98,11 @@ public static void main(String[] args) throws InterruptedException, IOException
if (args.length > 1) {
nbIterations = Integer.parseInt(args[1]);
}
EsEmbeddedServer server = new EsEmbeddedServer("datashare", System.getenv("DS_ELASTICSEARCH_HOME_PATH"),
System.getenv("DS_ELASTICSEARCH_DATA_PATH"), "9200");
EsEmbeddedServer server = new EsEmbeddedServer("datashare",
System.getenv("DS_ELASTICSEARCH_HOME_PATH"),
System.getenv("DS_ELASTICSEARCH_DATA_PATH"),
ofNullable(System.getenv("DS_ELASTICSEARCH_HTTP_PORT")).orElse("9200"),
ofNullable(System.getenv("DS_ELASTICSEARCH_TRANSPORT_PORT")).orElse("9300"));
server.start();
while (!server.isClosed() && nbIterations-- != 0) {
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
public class EsEmbeddedServerIntTest {
private static EsEmbeddedServer server;
@ClassRule static public TemporaryFolder esDir = new TemporaryFolder();
@Rule public ElasticsearchRule es = new ElasticsearchRule(create("http://localhost:9200"));
@Rule public ElasticsearchRule es = new ElasticsearchRule(create("http://localhost:9222"));

@Test
@Test(timeout = 10_000)
public void test_embedded_server_has_a_test_index() throws Exception {
assertThat(es.client.indices().exists(e -> e.index(TEST_INDEX)).value()).isTrue();
}

@BeforeClass
public static void setUp() {
server = new EsEmbeddedServer("datashare", esDir.getRoot().getPath(), esDir.getRoot().getPath(), "9200");
server = new EsEmbeddedServer("datashare", esDir.getRoot().getPath(), esDir.getRoot().getPath(), "9222", "9333");
server.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class EsEmbeddedServerTest {

@Test
public void launch_with_bad_codec() {
try {
try {
new EsEmbeddedServer("name", "home/path", "data/path", "9876") {
@Override
EsEmbeddedServer.PluginConfigurableNode createNode(Settings settings) {
Expand Down

0 comments on commit 5adb411

Please sign in to comment.