Search in sources :

Example 16 with GetRequest

use of com.couchbase.client.core.msg.kv.GetRequest in project couchbase-jvm-clients by couchbase.

the class KeyValueMessageHandlerTest method incrementsNotMyVbucketIndicator.

@Test
void incrementsNotMyVbucketIndicator() {
    EmbeddedChannel channel = new EmbeddedChannel(new KeyValueMessageHandler(null, CTX, Optional.of(BUCKET)));
    try {
        GetRequest request = new GetRequest("key", Duration.ofSeconds(1), CTX, CID, FailFastRetryStrategy.INSTANCE, null);
        channel.writeOutbound(request);
        ByteBuf getResponse = MemcacheProtocol.response(channel.alloc(), MemcacheProtocol.Opcode.GET, (byte) 0, MemcacheProtocol.Status.NOT_MY_VBUCKET.status(), request.opaque(), 0, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
        channel.writeInbound(getResponse);
        assertEquals(1, request.rejectedWithNotMyVbucket());
    } finally {
        channel.finishAndReleaseAll();
    }
}
Also used : GetRequest(com.couchbase.client.core.msg.kv.GetRequest) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 17 with GetRequest

use of com.couchbase.client.core.msg.kv.GetRequest in project couchbase-jvm-clients by couchbase.

the class KeyValueMessageHandlerTest method closesChannelWithInvalidOpaque.

/**
 * If a response is received with an invalid opaque that the channel knows nothing about, it should be
 * closed to bring it back to a valid state eventually.
 */
@Test
void closesChannelWithInvalidOpaque() {
    EmbeddedChannel channel = new EmbeddedChannel(new KeyValueMessageHandler(null, CTX, Optional.of(BUCKET)));
    try {
        GetRequest request1 = new GetRequest("key", Duration.ofSeconds(1), CTX, CID, FailFastRetryStrategy.INSTANCE, null);
        GetRequest request2 = new GetRequest("key", Duration.ofSeconds(1), CTX, CID, FailFastRetryStrategy.INSTANCE, null);
        channel.writeOutbound(request1, request2);
        assertTrue(channel.isOpen());
        ByteBuf getResponse = MemcacheProtocol.response(channel.alloc(), MemcacheProtocol.Opcode.GET, (byte) 0, (short) 0xFF, 1234, 0, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
        channel.writeInbound(getResponse);
        assertThrows(ExecutionException.class, () -> request1.response().get());
        assertEquals(RetryReason.CHANNEL_CLOSED_WHILE_IN_FLIGHT, request1.cancellationReason().innerReason());
        assertThrows(ExecutionException.class, () -> request2.response().get());
        assertEquals(RetryReason.CHANNEL_CLOSED_WHILE_IN_FLIGHT, request2.cancellationReason().innerReason());
        assertFalse(channel.isOpen());
        assertEquals(0, getResponse.refCnt());
    } finally {
        channel.finishAndReleaseAll();
    }
}
Also used : GetRequest(com.couchbase.client.core.msg.kv.GetRequest) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 18 with GetRequest

use of com.couchbase.client.core.msg.kv.GetRequest in project couchbase-jvm-clients by couchbase.

the class PartitionSelectionStrategyTest method selectPinnedForBinaryWithKey.

@Test
void selectPinnedForBinaryWithKey() {
    EndpointSelectionStrategy strategy = new PartitionSelectionStrategy();
    Endpoint endpoint1 = mock(Endpoint.class);
    Endpoint endpoint2 = mock(Endpoint.class);
    Endpoint endpoint3 = mock(Endpoint.class);
    when(endpoint1.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint2.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint3.state()).thenReturn(EndpointState.CONNECTED);
    when(endpoint1.freeToWrite()).thenReturn(true);
    when(endpoint2.freeToWrite()).thenReturn(true);
    when(endpoint3.freeToWrite()).thenReturn(true);
    List<Endpoint> endpoints = Arrays.asList(endpoint1, endpoint2, endpoint3);
    GetRequest request = mock(GetRequest.class);
    when(request.partition()).thenReturn((short) 12);
    Endpoint selected = strategy.select(request, endpoints);
    for (int i = 0; i < 1000; i++) {
        assertNotNull(selected);
        assertEquals(selected, endpoint1);
    }
}
Also used : Endpoint(com.couchbase.client.core.endpoint.Endpoint) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) EndpointSelectionStrategy(com.couchbase.client.core.service.EndpointSelectionStrategy) Endpoint(com.couchbase.client.core.endpoint.Endpoint) Test(org.junit.jupiter.api.Test)

Aggregations

GetRequest (com.couchbase.client.core.msg.kv.GetRequest)18 Test (org.junit.jupiter.api.Test)14 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)6 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)6 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)5 ArrayList (java.util.ArrayList)5 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)4 NodeInfo (com.couchbase.client.core.config.NodeInfo)4 RequestContext (com.couchbase.client.core.msg.RequestContext)4 GetResponse (com.couchbase.client.core.msg.kv.GetResponse)3 Core (com.couchbase.client.core.Core)2 CoreContext (com.couchbase.client.core.CoreContext)2 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 Endpoint (com.couchbase.client.core.endpoint.Endpoint)2 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)2 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)2 InsertResponse (com.couchbase.client.core.msg.kv.InsertResponse)2 SubdocGetRequest (com.couchbase.client.core.msg.kv.SubdocGetRequest)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 EndpointSelectionStrategy (com.couchbase.client.core.service.EndpointSelectionStrategy)2