use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class NodeAdapterES6 method version.
@Override
public Optional<SearchVersion> version() {
final Ping request = new Ping.Builder().build();
final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Unable to retrieve Elasticsearch version");
return Optional.ofNullable(jestResult.getJsonObject().path("version").path("number").asText(null)).map(this::parseVersion).map(SearchVersion::elasticsearch);
}
use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithQueryParsingException.
@Test
public void executeWithQueryParsingException() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode rootCauseStub = objectMapper.createObjectNode();
rootCauseStub.set("type", new TextNode("query_parsing_exception"));
rootCauseStub.set("reason", new TextNode("foobar"));
rootCauseStub.set("line", new IntNode(23));
rootCauseStub.set("col", new IntNode(42));
rootCauseStub.set("index", new TextNode("my_index"));
final ArrayNode rootCausesStub = objectMapper.createArrayNode();
rootCausesStub.add(rootCauseStub);
final ObjectNode errorStub = objectMapper.createObjectNode();
errorStub.set("root_cause", rootCausesStub);
final ObjectNode responseStub = objectMapper.createObjectNode();
responseStub.set("error", errorStub);
when(resultMock.getJsonObject()).thenReturn(responseStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected QueryParsingException to be thrown");
} catch (QueryParsingException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("foobar").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("foobar");
assertThat(e.getLine()).contains(23);
assertThat(e.getColumn()).contains(42);
assertThat(e.getIndex()).contains("my_index");
}
}
Aggregations