当前位置: 首页>>代码示例>>Java>>正文


Java BoundRequestBuilder类代码示例

本文整理汇总了Java中org.asynchttpclient.BoundRequestBuilder的典型用法代码示例。如果您正苦于以下问题:Java BoundRequestBuilder类的具体用法?Java BoundRequestBuilder怎么用?Java BoundRequestBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BoundRequestBuilder类属于org.asynchttpclient包,在下文中一共展示了BoundRequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deferredSimple

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void deferredSimple() throws IOException, ExecutionException, TimeoutException, InterruptedException {
    try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
        BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredSimple");

        CountingOutputStream cos = new CountingOutputStream();
        BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos);
        Future<Response> f = r.execute(bdah);
        Response resp = bdah.getResponse();
        assertNotNull(resp);
        assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
        assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG));
        // we got headers only, it's probably not all yet here (we have BIG file
        // downloading)
        assertTrue(cos.getByteCount() <= HALF_GIG);

        // now be polite and wait for body arrival too (otherwise we would be
        // dropping the "line" on server)
        f.get();
        // it all should be here now
        assertEquals(cos.getByteCount(), HALF_GIG);
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:24,代码来源:BodyDeferringAsyncHandlerTest.java

示例2: shouldThrowWhenServerFails

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test(expectedExceptions = HttpServerErrorException.class)
public void shouldThrowWhenServerFails() throws Exception {
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);
    when(httpClient.prepareGet("/product-index/bla/_count")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(500, "Internal Server Error", "{\"error\" : \"miserable failure\" }")));
    // when
    try {
        testee.setTypes("bla").execute();
    }

    // then
    catch (HttpServerErrorException e) {
        verify(httpClient).prepareGet("/product-index/bla/_count");
        assertThat(e.getStatusCode(), is(500));
        assertThat(e.getResponseBody(), is("{\"error\" : \"miserable failure\" }"));
        throw e;
    }

}
 
开发者ID:otto-de,项目名称:flummi,代码行数:20,代码来源:CountRequestBuilderTest.java

