use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.
the class RestSuggestActionTest method getStatistics.
@Override
public FstStats getStatistics() throws Exception {
List<FstStats.FstIndexShardStats> stats = Lists.newArrayList();
Response r = httpClient.prepareGet("http://localhost:" + port + "/__suggestStatistics").execute().get();
assertThat(r.getStatusCode(), is(200));
System.out.println(r.getResponseBody());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootObj = objectMapper.readTree(r.getResponseBody());
FstStats fstStats = new FstStats();
ArrayNode jsonFstStats = (ArrayNode) rootObj.get("fstStats");
Iterator<JsonNode> nodesIterator = jsonFstStats.iterator();
while (nodesIterator.hasNext()) {
JsonNode fstStatsNodeEntry = nodesIterator.next();
if (fstStatsNodeEntry.isObject()) {
ShardId shardId = new ShardId(fstStatsNodeEntry.get("index").asText(), fstStatsNodeEntry.get("id").asInt());
FstStats.FstIndexShardStats fstIndexShardStats = new FstStats.FstIndexShardStats(shardId, null, null, fstStatsNodeEntry.get("sizeInBytes").getLongValue());
stats.add(fstIndexShardStats);
}
fstStats.getStats().addAll(stats);
}
return fstStats;
}
use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.
the class RestSuggestActionTest method refreshIndexSuggesters.
@Override
public void refreshIndexSuggesters(String index) throws Exception {
Response r = httpClient.preparePost("http://localhost:" + port + "/" + index + "/product/__suggestRefresh").execute().get();
assertThat(r.getStatusCode(), is(200));
}
use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.
the class RestSuggestActionTest method refreshAllSuggesters.
@Override
public void refreshAllSuggesters() throws Exception {
Response r = httpClient.preparePost("http://localhost:" + port + "/__suggestRefresh").execute().get();
assertThat(r.getStatusCode(), is(200));
}
use of com.ning.http.client.Response in project elasticsearch-suggest-plugin by spinscale.
the class RestSuggestActionTest method getSuggestions.
@Override
public List<String> getSuggestions(SuggestionQuery suggestionQuery) throws Exception {
String json = createJSONQuery(suggestionQuery);
String url = "http://localhost:" + port + "/" + suggestionQuery.index + "/" + suggestionQuery.type + "/__suggest";
Response r = httpClient.preparePost(url).setBody(json).execute().get();
assertThat(r.getStatusCode(), is(200));
assertThatResponseHasNoShardFailures(r);
return getSuggestionsFromResponse(r.getResponseBody());
}
use of com.ning.http.client.Response in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method getCircuitBreaker_returns_CircuitBreakerDelegate_wrapping_default_CircuitBreakerForHttpStatusCode_using_host_as_the_key.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void getCircuitBreaker_returns_CircuitBreakerDelegate_wrapping_default_CircuitBreakerForHttpStatusCode_using_host_as_the_key(boolean useNettyEventLoop) {
// given
String host = UUID.randomUUID().toString();
String url = "http://" + host + "/some/path";
String method = "GET";
AsyncHttpClient.BoundRequestBuilder reqMock = mock(AsyncHttpClient.BoundRequestBuilder.class);
Optional<CircuitBreaker<Response>> customCb = Optional.empty();
RequestBuilderWrapper rbw = new RequestBuilderWrapper(url, method, reqMock, customCb, false);
if (useNettyEventLoop)
rbw.setCtx(ctxMock);
// when
Optional<CircuitBreaker<Response>> result = helperSpy.getCircuitBreaker(rbw);
// then
assertThat(result).isPresent();
assertThat(result.get()).isInstanceOf(CircuitBreakerDelegate.class);
CircuitBreakerDelegate<Response, Integer> wrapper = (CircuitBreakerDelegate) result.get();
CircuitBreaker<Integer> delegate = (CircuitBreaker<Integer>) Whitebox.getInternalState(wrapper, "delegate");
Function<Response, Integer> eventConverter = (Function<Response, Integer>) Whitebox.getInternalState(wrapper, "eventConverter");
assertThat(delegate).isSameAs(CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(host));
Response responseMock = mock(Response.class);
doReturn(42).when(responseMock).getStatusCode();
assertThat(eventConverter.apply(responseMock)).isEqualTo(42);
assertThat(eventConverter.apply(null)).isNull();
if (useNettyEventLoop) {
assertThat(Whitebox.getInternalState(delegate, "scheduler")).isEqualTo(eventLoopMock);
assertThat(Whitebox.getInternalState(delegate, "stateChangeNotificationExecutor")).isEqualTo(eventLoopMock);
} else {
assertThat(Whitebox.getInternalState(delegate, "scheduler")).isNotEqualTo(eventLoopMock);
assertThat(Whitebox.getInternalState(delegate, "stateChangeNotificationExecutor")).isNotEqualTo(eventLoopMock);
}
}
Aggregations