Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configuration of custom port for Elasticsearch dev services #37611

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading