Search in sources :

Example 21 with Response

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;
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) FstStats(de.spinscale.elasticsearch.action.suggest.statistics.FstStats) ShardId(org.elasticsearch.index.shard.ShardId) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 22 with Response

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));
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)

Example 23 with Response

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));
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)

Example 24 with Response

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());
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)

Example 25 with Response

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);
    }
}
Also used : CircuitBreaker(com.nike.fastbreak.CircuitBreaker) Matchers.anyString(org.mockito.Matchers.anyString) Response(com.ning.http.client.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Function(java.util.function.Function) CircuitBreakerDelegate(com.nike.fastbreak.CircuitBreakerDelegate) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

Response (com.ning.http.client.Response)30 Test (org.junit.Test)10 IOException (java.io.IOException)9 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)7 Test (org.testng.annotations.Test)7 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)4 Request (com.ning.http.client.Request)4 RequestBuilder (com.ning.http.client.RequestBuilder)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)4 HttpMethod (io.netty.handler.codec.http.HttpMethod)4 Map (java.util.Map)4 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)4 CircuitBreaker (com.nike.fastbreak.CircuitBreaker)3 Span (com.nike.wingtips.Span)3 NettyAsyncHttpProvider (com.ning.http.client.providers.netty.NettyAsyncHttpProvider)3 UnknownHostException (java.net.UnknownHostException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 KillBillClientException (org.killbill.billing.client.KillBillClientException)3 RoleDefinition (org.killbill.billing.client.model.RoleDefinition)3 UserRoles (org.killbill.billing.client.model.UserRoles)3