From 442ab5cc1d48b04d27a71fda2c7b1524dea6542b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 8 Dec 2023 12:54:50 +0100 Subject: [PATCH] Fix configuration of custom port for Elasticsearch dev services --- .../DevServicesElasticsearchProcessor.java | 2 +- ...lasticsearchDevModeCustomPortTestCase.java | 47 +++++++++++++++++++ .../lowlevel/runtime/TestResource.java | 7 +++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/DevServicesElasticsearchDevModeCustomPortTestCase.java diff --git a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java index 065acd241b0c0..e36b279d99b4a 100644 --- a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java +++ b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java @@ -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); diff --git a/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/DevServicesElasticsearchDevModeCustomPortTestCase.java b/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/DevServicesElasticsearchDevModeCustomPortTestCase.java new file mode 100644 index 0000000000000..3ea3334ae5a1e --- /dev/null +++ b/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/DevServicesElasticsearchDevModeCustomPortTestCase.java @@ -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\"}]")); + } +} diff --git a/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/TestResource.java b/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/TestResource.java index 5a10c4ebb8d67..4ab00a0f385d7 100644 --- a/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/TestResource.java +++ b/extensions/elasticsearch-rest-client/deployment/src/test/java/io/quarkus/elasticsearch/restclient/lowlevel/runtime/TestResource.java @@ -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; @@ -57,6 +58,12 @@ public List 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;