Skip to content

Commit

Permalink
Fix configuration of custom port for Elasticsearch dev services
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Dec 8, 2023
1 parent 018e8e4 commit 442ab5c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private DevServicesResultBuildItem.RunningDevService startElasticsearch(
container.withLabel(DEV_SERVICE_LABEL, config.serviceName);
}
if (config.port.isPresent()) {
container.setPortBindings(List.of(config.port.get() + ":" + config.port.get()));
container.setPortBindings(List.of(config.port.get() + ":" + ELASTICSEARCH_PORT));
}
timeout.ifPresent(container::withStartupTimeout);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.elasticsearch.restclient.lowlevel.runtime;

import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

public class DevServicesElasticsearchDevModeCustomPortTestCase {
@RegisterExtension
static QuarkusDevModeTest test = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar
.addClass(TestResource.class)
.addAsResource(new StringAsset("""
quarkus.elasticsearch.devservices.port=19200
"""), "application.properties"));

@Test
public void checkConfiguredPort() {
RestAssured
.when().get("/fruits/configured-hosts")
.then().body(endsWith(":19200"));

}

@Test
public void testDatasource() throws Exception {
var fruit = new TestResource.Fruit();
fruit.id = "1";
fruit.name = "banana";
fruit.color = "yellow";

RestAssured
.given().body(fruit).contentType("application/json")
.when().post("/fruits")
.then().statusCode(204);

RestAssured.when().get("/fruits/search?term=color&match=yellow")
.then()
.statusCode(200)
.body(equalTo("[{\"id\":\"1\",\"name\":\"banana\",\"color\":\"yellow\"}]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.ws.rs.QueryParam;

import org.apache.http.util.EntityUtils;
import org.eclipse.microprofile.config.ConfigProvider;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
Expand Down Expand Up @@ -57,6 +58,12 @@ public List<Fruit> search(@QueryParam("term") String term, @QueryParam("match")
return results;
}

@GET
@Path("/configured-hosts")
public String configuredHosts() {
return ConfigProvider.getConfig().getConfigValue("quarkus.elasticsearch.hosts").getValue();
}

public static class Fruit {
public String id;
public String name;
Expand Down

0 comments on commit 442ab5c

Please sign in to comment.