diff --git a/sail/pom.xml b/sail/pom.xml index 295210c52..c1d7d811f 100644 --- a/sail/pom.xml +++ b/sail/pom.xml @@ -44,6 +44,11 @@ elasticsearch-java ${elasticsearch.version} + + org.elasticsearch.client + elasticsearch-rest-client-sniffer + ${elasticsearch.version} + com.fasterxml.jackson.core jackson-databind diff --git a/sail/src/main/java/com/msd/gin/halyard/sail/ElasticSettings.java b/sail/src/main/java/com/msd/gin/halyard/sail/ElasticSettings.java index 341eec536..729cf29d2 100644 --- a/sail/src/main/java/com/msd/gin/halyard/sail/ElasticSettings.java +++ b/sail/src/main/java/com/msd/gin/halyard/sail/ElasticSettings.java @@ -23,15 +23,24 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.apache.http.impl.nio.reactor.IOReactorConfig; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback; +import org.elasticsearch.client.sniff.ElasticsearchNodesSniffer; +import org.elasticsearch.client.sniff.NodesSniffer; +import org.elasticsearch.client.sniff.Sniffer; +import co.elastic.clients.json.JsonpMapper; import co.elastic.clients.json.jackson.JacksonJsonpMapper; import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.rest_client.RestClientTransport; public final class ElasticSettings { + private static final String USER = "es.net.http.auth.user"; + private static final String PASS = "es.net.http.auth.pass"; + private static final String IO_THREADS = "halyard.es.ioThreads"; + String protocol; String host; int port; @@ -39,6 +48,7 @@ public final class ElasticSettings { String password; String indexName; SSLSettings sslSettings; + int ioThreads; public String getProtocol() { return protocol; @@ -89,44 +99,52 @@ public static ElasticSettings from(String esIndexUrl, Configuration conf) { throw new IllegalArgumentException(e); } if (merged.username == null) { - merged.username = conf.get("es.net.http.auth.user"); + merged.username = conf.get(USER); } if (merged.password == null) { - merged.password = conf.get("es.net.http.auth.pass"); + merged.password = conf.get(PASS); } if ("https".equals(merged.protocol)) { merged.sslSettings = SSLSettings.from(conf); } + merged.ioThreads = conf.getInt(IO_THREADS, 0); return merged; } public static ElasticSettings merge(Configuration conf, ElasticSettings defaults) { - ElasticSettings merged; + ElasticSettings urlSettings; String esIndexUrl = conf.get(HBaseSail.ELASTIC_INDEX_URL); if (esIndexUrl != null) { try { - merged = from(new URL(esIndexUrl)); + urlSettings = from(new URL(esIndexUrl)); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } else if (defaults != null) { - merged = new ElasticSettings(); - merged.protocol = defaults.protocol; - merged.host = defaults.host; - merged.port = defaults.port; - merged.indexName = defaults.indexName; + urlSettings = new ElasticSettings(); + urlSettings.protocol = defaults.protocol; + urlSettings.host = defaults.host; + urlSettings.port = defaults.port; + urlSettings.indexName = defaults.indexName; } else { return null; } - if (merged.username == null) { - merged.username = conf.get("es.net.http.auth.user", defaults != null ? defaults.username : null); - } - if (merged.password == null) { - merged.password = conf.get("es.net.http.auth.pass", defaults != null ? defaults.password : null); + if (defaults != null) { + if (urlSettings.username == null) { + urlSettings.username = defaults.username; + } + if (urlSettings.password == null) { + urlSettings.password = defaults.password; + } } + + ElasticSettings merged = urlSettings; + merged.username = conf.get(USER, urlSettings.username); + merged.password = conf.get(PASS, urlSettings.password); if ("https".equals(merged.protocol)) { merged.sslSettings = SSLSettings.merge(conf, defaults != null ? defaults.sslSettings : null); } + merged.ioThreads = conf.getInt(IO_THREADS, defaults != null ? defaults.ioThreads : 0); return merged; } @@ -154,10 +172,44 @@ public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpCli if (sslContext != null) { httpClientBuilder.setSSLContext(sslContext); } + if (ioThreads > 0) { + httpClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(ioThreads).build()); + } return httpClientBuilder; } }); RestClient restClient = restClientBuilder.build(); - return new RestClientTransport(restClient, new JacksonJsonpMapper()); + ElasticsearchNodesSniffer.Scheme snifferScheme; + switch (protocol) { + case "http": + snifferScheme = ElasticsearchNodesSniffer.Scheme.HTTP; + break; + case "https": + snifferScheme = ElasticsearchNodesSniffer.Scheme.HTTPS; + break; + default: + throw new AssertionError("Unsupported scheme: " + protocol); + } + NodesSniffer nodesSniffer = new ElasticsearchNodesSniffer(restClient, ElasticsearchNodesSniffer.DEFAULT_SNIFF_REQUEST_TIMEOUT, snifferScheme); + Sniffer sniffer = Sniffer.builder(restClient).setNodesSniffer(nodesSniffer).build(); + return new RestClientTransportWithSniffer(restClient, new JacksonJsonpMapper(), sniffer); + } + + private static final class RestClientTransportWithSniffer extends RestClientTransport { + private final Sniffer sniffer; + + public RestClientTransportWithSniffer(RestClient restClient, JsonpMapper mapper, Sniffer sniffer) { + super(restClient, mapper); + this.sniffer = sniffer; + } + + @Override + public void close() throws IOException { + try { + sniffer.close(); + } finally { + super.close(); + } + } } } \ No newline at end of file diff --git a/sail/src/test/java/com/msd/gin/halyard/sail/AbstractSearchTest.java b/sail/src/test/java/com/msd/gin/halyard/sail/AbstractSearchTest.java index 3cbc5c82f..8e1392a8c 100644 --- a/sail/src/test/java/com/msd/gin/halyard/sail/AbstractSearchTest.java +++ b/sail/src/test/java/com/msd/gin/halyard/sail/AbstractSearchTest.java @@ -5,21 +5,24 @@ import com.msd.gin.halyard.common.HBaseServerTestInstance; import com.msd.gin.halyard.common.RDFFactory; import com.msd.gin.halyard.sail.search.SearchDocument; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; +import java.io.InputStream; +import java.io.OutputStreamWriter; import java.io.StringWriter; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.tuple.Pair; @@ -27,15 +30,13 @@ import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.repository.Repository; import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.json.JSONObject; import org.junit.Before; -import org.slf4j.LoggerFactory; - -import static org.junit.Assert.*; public abstract class AbstractSearchTest { private static final int QUERY_TIMEOUT = 15; - protected static final String INDEX = "myIndex"; + protected static final String INDEX_NAME = "myIndex"; protected Configuration conf; private RDFFactory rdfFactory; @@ -45,18 +46,18 @@ public void setup() throws Exception { rdfFactory = RDFFactory.create(conf); } - protected final Repository createRepo(String tableName, ServerSocket esServer) throws Exception { - HBaseSail hbaseSail = new HBaseSail(conf, tableName, true, 0, true, QUERY_TIMEOUT, ElasticSettings.from(new URL("http", InetAddress.getLoopbackAddress().getHostAddress(), esServer.getLocalPort(), "/" + INDEX)), null); + protected final Repository createRepo(String tableName, MockElasticServer esServer) throws Exception { + HBaseSail hbaseSail = new HBaseSail(conf, tableName, true, 0, true, QUERY_TIMEOUT, ElasticSettings.from(new URL(esServer.getIndexUrl())), null); Repository hbaseRepo = new SailRepository(hbaseSail); hbaseRepo.init(); return hbaseRepo; } - protected final ServerSocket startElasticsearch(String expectedRequest, Literal... response) throws IOException, InterruptedException { + protected final MockElasticServer startElasticsearch(String expectedRequest, Literal... response) throws IOException, InterruptedException { return startElasticsearch(Collections.singletonMap(expectedRequest, response)); } - protected final ServerSocket startElasticsearch(List> reqRespPairs) throws IOException, InterruptedException { + protected final MockElasticServer startElasticsearch(List> reqRespPairs) throws IOException, InterruptedException { Map requestResponses = new HashMap<>(); for (Pair reqResp : reqRespPairs) { requestResponses.put(reqResp.getKey(), reqResp.getValue()); @@ -64,84 +65,190 @@ protected final ServerSocket startElasticsearch(List> re return startElasticsearch(requestResponses); } - protected final ServerSocket startElasticsearch(Map requestResponses) throws IOException, InterruptedException { - final ServerSocket server = new ServerSocket(0, 50, InetAddress.getLoopbackAddress()); - Thread t = new Thread(() -> { - while (!server.isClosed()) { - try (Socket s = server.accept()) { - try (BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8"))) { - String line; - int length = 0; - while ((line = in.readLine()) != null && line.length() > 0) { - if (line.startsWith("Content-Length:")) { - length = Integer.parseInt(line.substring(15).trim()); + protected final MockElasticServer startElasticsearch(Map requestResponses) throws IOException, InterruptedException { + MockElasticServer server = new MockElasticServer(INDEX_NAME, requestResponses, rdfFactory); + server.start(); + return server; + } + + static class MockElasticServer implements AutoCloseable { + private static final String ES_VERSION = "8.4.2"; + private static final String NODE_ID = UUID.randomUUID().toString(); + + final String indexName; + final String indexPath; + final HttpServer server; + final Map requestResponses; + final RDFFactory rdfFactory; + + MockElasticServer(String indexName, Map requestResponses, RDFFactory rdfFactory) throws IOException { + this.indexName = indexName; + this.requestResponses = requestResponses; + this.rdfFactory = rdfFactory; + indexPath = "/" + indexName; + server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); + server.createContext("/", new HttpHandler() { + @Override + public void handle(HttpExchange he) throws IOException { + String path = he.getRequestURI().getPath(); + int statusCode; + JSONObject response; + if ("GET".equalsIgnoreCase(he.getRequestMethod())) { + switch (path) { + case "/": + JSONObject version = new JSONObject(); + version.put("number", ES_VERSION); + version.put("lucene_version", "8.11.1"); + version.put("minimum_wire_compatibility_version", "6.8.0"); + version.put("minimum_index_compatibiltiy_version", "6.0.0-beta1"); + statusCode = HttpURLConnection.HTTP_OK; + response = new JSONObject(); + response.put("name", "localhost"); + response.put("cluster_name", "halyard-test"); + response.put("cluster_uuid", "_na_"); + response.put("version", version); + response.put("tagline", "You Know, for Search"); + response.put("build_flavor", "default"); + he.getResponseHeaders().set("X-elastic-product", "Elasticsearch"); + break; + case "/_nodes/http": + JSONObject nodeInfo = new JSONObject(); + nodeInfo.put("version", ES_VERSION); + nodeInfo.put("name", "test-es-node"); + nodeInfo.put("host", "localhost"); + nodeInfo.put("ip", server.getAddress().getAddress().getHostAddress()); + nodeInfo.put("roles", Arrays.asList("master", "data", "ingest")); + JSONObject httpNode = new JSONObject(); + httpNode.put("publish_address", server.getAddress().toString()); + nodeInfo.put("http", httpNode); + JSONObject node = new JSONObject(); + node.put(NODE_ID, nodeInfo); + statusCode = HttpURLConnection.HTTP_OK; + response = new JSONObject(); + response.put("nodes", node); + break; + default: + statusCode = HttpURLConnection.HTTP_NOT_FOUND; + response = null; + } + } else { + statusCode = HttpURLConnection.HTTP_BAD_REQUEST; + response = null; + } + + if (statusCode >= 400) { + he.sendResponseHeaders(statusCode, 0); + try (OutputStreamWriter writer = new OutputStreamWriter(he.getResponseBody(), StandardCharsets.UTF_8)) { + writer.write(he.getRequestMethod() + " " + he.getRequestURI()); + } + } else { + he.sendResponseHeaders(statusCode, response != null ? 0 : -1); + if (response != null) { + try (OutputStreamWriter writer = new OutputStreamWriter(he.getResponseBody(), StandardCharsets.UTF_8)) { + response.write(writer); } - System.out.println(line); } - char[] body = new char[length]; - in.read(body); - String request = new String(body); - System.out.println(request); + } - Literal[] responseValues = requestResponses.get(request); + he.close(); + } + }); + server.createContext(indexPath, new HttpHandler() { + @Override + public void handle(HttpExchange he) throws IOException { + int statusCode; + String response; + if ("POST".equalsIgnoreCase(he.getRequestMethod())) { + String requestBody; + try (InputStream in = he.getRequestBody()) { + requestBody = IOUtils.toString(in, StandardCharsets.UTF_8); + } + Literal[] responseValues = requestResponses.get(requestBody); if (responseValues != null) { - String response = createResponse(responseValues); - try (OutputStream out = s.getOutputStream()) { - IOUtils.write(response, out, StandardCharsets.UTF_8); - } + statusCode = HttpURLConnection.HTTP_OK; + response = createResponse(responseValues); } else { - fail("Unexpected request: " + request); + throw new AssertionError("Unexpected request: " + requestBody); } + } else { + statusCode = HttpURLConnection.HTTP_BAD_REQUEST; + response = null; } - } catch (IOException ex) { - if (!server.isClosed()) { - LoggerFactory.getLogger(getClass()).error("Error reading from socket", ex); + + if (statusCode >= 400) { + he.sendResponseHeaders(statusCode, 0); + try (OutputStreamWriter writer = new OutputStreamWriter(he.getResponseBody(), StandardCharsets.UTF_8)) { + writer.write(he.getRequestMethod() + " " + he.getRequestURI()); + } + } else { + he.getResponseHeaders().set("Content-type", "application/json; charset=UTF-8"); + he.getResponseHeaders().set("X-Elastic-Product", "Elasticsearch"); + he.sendResponseHeaders(statusCode, response != null ? 0 : -1); + if (response != null) { + try (OutputStreamWriter writer = new OutputStreamWriter(he.getResponseBody(), StandardCharsets.UTF_8)) { + writer.write(response); + } + } } + + he.close(); } - } - }); - t.setDaemon(true); - t.start(); - return server; - } + }); + } - private String createResponse(Literal[] values) throws IOException { - StringWriter jsonBuf = new StringWriter(); - JsonGenerator jsonGen = new JsonFactory().createGenerator(jsonBuf); - jsonGen.writeStartObject(); - jsonGen.writeNumberField("took", 34); - jsonGen.writeBooleanField("timed_out", false); - jsonGen.writeObjectFieldStart("_shards"); - jsonGen.writeNumberField("total", 5); - jsonGen.writeNumberField("successful", 5); - jsonGen.writeNumberField("skipped", 0); - jsonGen.writeNumberField("failed", 0); - jsonGen.writeEndObject(); - jsonGen.writeObjectFieldStart("hits"); - jsonGen.writeArrayFieldStart("hits"); - for (int i = 0; i < values.length; i++) { - Literal val = values[i]; + private String createResponse(Literal[] values) throws IOException { + StringWriter jsonBuf = new StringWriter(); + JsonGenerator jsonGen = new JsonFactory().createGenerator(jsonBuf); jsonGen.writeStartObject(); - jsonGen.writeStringField("_index", INDEX); - String id = rdfFactory.id(val).toString(); - jsonGen.writeStringField("_id", id); - jsonGen.writeNumberField("_score", (double) (values.length - i)); - jsonGen.writeObjectFieldStart("_source"); - jsonGen.writeStringField(SearchDocument.ID_FIELD, id); - jsonGen.writeStringField(SearchDocument.LABEL_FIELD, val.getLabel()); - jsonGen.writeStringField(SearchDocument.DATATYPE_FIELD, val.getDatatype().stringValue()); - if (val.getLanguage().isPresent()) { - jsonGen.writeStringField(SearchDocument.LANG_FIELD, val.getLanguage().get()); + jsonGen.writeNumberField("took", 34); + jsonGen.writeBooleanField("timed_out", false); + jsonGen.writeObjectFieldStart("_shards"); + jsonGen.writeNumberField("total", 5); + jsonGen.writeNumberField("successful", 5); + jsonGen.writeNumberField("skipped", 0); + jsonGen.writeNumberField("failed", 0); + jsonGen.writeEndObject(); + jsonGen.writeObjectFieldStart("hits"); + jsonGen.writeArrayFieldStart("hits"); + for (int i = 0; i < values.length; i++) { + Literal val = values[i]; + jsonGen.writeStartObject(); + jsonGen.writeStringField("_index", indexName); + String id = rdfFactory.id(val).toString(); + jsonGen.writeStringField("_id", id); + jsonGen.writeNumberField("_score", (double) (values.length - i)); + jsonGen.writeObjectFieldStart("_source"); + jsonGen.writeStringField(SearchDocument.ID_FIELD, id); + jsonGen.writeStringField(SearchDocument.LABEL_FIELD, val.getLabel()); + jsonGen.writeStringField(SearchDocument.DATATYPE_FIELD, val.getDatatype().stringValue()); + if (val.getLanguage().isPresent()) { + jsonGen.writeStringField(SearchDocument.LANG_FIELD, val.getLanguage().get()); + } + jsonGen.writeEndObject(); + jsonGen.writeEndObject(); } + jsonGen.writeEndArray(); jsonGen.writeEndObject(); jsonGen.writeEndObject(); + jsonGen.close(); + return jsonBuf.toString(); + } + + void start() { + server.start(); + } + + int getPort() { + return server.getAddress().getPort(); + } + + String getIndexUrl() { + String indexUrl = "http://localhost:" + getPort() + indexPath; + return indexUrl; + } + + public void close() { + server.stop(0); } - jsonGen.writeEndArray(); - jsonGen.writeEndObject(); - jsonGen.writeEndObject(); - jsonGen.close(); - String json = jsonBuf.toString(); - String response = "HTTP/1.1 200 OK\ncontent-type: application/json; charset=UTF-8\ncontent-length: " + json.length() + "\nX-elastic-product: Elasticsearch\n\r\n" + json; - return response; } } diff --git a/sail/src/test/java/com/msd/gin/halyard/sail/GeoSPARQLSearchTest.java b/sail/src/test/java/com/msd/gin/halyard/sail/GeoSPARQLSearchTest.java index 4ca9729c1..fd58f21ec 100644 --- a/sail/src/test/java/com/msd/gin/halyard/sail/GeoSPARQLSearchTest.java +++ b/sail/src/test/java/com/msd/gin/halyard/sail/GeoSPARQLSearchTest.java @@ -1,6 +1,5 @@ package com.msd.gin.halyard.sail; -import java.net.ServerSocket; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -31,7 +30,7 @@ public class GeoSPARQLSearchTest extends AbstractSearchTest { @Test public void literalWithinDistance() throws Exception { String expectedRequest = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"query\":{\"geo_distance\":{\"label.point\":{\"lat\":0.0,\"lon\":0.0},\"distance\":\"277.98769933592183km\"}}}"; - try (ServerSocket server = startElasticsearch(expectedRequest, pos1, pos2)) { + try (MockElasticServer server = startElasticsearch(expectedRequest, pos1, pos2)) { IRI whatever = vf.createIRI("http://whatever"); Repository hbaseRepo = createRepo("literalWithinDistance", server); try (RepositoryConnection conn = hbaseRepo.getConnection()) { @@ -57,7 +56,7 @@ public void literalWithinDistance() throws Exception { public void varWithinDistance() throws Exception { String expectedRequest1 = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"query\":{\"geo_distance\":{\"label.point\":{\"lat\":0.0,\"lon\":0.0},\"distance\":\"111200.0m\"}}}"; String expectedRequest2 = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"query\":{\"geo_distance\":{\"label.point\":{\"lat\":0.0,\"lon\":0.0},\"distance\":\"318.55043857000004km\"}}}"; - try (ServerSocket server = startElasticsearch( + try (MockElasticServer server = startElasticsearch( Arrays.asList(Pair.of(expectedRequest1, new Literal[] { pos1 }), Pair.of(expectedRequest2, new Literal[] { pos1, pos2 })))) { IRI from = vf.createIRI("http://from"); IRI whatever = vf.createIRI("http://whatever"); @@ -86,7 +85,7 @@ public void varWithinDistance() throws Exception { public void bindWithinDistance() throws Exception { String expectedRequest1 = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"query\":{\"geo_distance\":{\"label.point\":{\"lat\":0.0,\"lon\":0.0},\"distance\":\"111200.0m\"}}}"; String expectedRequest2 = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"query\":{\"geo_distance\":{\"label.point\":{\"lat\":0.0,\"lon\":0.0},\"distance\":\"318.55043857000004km\"}}}"; - try (ServerSocket server = startElasticsearch(Arrays.asList(Pair.of(expectedRequest1, new Literal[] { pos1 }), Pair.of(expectedRequest2, new Literal[] { pos1, pos2 })))) { + try (MockElasticServer server = startElasticsearch(Arrays.asList(Pair.of(expectedRequest1, new Literal[] { pos1 }), Pair.of(expectedRequest2, new Literal[] { pos1, pos2 })))) { IRI from = vf.createIRI("http://from"); IRI whatever = vf.createIRI("http://whatever"); Repository hbaseRepo = createRepo("bindWithinDistance", server); diff --git a/sail/src/test/java/com/msd/gin/halyard/sail/SearchTest.java b/sail/src/test/java/com/msd/gin/halyard/sail/SearchTest.java index a382580a8..d64ef43a1 100644 --- a/sail/src/test/java/com/msd/gin/halyard/sail/SearchTest.java +++ b/sail/src/test/java/com/msd/gin/halyard/sail/SearchTest.java @@ -18,8 +18,6 @@ import com.msd.gin.halyard.vocab.HALYARD; -import java.net.ServerSocket; - import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Statement; @@ -48,7 +46,7 @@ public void statementLiteralSearchTest() throws Exception { Literal val2 = vf.createLiteral("Whatever Text", "en"); Literal val3 = vf.createLiteral("Que sea", "es"); String expectedRequest = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"min_score\":0.0,\"query\":{\"query_string\":{\"default_field\":\"label\",\"fuzziness\":\"1\",\"phrase_slop\":0.0,\"query\":\"what\"}},\"size\":10000}"; - try (ServerSocket server = startElasticsearch(expectedRequest, val1, val2)) { + try (MockElasticServer server = startElasticsearch(expectedRequest, val1, val2)) { IRI whatever = vf.createIRI("http://whatever"); Repository hbaseRepo = createRepo("testSimpleLiteralSearch", server); try (RepositoryConnection conn = hbaseRepo.getConnection()) { @@ -75,7 +73,7 @@ public void advancedSearchTest() throws Exception { Literal val2 = vf.createLiteral("Whatever Text", "en"); Literal val3 = vf.createLiteral("Que sea", "es"); String expectedRequest = "{\"_source\":{\"includes\":[\"id\",\"iri\",\"label\",\"lang\",\"datatype\"]},\"min_score\":0.0,\"query\":{\"query_string\":{\"default_field\":\"label\",\"fuzziness\":\"1\",\"phrase_slop\":0.0,\"query\":\"what\"}},\"size\":5}"; - try (ServerSocket server = startElasticsearch(expectedRequest, val1, val2)) { + try (MockElasticServer server = startElasticsearch(expectedRequest, val1, val2)) { IRI whatever = vf.createIRI("http://whatever"); Repository hbaseRepo = createRepo("testAdvancedLiteralSearch", server); try (RepositoryConnection conn = hbaseRepo.getConnection()) { @@ -88,11 +86,11 @@ public void advancedSearchTest() throws Exception { assertTrue(iter.hasNext()); BindingSet bs = iter.next(); assertEquals(2.0, ((Literal) bs.getValue("score")).doubleValue(), 0.0); - assertEquals(INDEX, ((Literal) bs.getValue("index")).stringValue()); + assertEquals(INDEX_NAME, ((Literal) bs.getValue("index")).stringValue()); assertTrue(iter.hasNext()); bs = iter.next(); assertEquals(1.0, ((Literal) bs.getValue("score")).doubleValue(), 0.0); - assertEquals(INDEX, ((Literal) bs.getValue("index")).stringValue()); + assertEquals(INDEX_NAME, ((Literal) bs.getValue("index")).stringValue()); assertFalse(iter.hasNext()); } } diff --git a/webapps/pom.xml b/webapps/pom.xml index 10f94dddf..e54e19064 100644 --- a/webapps/pom.xml +++ b/webapps/pom.xml @@ -158,6 +158,11 @@ elasticsearch-rest-client ${elasticsearch.version} + + org.elasticsearch.client + elasticsearch-rest-client-sniffer + ${elasticsearch.version} + org.apache.httpcomponents httpasyncclient