use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method propagatesChannelActiveAfterSendingInitialRequest.
/**
* This test makes sure that after the initial request is sent, the channel active signal is
* propagated so that we do not regress bootstrap pipelining functionality.
*/
@Test
void propagatesChannelActiveAfterSendingInitialRequest() {
final ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
final AtomicBoolean channelActiveFired = new AtomicBoolean();
channel.pipeline().addLast(handler).addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channelActiveFired.set(true);
}
});
assertEquals(handler, channel.pipeline().get(ErrorMapLoadingHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
waitUntilCondition(channelActiveFired::get);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method decodeNonSuccessfulHelloResponse.
/**
* This test checks that a non-successful response is properly handled.
*/
@Test
void decodeNonSuccessfulHelloResponse() {
Set<ServerFeature> toNegotiate = EnumSet.of(ServerFeature.TCPNODELAY, ServerFeature.XATTR, ServerFeature.XERROR, ServerFeature.SELECT_BUCKET, ServerFeature.SNAPPY, ServerFeature.TRACING);
FeatureNegotiatingHandler handler = new FeatureNegotiatingHandler(endpointContext, toNegotiate);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(FeatureNegotiatingHandler.class));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
assertFalse(connectFuture.isDone());
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
ByteBuf writtenRequest = channel.readOutbound();
verifyRequest(writtenRequest, MemcacheProtocol.Opcode.HELLO.opcode(), true, false, true);
assertNotNull(channel.pipeline().get(FeatureNegotiatingHandler.class));
ByteBuf response = decodeHexDump(readResource("error_hello_response.txt", FeatureNegotiatingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
assertEquals(2, eventBus.publishedEvents().size());
FeaturesNegotiationFailedEvent failureEvent = (FeaturesNegotiationFailedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.WARN, failureEvent.severity());
assertEquals("HELLO Negotiation failed (Status 0x1)", failureEvent.description());
FeaturesNegotiatedEvent event = (FeaturesNegotiatedEvent) eventBus.publishedEvents().get(1);
assertEquals("Negotiated []", event.description());
assertEquals(Event.Severity.DEBUG, event.severity());
Set<ServerFeature> serverFeatures = channel.attr(ChannelAttributes.SERVER_FEATURE_KEY).get();
assertTrue(serverFeatures.isEmpty());
assertNull(channel.pipeline().get(FeatureNegotiatingHandler.class));
ReferenceCountUtil.release(writtenRequest);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method decodeAndIgnoreNonAskedForFeaturesInResponse.
/**
* Should the server return non-asked-for features, ignore them.
*/
@Test
void decodeAndIgnoreNonAskedForFeaturesInResponse() {
Set<ServerFeature> toNegotiate = EnumSet.of(ServerFeature.SNAPPY, ServerFeature.TRACING);
FeatureNegotiatingHandler handler = new FeatureNegotiatingHandler(endpointContext, toNegotiate);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(FeatureNegotiatingHandler.class));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
assertFalse(connectFuture.isDone());
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
ByteBuf writtenRequest = channel.readOutbound();
verifyRequest(writtenRequest, MemcacheProtocol.Opcode.HELLO.opcode(), true, false, true);
assertNotNull(channel.pipeline().get(FeatureNegotiatingHandler.class));
ByteBuf response = decodeHexDump(readResource("success_hello_response.txt", FeatureNegotiatingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
assertEquals(2, eventBus.publishedEvents().size());
UnsolicitedFeaturesReturnedEvent unsolicitedEvent = (UnsolicitedFeaturesReturnedEvent) eventBus.publishedEvents().get(0);
assertEquals("Received unsolicited features during HELLO [TCPNODELAY, XATTR, XERROR, SELECT_BUCKET]", unsolicitedEvent.description());
assertEquals(Event.Severity.WARN, unsolicitedEvent.severity());
FeaturesNegotiatedEvent event = (FeaturesNegotiatedEvent) eventBus.publishedEvents().get(1);
assertEquals("Negotiated [SNAPPY, TRACING]", event.description());
Set<ServerFeature> serverFeatures = channel.attr(ChannelAttributes.SERVER_FEATURE_KEY).get();
assertEquals(toNegotiate, serverFeatures);
assertNull(channel.pipeline().get(FeatureNegotiatingHandler.class));
ReferenceCountUtil.release(writtenRequest);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method propagatesChannelActiveAfterSendingInitialRequest.
/**
* This test makes sure that after the initial request is sent, the channel active signal is
* propagated so that we do not regress bootstrap pipelining functionality.
*/
@Test
void propagatesChannelActiveAfterSendingInitialRequest() {
final FeatureNegotiatingHandler handler = new FeatureNegotiatingHandler(endpointContext, Collections.singleton(ServerFeature.SELECT_BUCKET));
final AtomicBoolean channelActiveFired = new AtomicBoolean();
channel.pipeline().addLast(handler).addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channelActiveFired.set(true);
}
});
assertEquals(handler, channel.pipeline().get(FeatureNegotiatingHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
waitUntilCondition(channelActiveFired::get);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class KeyValueMessageHandlerTest method retriesCertainResponseStatusCodes.
/**
* Certain status codes are identified that should be passed to the retry orchestrator rathen than complete
* the response right away.
*/
@Test
void retriesCertainResponseStatusCodes() {
List<MemcacheProtocol.Status> retryOnThese = Arrays.asList(MemcacheProtocol.Status.LOCKED, MemcacheProtocol.Status.TEMPORARY_FAILURE, MemcacheProtocol.Status.SYNC_WRITE_IN_PROGRESS, MemcacheProtocol.Status.SYNC_WRITE_RE_COMMIT_IN_PROGRESS);
List<RetryReason> retryReasons = Arrays.asList(RetryReason.KV_LOCKED, RetryReason.KV_TEMPORARY_FAILURE, RetryReason.KV_SYNC_WRITE_IN_PROGRESS, RetryReason.KV_SYNC_WRITE_RE_COMMIT_IN_PROGRESS);
int i = 0;
for (MemcacheProtocol.Status status : retryOnThese) {
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, status.status(), request.opaque(), 0, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
channel.writeInbound(getResponse);
assertEquals(CancellationReason.noMoreRetries(retryReasons.get(i)), request.cancellationReason());
assertEquals(0, getResponse.refCnt());
i++;
} finally {
channel.finishAndReleaseAll();
}
}
}
Aggregations