Search in sources :

Example 1 with NoopResponse

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

the class ReactorTest method propagatesCancellation.

@Test
void propagatesCancellation() {
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), true);
    assertThrows(Exception.class, () -> mono.timeout(Duration.ofMillis(10)).block());
    assertTrue(request.response().isCompletedExceptionally());
    assertTrue(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)

Example 2 with NoopResponse

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

the class ReactorTest method completesWithErrorAfterSubscription.

@Test
void completesWithErrorAfterSubscription() {
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), true);
    RequestCanceledException exception = mock(RequestCanceledException.class);
    StepVerifier verifier = StepVerifier.create(mono).expectError(RequestCanceledException.class);
    request.fail(exception);
    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 3 with NoopResponse

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

the class ReactorTest method completesWithSuccessAfterSubscription.

@Test
void completesWithSuccessAfterSubscription() {
    NoopRequest request = new NoopRequest(Duration.ZERO, mock(RequestContext.class), mock(RetryStrategy.class), mock(CollectionIdentifier.class));
    Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), true);
    NoopResponse response = mock(NoopResponse.class);
    StepVerifier verifier = StepVerifier.create(mono).expectNext(response).expectComplete();
    request.succeed(response);
    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 4 with NoopResponse

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

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

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