use of com.couchbase.client.core.msg.kv.NoopRequest 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();
}
use of com.couchbase.client.core.msg.kv.NoopRequest 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());
}
use of com.couchbase.client.core.msg.kv.NoopRequest in project couchbase-jvm-clients by couchbase.
the class ReactorTest method noErrorDroppedWhenCancelledViaRequestCanceledException.
@Test
void noErrorDroppedWhenCancelledViaRequestCanceledException() {
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 single-stage CompleteableFuture, the RequestCanceledException will raised directly in the
// internals.
Mono<NoopResponse> mono = Reactor.wrap(request, request.response(), true);
Disposable subscriber = mono.subscribe();
StepVerifier verifier = StepVerifier.create(mono).expectError(RequestCanceledException.class);
subscriber.dispose();
verifier.verify();
assertEquals(0, droppedErrors.get());
}
use of com.couchbase.client.core.msg.kv.NoopRequest in project couchbase-jvm-clients by couchbase.
the class PooledServiceTest method retriesRequestIfEndpointCannotConnect.
/**
* With direct dispatch in the pool it is possible that endpoint for which the socket is
* waiting for to be dispatched never goes into a connected state but rather into disconnected
* (and then subsequent reconnect). As soon as we observe a disconnect state we need to retry the
* op so that it has a chance to complete somewhere else.
*/
@Test
void retriesRequestIfEndpointCannotConnect() {
int minEndpoints = 0;
Endpoint mock1 = mock(Endpoint.class);
when(mock1.state()).thenReturn(EndpointState.DISCONNECTED);
DirectProcessor<EndpointState> states = DirectProcessor.create();
when(mock1.states()).thenReturn(states);
when(mock1.outstandingRequests()).thenReturn(0L);
final List<Endpoint> mocks = Collections.singletonList(mock1);
final AtomicInteger invocation = new AtomicInteger();
MockedService service = new MockedService(new MockedServiceConfig(minEndpoints, 2, Duration.ofMillis(500), false), () -> mocks.get(invocation.getAndIncrement()), new FirstEndpointSelectionStrategy());
service.connect();
assertTrue(service.trackedEndpoints().isEmpty());
NoopRequest request = new NoopRequest(Duration.ofSeconds(1), serviceContext, BestEffortRetryStrategy.INSTANCE, CollectionIdentifier.fromDefault("bucket"));
service.send(request);
// Simulate the connecting and connected
states.onNext(EndpointState.CONNECTING);
states.onNext(EndpointState.DISCONNECTED);
waitUntilCondition(() -> !service.trackedEndpoints.isEmpty());
assertEquals(1, service.trackedEndpoints().size());
waitUntilCondition(() -> request.context().retryAttempts() >= 1);
verify(mock1, never()).send(request);
}
use of com.couchbase.client.core.msg.kv.NoopRequest in project couchbase-jvm-clients by couchbase.
the class PooledServiceTest method retriesIfNoSlotAvailable.
@Test
void retriesIfNoSlotAvailable() {
int minEndpoints = 0;
Endpoint mock1 = mock(Endpoint.class);
when(mock1.state()).thenReturn(EndpointState.CONNECTED);
when(mock1.outstandingRequests()).thenReturn(1L);
DirectProcessor<EndpointState> states = DirectProcessor.create();
when(mock1.states()).thenReturn(states);
final List<Endpoint> mocks = Collections.singletonList(mock1);
final AtomicInteger invocation = new AtomicInteger();
MockedService service = new MockedService(new MockedServiceConfig(minEndpoints, 1, Duration.ofMillis(500), false), () -> mocks.get(invocation.getAndIncrement()), new FirstEndpointSelectionStrategy());
service.connect();
assertTrue(service.trackedEndpoints().isEmpty());
NoopRequest request1 = new NoopRequest(Duration.ofSeconds(1), serviceContext, BestEffortRetryStrategy.INSTANCE, CollectionIdentifier.fromDefault("bucket"));
NoopRequest request2 = new NoopRequest(Duration.ofSeconds(1), serviceContext, BestEffortRetryStrategy.INSTANCE, CollectionIdentifier.fromDefault("bucket"));
service.send(request1);
service.send(request2);
assertEquals(1, service.trackedEndpoints().size());
// The first request is sent into the free slot without retrying
assertEquals(0, request1.context().retryAttempts());
// No more slots available, this one goes into retry
assertTrue(request2.context().retryAttempts() > 0);
// Simulate the connecting and connected
states.onNext(EndpointState.CONNECTING);
states.onNext(EndpointState.CONNECTED);
waitUntilCondition(() -> {
Collection<Invocation> invocations = Mockito.mockingDetails(mock1).getInvocations();
for (Invocation inv : invocations) {
if (inv.getMethod().getName().equals("send")) {
if (inv.getArgument(0) == request1) {
return true;
}
}
}
return false;
});
verify(mock1, never()).send(request2);
}
Aggregations