示例3: shouldCreateClusterAdminClient

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldCreateClusterAdminClient() throws ExecutionException, InterruptedException, IOException {
    // Given
    final BoundRequestBuilder boundRequestBuilder = mock(BoundRequestBuilder.class);
    final ListenableFuture<Response> listenableFuture = mock(ListenableFuture.class);
    final Response response = mock(Response.class);
    when(response.getStatusCode()).thenReturn(200);
    when(response.getResponseBody()).thenReturn("{\"status\":\"GREEN\", \"cluster_name\":\"someClusterName\", \"timed_out\":\"someTimedOut\"}");
    when(listenableFuture.get()).thenReturn(response);
    when(boundRequestBuilder.execute()).thenReturn(listenableFuture);
    when(httpClient.prepareGet(anyString())).thenReturn(boundRequestBuilder);
    final ClusterAdminClient cluster = adminClient.cluster();
    final ClusterHealthRequestBuilder clusterHealthRequestBuilder = cluster.prepareHealth("someIndexName");

    //When
    clusterHealthRequestBuilder.execute();

    //Then
    Mockito.verify(httpClient).prepareGet("/_cluster/health/someIndexName");
    assertThat(cluster, notNullValue());
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:22,代码来源:AdminClientTest.java

示例4: shouldCreateIndicesAdminClient

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldCreateIndicesAdminClient() throws ExecutionException, InterruptedException, IOException {
    //Given
    final BoundRequestBuilder boundRequestBuilder = mock(BoundRequestBuilder.class);
    when(httpClient.preparePut(anyString())).thenReturn(boundRequestBuilder);
    when(boundRequestBuilder.setBody(anyString())).thenReturn(boundRequestBuilder);
    when(boundRequestBuilder.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilder);
    final ListenableFuture<Response> listenableFuture = mock(ListenableFuture.class);
    when(boundRequestBuilder.execute()).thenReturn(listenableFuture);
    final Response response = mock(Response.class);
    when(listenableFuture.get()).thenReturn(response);
    when(response.getStatusCode()).thenReturn(200);
    when(response.getResponseBody()).thenReturn("{\"acknowledged\":\"true\"}");
    final IndicesAdminClient indicesAdminClient = adminClient.indices();
    final CreateIndexRequestBuilder createIndexRequestBuilder = indicesAdminClient.prepareCreate("someIndexName");

    //When
    createIndexRequestBuilder.execute();

    //Then
    verify(httpClient).preparePut("/someIndexName");
    assertThat(indicesAdminClient, notNullValue());
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:24,代码来源:AdminClientTest.java

示例5: shouldFireBulkRequest

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldFireBulkRequest() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":false}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    testee.execute();

    // then
    verify(asyncHttpClient).preparePost("/_bulk");
    verify(boundRequestBuilderMock).execute();
    verify(boundRequestBuilderMock).setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n");
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:21,代码来源:BulkRequestBuilderTest.java

示例6: shouldThrowExceptionIfHttpStatusIsNot200

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test(expectedExceptions = HttpServerErrorException.class)
public void shouldThrowExceptionIfHttpStatusIsNot200() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(400, "not ok", "{\"errors\":false}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    try {
        testee.execute();
    }
    // then
    catch (HttpServerErrorException e) {
        assertThat(e.getStatusCode(), is(400));
        assertThat(e.getResponseBody(), is("{\"errors\":false}"));
        throw e;
    }
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:24,代码来源:BulkRequestBuilderTest.java

示例7: shouldThrowAnExceptionIfOneOpIsPresentAndItIsNotAnUpdate404

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldThrowAnExceptionIfOneOpIsPresentAndItIsNotAnUpdate404() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":true,\"items\":[{\"index\":{\"status\":400,\"error\":\"someError\"}}]}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    try {
        testee.execute();
    } catch (InvalidElasticsearchResponseException e) {
        assertThat(e.getMessage(), is("Response contains errors': {\"errors\":true,\"items\":[{\"index\":{\"status\":400,\"error\":\"someError\"}}]}"));
    }
    // then
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:21,代码来源:BulkRequestBuilderTest.java

示例8: shouldNotThrowAnExceptionIfOneOpIsPresentAndItIsAnUpdate404

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldNotThrowAnExceptionIfOneOpIsPresentAndItIsAnUpdate404() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":true,\"items\":[{\"update\":{\"status\":404,\"error\":\"someError\"}}]}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    testee.execute();
    // then
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:17,代码来源:BulkRequestBuilderTest.java

示例9: shouldThrowAnExceptionIfOneOpIsPresentAndItIsNotAnUpdate503

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldThrowAnExceptionIfOneOpIsPresentAndItIsNotAnUpdate503() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":true,\"items\":[{\"index\":{\"status\":503,\"error\":\"someError\"}}]}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    try {
        testee.execute();
    } catch (InvalidElasticsearchResponseException e) {
        assertThat(e.getMessage(), is("Response contains errors': {\"errors\":true,\"items\":[{\"index\":{\"status\":503,\"error\":\"someError\"}}]}"));
    }
    // then
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:21,代码来源:BulkRequestBuilderTest.java

示例10: shouldThrowAnExceptionIfTwoOpsArePresentAndDeleteHasAnError

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldThrowAnExceptionIfTwoOpsArePresentAndDeleteHasAnError() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":true,\"items\":[{\"create\":{\"status\":200}},{\"delete\":{\"status\":503,\"error\":\"someError\"}}]}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    try {
        testee.execute();
    } catch (InvalidElasticsearchResponseException e) {
        assertThat(e.getMessage(), is("Response contains errors': {\"errors\":true,\"items\":[{\"create\":{\"status\":200}},{\"delete\":{\"status\":503,\"error\":\"someError\"}}]}"));
    }
    // then
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:21,代码来源:BulkRequestBuilderTest.java

示例11: shouldNotThrowAnExceptionIfTwoOpsArePresentAndUpdateHasAn404Error

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldNotThrowAnExceptionIfTwoOpsArePresentAndUpdateHasAn404Error() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":true,\"items\":[{\"create\":{\"status\":200}},{\"update\":{\"status\":404,\"error\":\"someError\"}}]}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    testee.execute();
    // then
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:17,代码来源:BulkRequestBuilderTest.java

