use of com.couchbase.client.core.msg.Request in project couchbase-jvm-clients by couchbase.
the class NodeTest method retriesIfLocalServiceNotFound.
@Test
@SuppressWarnings({ "unchecked" })
void retriesIfLocalServiceNotFound() {
final Service s = mock(Service.class);
final AtomicReference<Request<?>> retried = new AtomicReference<>();
Node node = new Node(CTX, mock(NodeIdentifier.class), NO_ALTERNATE) {
@Override
protected Service createService(ServiceType serviceType, int port, Optional<String> bucket) {
when(s.state()).thenReturn(ServiceState.CONNECTED);
when(s.states()).thenReturn(DirectProcessor.create());
when(s.type()).thenReturn(serviceType);
return s;
}
@Override
protected <R extends Request<? extends Response>> void sendIntoRetry(R request) {
retried.set(request);
}
};
node.addService(ServiceType.KV, 11210, Optional.of("bucket")).block();
KeyValueRequest r = mock(KeyValueRequest.class);
when(r.serviceType()).thenReturn(ServiceType.KV);
when(r.bucket()).thenReturn("other_bucket");
node.send(r);
verify(s, never()).send(eq(r));
assertEquals(r, retried.get());
}
use of com.couchbase.client.core.msg.Request in project couchbase-jvm-clients by couchbase.
the class RetryOrchestratorTest method cancelIfNoMoreRetriesAllowed.
@Test
@SuppressWarnings({ "unchecked" })
void cancelIfNoMoreRetriesAllowed() {
RetryStrategy retryStrategy = mock(RetryStrategy.class);
when(retryStrategy.shouldRetry(any(Request.class), any(RetryReason.class))).thenReturn(CompletableFuture.completedFuture(RetryAction.noRetry()));
Request<?> request = mock(Request.class);
when(request.completed()).thenReturn(false);
when(request.retryStrategy()).thenReturn(retryStrategy);
RequestContext requestContext = mock(RequestContext.class);
when(request.context()).thenReturn(requestContext);
CoreEnvironment env = mock(CoreEnvironment.class);
SimpleEventBus eventBus = new SimpleEventBus(true);
when(env.eventBus()).thenReturn(eventBus);
CoreContext context = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
RetryOrchestrator.maybeRetry(context, request, RetryReason.UNKNOWN);
verify(request, times(1)).cancel(CancellationReason.noMoreRetries(RetryReason.UNKNOWN), Function.identity());
assertEquals(1, eventBus.publishedEvents().size());
RequestNotRetriedEvent retryEvent = (RequestNotRetriedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.INFO, retryEvent.severity());
assertEquals(Event.Category.REQUEST.path(), retryEvent.category());
assertEquals(requestContext, retryEvent.context());
}
use of com.couchbase.client.core.msg.Request in project couchbase-jvm-clients by couchbase.
the class RoundRobinSelectionStrategyTest method testRoundRobinSelectOverIntegerMaxValue.
@Test
@SuppressWarnings("unchecked")
void testRoundRobinSelectOverIntegerMaxValue() {
RoundRobinSelectionStrategy strategy = new RoundRobinSelectionStrategy();
Endpoint a = Mockito.mock(Endpoint.class);
Endpoint b = Mockito.mock(Endpoint.class);
Endpoint c = Mockito.mock(Endpoint.class);
Endpoint d = Mockito.mock(Endpoint.class);
Endpoint e = Mockito.mock(Endpoint.class);
when(a.state()).thenReturn(EndpointState.CONNECTED);
when(a.freeToWrite()).thenReturn(true);
when(b.state()).thenReturn(EndpointState.CONNECTED);
when(b.freeToWrite()).thenReturn(true);
when(c.state()).thenReturn(EndpointState.CONNECTED);
when(c.freeToWrite()).thenReturn(true);
when(d.state()).thenReturn(EndpointState.CONNECTED);
when(d.freeToWrite()).thenReturn(true);
when(e.state()).thenReturn(EndpointState.CONNECTED);
when(e.freeToWrite()).thenReturn(true);
List<Endpoint> endpoints = Arrays.asList(a, b, c, d, e);
Request request = Mockito.mock(Request.class);
strategy.setSkip(Integer.MAX_VALUE - 2);
// selecting brings skip to max-value - 1
strategy.select(request, endpoints);
int skipStart = strategy.currentSkip();
assertTrue(skipStart > 1000);
// max-value
strategy.select(request, endpoints);
assertEquals(skipStart + 1, strategy.currentSkip());
assertTrue(strategy.currentSkip() > 0);
// max-value + 1: wrapping
Endpoint selected = strategy.select(request, endpoints);
assertEquals(0, strategy.currentSkip());
assertEquals(selected, a);
// following selects will select B, C, D, E, A and increment skip to 5
selected = strategy.select(request, endpoints);
assertEquals(1, strategy.currentSkip());
assertEquals(selected, b);
selected = strategy.select(request, endpoints);
assertEquals(2, strategy.currentSkip());
assertEquals(selected, c);
selected = strategy.select(request, endpoints);
assertEquals(3, strategy.currentSkip());
assertEquals(selected, d);
selected = strategy.select(request, endpoints);
assertEquals(4, strategy.currentSkip());
assertEquals(selected, e);
selected = strategy.select(request, endpoints);
assertEquals(5, strategy.currentSkip());
assertEquals(selected, a);
}
Aggregations