use of com.couchbase.client.core.msg.Response 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.Response in project couchbase-jvm-clients by couchbase.
the class BaseEndpointTest method writeAndFlushToChannelIfFullyConnected.
/**
* If we are fully connected and the circuit breaker is closed, make sure that we can
* write the request into the channel and it is flushed as well.
*/
@Test
@SuppressWarnings({ "unchecked" })
void writeAndFlushToChannelIfFullyConnected() {
EmbeddedChannel channel = new EmbeddedChannel();
InstrumentedEndpoint endpoint = connectSuccessfully(channel);
assertEquals(0, endpoint.lastResponseReceived());
Request<Response> request = mock(Request.class);
CompletableFuture<Response> response = new CompletableFuture<>();
when(request.response()).thenReturn(response);
when(request.context()).thenReturn(new RequestContext(ctx, request));
assertEquals(0, endpoint.outstandingRequests());
endpoint.send(request);
assertEquals(1, endpoint.outstandingRequests());
assertEquals(request, channel.readOutbound());
assertEquals(0, endpoint.lastResponseReceived());
response.complete(mock(Response.class));
endpoint.markRequestCompletion();
assertTrue(endpoint.lastResponseReceived() > 0);
assertEquals(0, endpoint.outstandingRequests());
}
Aggregations