Search in sources :

Example 11 with NoopRequest

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

the class KeyValueServiceIntegrationTest method connectNoopAndDisconnect.

/**
 * The most simplistic end-to-end test for a KV service.
 *
 * <p>This integration test connects to a node and then performs a NOOP and
 * waits for a successful response.</p>
 *
 * @throws Exception if waiting on the response fails.
 */
@Test
void connectNoopAndDisconnect() throws Exception {
    TestNodeConfig node = config().nodes().get(0);
    KeyValueService service = new KeyValueService(KeyValueServiceConfig.builder().build(), core.context(), node.hostname(), node.ports().get(Services.KV), Optional.of(config().bucketname()), core.context().authenticator());
    service.connect();
    waitUntilCondition(() -> service.state() == ServiceState.CONNECTED);
    NoopRequest request = new NoopRequest(kvTimeout, core.context(), null, CollectionIdentifier.fromDefault(config().bucketname()));
    assertTrue(request.id() > 0);
    service.send(request);
    NoopResponse response = request.response().get(1, TimeUnit.SECONDS);
    assertTrue(response.status().success());
    assertTrue(request.context().dispatchLatency() > 0);
    service.disconnect();
    waitUntilCondition(() -> service.state() == ServiceState.DISCONNECTED);
}
Also used : NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with NoopRequest

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

the class KeyValueEndpointIntegrationTest method connectNoopAndDisconnect.

/**
 * The most simplistic end-to-end test for a KV endpoint.
 *
 * <p>This integration test connects to a node and then performs a NOOP and
 * waits for a successful response.</p>
 *
 * @throws Exception if waiting on the response fails.
 */
@Test
void connectNoopAndDisconnect() throws Exception {
    TestNodeConfig node = config().nodes().get(0);
    KeyValueEndpoint endpoint = new KeyValueEndpoint(serviceContext, node.hostname(), node.ports().get(Services.KV), Optional.of(config().bucketname()), authenticator());
    endpoint.connect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.CONNECTED);
    NoopRequest request = new NoopRequest(kvTimeout, serviceContext, null, CollectionIdentifier.fromDefault(config().bucketname()));
    assertTrue(request.id() > 0);
    endpoint.send(request);
    NoopResponse response = request.response().get(1, TimeUnit.SECONDS);
    assertTrue(response.status().success());
    assertTrue(request.context().dispatchLatency() > 0);
    endpoint.disconnect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
}
Also used : NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with NoopRequest

use of com.couchbase.client.core.msg.kv.NoopRequest 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 14 with NoopRequest

use of com.couchbase.client.core.msg.kv.NoopRequest 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 15 with NoopRequest

use of com.couchbase.client.core.msg.kv.NoopRequest 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)

Aggregations

NoopRequest (com.couchbase.client.core.msg.kv.NoopRequest)20 Test (org.junit.jupiter.api.Test)20 NoopResponse (com.couchbase.client.core.msg.kv.NoopResponse)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Endpoint (com.couchbase.client.core.endpoint.Endpoint)9 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)8 RequestContext (com.couchbase.client.core.msg.RequestContext)8 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)8 EndpointState (com.couchbase.client.core.endpoint.EndpointState)7 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 Invocation (org.mockito.invocation.Invocation)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