示例12: shouldNotThrowExceptionForResponseItemWithoutErrors

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldNotThrowExceptionForResponseItemWithoutErrors() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    when(asyncHttpClient.preparePost("/_bulk")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setBody("{\"index\":{\"_index\":\"someIndex\",\"_type\":\"Flutschfinger\"}}\n{\"Eis\":\"am Stiel\"}\n")).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.setCharset(Charset.forName("UTF-8"))).thenReturn(boundRequestBuilderMock);
    when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok", "{\"errors\":true,\"items\":[{\"update\":{\"_index\":\"mytestindex\",\"_type\":\"product\",\"_id\":\"340891232\",\"status\":409}}]}")));

    testee.add(new IndexActionBuilder("someIndex").setOpType(IndexOpType.INDEX).setType("Flutschfinger").setSource(object("Eis", "am Stiel")));

    // when
    testee.execute();

    // then
    verify(asyncHttpClient).preparePost("/_bulk");
    verify(boundRequestBuilderMock).execute();
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:20,代码来源:BulkRequestBuilderTest.java

示例13: shouldExecuteSimpleRequest

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldExecuteSimpleRequest() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    Mockito.when(asyncHttpClient.prepareGet("/_cluster/health/someIndex,someOtherIndex")).thenReturn(boundRequestBuilderMock);
    Mockito.when(boundRequestBuilderMock.addQueryParam(anyString(), anyString())).thenReturn(boundRequestBuilderMock);
    Mockito.when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok",
            "{\n" +
                    "  \"cluster_name\": \"myCluster\",\n" +
                    "  \"status\": \"green\",\n" +
                    "  \"timed_out\": false" +
                    "}")));

    // when
    ClusterHealthResponse healthResponse = testee.execute();

    // then
    assertThat(healthResponse.getStatus(), is(ClusterHealthStatus.GREEN));
    assertThat(healthResponse.getCluster_name(), is("myCluster"));
    assertThat(healthResponse.isTimedOut(), is(false));
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:23,代码来源:ClusterHealthRequestBuilderTest.java

示例14: shouldExecuteRequestWithTimeout

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldExecuteRequestWithTimeout() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    Mockito.when(asyncHttpClient.prepareGet("/_cluster/health/someIndex,someOtherIndex")).thenReturn(boundRequestBuilderMock);
    Mockito.when(boundRequestBuilderMock.addQueryParam(anyString(), anyString())).thenReturn(boundRequestBuilderMock);
    Mockito.when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok",
            "{\n" +
                    "  \"cluster_name\": \"myCluster\",\n" +
                    "  \"status\": \"green\",\n" +
                    "  \"timed_out\": false" +
                    "}")));

    // when
    ClusterHealthResponse healthResponse = testee.setTimeout(1000).execute();

    // then
    assertThat(healthResponse.getStatus(), is(ClusterHealthStatus.GREEN));
    assertThat(healthResponse.getCluster_name(), is("myCluster"));
    assertThat(healthResponse.isTimedOut(), is(false));
    Mockito.verify(boundRequestBuilderMock).addQueryParam("timeout", "1000ms");
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:24,代码来源:ClusterHealthRequestBuilderTest.java

示例15: shouldExecuteRequestWithWaitForYellowStatus

import org.asynchttpclient.BoundRequestBuilder; //导入依赖的package包/类
@Test
public void shouldExecuteRequestWithWaitForYellowStatus() throws Exception {
    // given
    BoundRequestBuilder boundRequestBuilderMock = mock(BoundRequestBuilder.class);

    Mockito.when(asyncHttpClient.prepareGet("/_cluster/health/someIndex,someOtherIndex")).thenReturn(boundRequestBuilderMock);
    Mockito.when(boundRequestBuilderMock.addQueryParam(anyString(), anyString())).thenReturn(boundRequestBuilderMock);
    Mockito.when(boundRequestBuilderMock.execute()).thenReturn(new CompletedFuture(new MockResponse(200, "ok",
            "{\n" +
                    "  \"cluster_name\": \"myCluster\",\n" +
                    "  \"status\": \"green\",\n" +
                    "  \"timed_out\": false" +
                    "}")));

    // when
    ClusterHealthResponse healthResponse = testee.setWaitForYellowStatus().execute();

    // then
    assertThat(healthResponse.getStatus(), is(ClusterHealthStatus.GREEN));
    assertThat(healthResponse.getCluster_name(), is("myCluster"));
    assertThat(healthResponse.isTimedOut(), is(false));
    Mockito.verify(boundRequestBuilderMock).addQueryParam("wait_for_status", "yellow");
}
 
开发者ID:otto-de,项目名称:flummi,代码行数:24,代码来源:ClusterHealthRequestBuilderTest.java


注:本文中的org.asynchttpclient.BoundRequestBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。