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);
}
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);
}
}
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);
}
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();
}
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);
});
}
Aggregations