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();
}
}
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();
}
}
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);
}
}
Aggregations