Search in sources :

Example 6 with NoopResponse

use of com.couchbase.client.core.msg.kv.NoopResponse in project couchbase-jvm-clients by couchbase.

the class KeyValueChannelIntegrationTest method connectNoopAndDisconnect.

/**
 * This is the most simple kv test case one can do in a full-stack manner.
 *
 * <p>It connects to a kv socket, including all auth and bucket selection. It then
 * checks that the channel is opened properly and performs a NOOP and checks for a
 * successful result. Then it shuts everything down.</p>
 *
 * @throws Exception if waiting on the response fails.
 */
@Test
void connectNoopAndDisconnect() throws Exception {
    TestNodeConfig node = config().nodes().get(0);
    Bootstrap bootstrap = new Bootstrap().remoteAddress(node.hostname(), node.ports().get(Services.KV)).group(eventLoopGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) {
            new KeyValueEndpoint.KeyValuePipelineInitializer(endpointContext, Optional.of(config().bucketname()), endpointContext.authenticator()).init(null, ch.pipeline());
        }
    });
    Channel channel = bootstrap.connect().awaitUninterruptibly().channel();
    assertTrue(channel.isActive());
    assertTrue(channel.isOpen());
    NoopRequest request = new NoopRequest(Duration.ZERO, endpointContext, null, CollectionIdentifier.fromDefault(config().bucketname()));
    channel.writeAndFlush(request);
    NoopResponse response = request.response().get(1, TimeUnit.SECONDS);
    assertTrue(response.status().success());
    channel.close().awaitUninterruptibly();
}
Also used : NioSocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.nio.NioSocketChannel) NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) SocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.SocketChannel) NioSocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.nio.NioSocketChannel) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) SocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.SocketChannel) Channel(com.couchbase.client.core.deps.io.netty.channel.Channel) NioSocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.nio.NioSocketChannel) Bootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with NoopResponse

use of com.couchbase.client.core.msg.kv.NoopResponse in project couchbase-jvm-clients by couchbase.

the class ReactorTest method completesWithErrorBeforeSubscription.

@Test
void completesWithErrorBeforeSubscription() {
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    RequestCanceledException exception = mock(RequestCanceledException.class);
    request.fail(exception);
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), true);
    StepVerifier verifier = StepVerifier.create(mono).expectError(RequestCanceledException.class);
    verifier.verify();
}
Also used : NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) RequestContext(com.couchbase.client.core.msg.RequestContext) StepVerifier(reactor.test.StepVerifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) Test(org.junit.jupiter.api.Test)

Example 8 with NoopResponse

use of com.couchbase.client.core.msg.kv.NoopResponse in project couchbase-jvm-clients by couchbase.

the class ReactorTest method noErrorDroppedWhenCancelledViaCompletionException.

@Test
void noErrorDroppedWhenCancelledViaCompletionException() {
    AtomicInteger droppedErrors = new AtomicInteger(0);
    Hooks.onErrorDropped(v -> {
        droppedErrors.incrementAndGet();
    });
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    // Because this is a multi-step CompleteableFuture, the RequestCanceledException will be wrapped in a
    // CompletionException in the internals.  It will be unwrapped by the time it is raised to the app.
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response().thenApply(v -> v), true);
    Disposable subscriber = mono.subscribe();
    StepVerifier verifier = StepVerifier.create(mono).expectError(RequestCanceledException.class);
    subscriber.dispose();
    verifier.verify();
    assertEquals(0, droppedErrors.get());
}
Also used : NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) FluxSink(reactor.core.publisher.FluxSink) Hooks(reactor.core.publisher.Hooks) NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) ArrayList(java.util.ArrayList) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) RequestContext(com.couchbase.client.core.msg.RequestContext) RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CancellationReason(com.couchbase.client.core.msg.CancellationReason) Subscriber(org.reactivestreams.Subscriber) ExecutorService(java.util.concurrent.ExecutorService) DirectProcessor(reactor.core.publisher.DirectProcessor) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) Mono(reactor.core.publisher.Mono) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) List(java.util.List) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) Subscription(org.reactivestreams.Subscription) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) Mockito.mock(org.mockito.Mockito.mock) Disposable(reactor.core.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RequestContext(com.couchbase.client.core.msg.RequestContext) StepVerifier(reactor.test.StepVerifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) Test(org.junit.jupiter.api.Test)

Example 9 with NoopResponse

use of com.couchbase.client.core.msg.kv.NoopResponse in project couchbase-jvm-clients by couchbase.

the class ReactorTest method completesWithSuccessBeforeSubscription.

@Test
void completesWithSuccessBeforeSubscription() {
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    NoopResponse response = mock(NoopResponse.class);
    request.succeed(response);
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), true);
    StepVerifier verifier = StepVerifier.create(mono).expectNext(response).expectComplete();
    verifier.verify();
}
Also used : NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) RequestContext(com.couchbase.client.core.msg.RequestContext) StepVerifier(reactor.test.StepVerifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) Test(org.junit.jupiter.api.Test)

Example 10 with NoopResponse

use of com.couchbase.client.core.msg.kv.NoopResponse in project couchbase-jvm-clients by couchbase.

the class ReactorTest method ignoresCancellationPropagation.

@Test
void ignoresCancellationPropagation() {
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), false);
    assertThrows(Exception.class, () -> mono.timeout(Duration.ofMillis(10)).block());
    assertFalse(request.response().isCompletedExceptionally());
    assertFalse(request.response().isDone());
}
Also used : NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) RequestContext(com.couchbase.client.core.msg.RequestContext) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

NoopRequest (com.couchbase.client.core.msg.kv.NoopRequest)11 NoopResponse (com.couchbase.client.core.msg.kv.NoopResponse)11 Test (org.junit.jupiter.api.Test)11 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)8 RequestContext (com.couchbase.client.core.msg.RequestContext)8 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)8 StepVerifier (reactor.test.StepVerifier)6 RequestCanceledException (com.couchbase.client.core.error.RequestCanceledException)3 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)3 TestNodeConfig (com.couchbase.client.test.TestNodeConfig)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Disposable (reactor.core.Disposable)2 Bootstrap (com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap)1 Channel (com.couchbase.client.core.deps.io.netty.channel.Channel)1 SocketChannel (com.couchbase.client.core.deps.io.netty.channel.socket.SocketChannel)1 NioSocketChannel (com.couchbase.client.core.deps.io.netty.channel.socket.nio.NioSocketChannel)1 CancellationReason (com.couchbase.client.core.msg.CancellationReason)1 Util.waitUntilCondition (com.couchbase.client.test.Util.waitUntilCondition)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1