Search in sources :

Example 11 with Response

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());
}
Also used : Response(com.couchbase.client.core.msg.Response) KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) Optional(java.util.Optional) ServiceType(com.couchbase.client.core.service.ServiceType) QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) Request(com.couchbase.client.core.msg.Request) KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) Service(com.couchbase.client.core.service.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 12 with Response

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());
}
Also used : Response(com.couchbase.client.core.msg.Response) CompletableFuture(java.util.concurrent.CompletableFuture) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) RequestContext(com.couchbase.client.core.msg.RequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

Response (com.couchbase.client.core.msg.Response)12 ChannelClosedProactivelyEvent (com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent)4 InvalidRequestDetectedEvent (com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent)4 Request (com.couchbase.client.core.msg.Request)4 KeyValueRequest (com.couchbase.client.core.msg.kv.KeyValueRequest)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)3 RequestTracer (com.couchbase.client.core.cnc.RequestTracer)3 UnsupportedResponseTypeReceivedEvent (com.couchbase.client.core.cnc.events.io.UnsupportedResponseTypeReceivedEvent)3 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)3 ResponseStatus (com.couchbase.client.core.msg.ResponseStatus)3 RetryReason (com.couchbase.client.core.retry.RetryReason)3 ServiceType (com.couchbase.client.core.service.ServiceType)3 Optional (java.util.Optional)3 KeyValueErrorMapCodeHandledEvent (com.couchbase.client.core.cnc.events.io.KeyValueErrorMapCodeHandledEvent)2 UnknownResponseStatusReceivedEvent (com.couchbase.client.core.cnc.events.io.UnknownResponseStatusReceivedEvent)2 ConfigurationProvider (com.couchbase.client.core.config.ConfigurationProvider)2 MemcachedBucketConfig (com.couchbase.client.core.config.MemcachedBucketConfig)2 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)2 FullHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpResponse)2 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)2