Search in sources :

Example 6 with RequestCanceledException

use of com.couchbase.client.core.error.RequestCanceledException 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 7 with RequestCanceledException

use of com.couchbase.client.core.error.RequestCanceledException 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

RequestCanceledException (com.couchbase.client.core.error.RequestCanceledException)7 Test (org.junit.jupiter.api.Test)5 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)4 RequestContext (com.couchbase.client.core.msg.RequestContext)4 NoopRequest (com.couchbase.client.core.msg.kv.NoopRequest)3 NoopResponse (com.couchbase.client.core.msg.kv.NoopResponse)3 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)3 StepVerifier (reactor.test.StepVerifier)3 CancellationReason (com.couchbase.client.core.msg.CancellationReason)2 ExecutionException (java.util.concurrent.ExecutionException)2 InitGlobalConfigFailedEvent (com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent)1 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)1 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)1 AlreadyShutdownException (com.couchbase.client.core.error.AlreadyShutdownException)1 AmbiguousTimeoutException (com.couchbase.client.core.error.AmbiguousTimeoutException)1 ConfigException (com.couchbase.client.core.error.ConfigException)1 GlobalConfigNotFoundException (com.couchbase.client.core.error.GlobalConfigNotFoundException)1 TimeoutException (com.couchbase.client.core.error.TimeoutException)1 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)1 UnsupportedConfigMechanismException (com.couchbase.client.core.error.UnsupportedConfigMechanismException)1