Search in sources :

Example 1 with CoreHttpRequest

use of com.couchbase.client.core.endpoint.http.CoreHttpRequest in project couchbase-jvm-clients by couchbase.

the class ViewEndpointIntegrationTest method dispatchGenericRequest.

/**
 * Makes sure that we can execute a generic view management request.
 *
 * <p>The mock does not support hitting the / path for views, so this test is ignored there.</p>
 */
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void dispatchGenericRequest() throws Exception {
    TestNodeConfig node = config().nodes().get(0);
    ViewEndpoint endpoint = new ViewEndpoint(serviceContext, node.hostname(), node.ports().get(Services.VIEW));
    endpoint.connect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.CONNECTED);
    CoreHttpRequest request = CoreHttpRequest.builder(CoreCommonOptions.of(Duration.ofSeconds(5), null, null), serviceContext, HttpMethod.GET, CoreHttpPath.path("/"), RequestTarget.views(config().bucketname())).build();
    endpoint.send(request);
    CoreHttpResponse response = request.response().get();
    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertNotNull(response.content());
    assertTrue(response.content().length > 0);
    endpoint.disconnect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
}
Also used : CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) CoreHttpResponse(com.couchbase.client.core.endpoint.http.CoreHttpResponse) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with CoreHttpRequest

use of com.couchbase.client.core.endpoint.http.CoreHttpRequest in project couchbase-jvm-clients by couchbase.

the class ChunkedHandlerSwitcherTest method switchesToChunkIfNeeded.

/**
 * If non-chunked is loaded, make sure it switches back to chunked.
 */
@Test
void switchesToChunkIfNeeded() {
    assertChunkedInPipeline(channel);
    for (int i = 0; i < 2; i++) {
        CoreHttpRequest genericSearchRequest = mock(CoreHttpRequest.class);
        when(genericSearchRequest.retryStrategy()).thenReturn(FailFastRetryStrategy.INSTANCE);
        channel.write(genericSearchRequest);
        assertNonChunkedInPipeline(channel);
        SearchRequest searchRequest = mock(SearchRequest.class);
        when(searchRequest.retryStrategy()).thenReturn(FailFastRetryStrategy.INSTANCE);
        channel.write(searchRequest);
        assertChunkedInPipeline(channel);
    }
}
Also used : SearchRequest(com.couchbase.client.core.msg.search.SearchRequest) CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) Test(org.junit.jupiter.api.Test)

Example 3 with CoreHttpRequest

use of com.couchbase.client.core.endpoint.http.CoreHttpRequest in project couchbase-jvm-clients by couchbase.

the class ChunkedHandlerSwitcherTest method switchesToNonChunkIfNeeded.

/**
 * If chunked is loaded, make sure it switches over to non-chunked.
 */
@Test
void switchesToNonChunkIfNeeded() {
    assertChunkedInPipeline(channel);
    CoreHttpRequest upsertRequest = mock(CoreHttpRequest.class);
    when(upsertRequest.retryStrategy()).thenReturn(FailFastRetryStrategy.INSTANCE);
    channel.write(upsertRequest);
    assertNonChunkedInPipeline(channel);
}
Also used : CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) Test(org.junit.jupiter.api.Test)

Example 4 with CoreHttpRequest

use of com.couchbase.client.core.endpoint.http.CoreHttpRequest in project couchbase-jvm-clients by couchbase.

the class NonChunkedHttpMessageHandlerTest method callsMarkRequestCompletedOnceFinished.

@Test
void callsMarkRequestCompletedOnceFinished() throws Exception {
    channel.pipeline().addFirst(NonChunkedHttpMessageHandler.IDENTIFIER, new TestNonChunkedHttpMessageHandler(endpoint));
    channel.pipeline().fireChannelActive();
    CoreHttpRequest request = CoreHttpRequest.builder(CoreCommonOptions.of(Duration.ofSeconds(1), BestEffortRetryStrategy.INSTANCE, null), endpoint.context(), HttpMethod.GET, CoreHttpPath.path("/"), RequestTarget.views("bucket")).build();
    channel.writeAndFlush(request);
    FullHttpRequest written = channel.readOutbound();
    assertEquals("/", written.uri());
    FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    channel.writeInbound(response);
    assertEquals(ResponseStatus.SUCCESS, request.response().get().status());
    verify(endpoint, times(1)).markRequestCompletion();
}
Also used : DefaultFullHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest) CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) FullHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpResponse) Test(org.junit.jupiter.api.Test)

Example 5 with CoreHttpRequest

use of com.couchbase.client.core.endpoint.http.CoreHttpRequest in project couchbase-jvm-clients by couchbase.

the class AsyncCouchbaseHttpClient method exec.

private CompletableFuture<HttpResponse> exec(HttpMethod method, HttpTarget target, HttpPath path, CommonHttpOptions<?>.BuiltCommonHttpOptions options, Consumer<CoreHttpRequest.Builder> customizer) {
    CoreHttpRequest.Builder builder = new CoreHttpClient(core, target.coreTarget).newRequest(method, CoreHttpPath.path(path.formatted), options).bypassExceptionTranslation(true);
    options.headers().forEach(it -> builder.header(it.name, it.value));
    customizer.accept(builder);
    CoreHttpRequest req = builder.build();
    // request doesn't mysteriously time out while the service locator twiddles its thumbs.
    if (req.bucket() != null) {
        cluster.bucket(req.bucket());
    }
    return req.exec(core).thenApply(HttpResponse::new).exceptionally(t -> {
        HttpStatusCodeException statusCodeException = findCause(t, HttpStatusCodeException.class).orElseThrow(() -> propagate(t));
        return new HttpResponse(statusCodeException);
    });
}
Also used : CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) HttpStatusCodeException(com.couchbase.client.core.error.HttpStatusCodeException)

Aggregations

CoreHttpRequest (com.couchbase.client.core.endpoint.http.CoreHttpRequest)6 Test (org.junit.jupiter.api.Test)4 Core (com.couchbase.client.core.Core)1 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)1 NodeInfo (com.couchbase.client.core.config.NodeInfo)1 PortInfo (com.couchbase.client.core.config.PortInfo)1 DefaultFullHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpResponse)1 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)1 FullHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpResponse)1 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)1 CoreCommonOptions (com.couchbase.client.core.endpoint.http.CoreCommonOptions)1 CoreHttpClient (com.couchbase.client.core.endpoint.http.CoreHttpClient)1 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)1 CoreHttpResponse (com.couchbase.client.core.endpoint.http.CoreHttpResponse)1 HttpStatusCodeException (com.couchbase.client.core.error.HttpStatusCodeException)1 TimeoutException (com.couchbase.client.core.error.TimeoutException)1 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)1