use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method propagateConnectFailureFromDownstream.
/**
* This test verifies that if a downstream promise fails that the error
* is propagated through the captured promise.
*/
@Test
void propagateConnectFailureFromDownstream() {
final Exception connectException = new Exception("I failed");
ChannelDuplexHandler failingHandler = new ChannelDuplexHandler() {
@Override
public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {
promise.setFailure(connectException);
}
};
ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
channel.pipeline().addLast(failingHandler).addLast(handler);
ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
assertEquals(connectException, connect.awaitUninterruptibly().cause());
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method decodeUnsuccessfulResponse.
/**
* Make sure that when the server returns a non-successful response we still handle
* it and not crash.
*/
@Test
void decodeUnsuccessfulResponse() {
ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(ErrorMapLoadingHandler.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.ERROR_MAP.opcode(), false, false, true);
assertNotNull(channel.pipeline().get(ErrorMapLoadingHandler.class));
ReferenceCountUtil.release(writtenRequest);
ByteBuf response = decodeHexDump(readResource("error_errormap_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
assertEquals(1, eventBus.publishedEvents().size());
ErrorMapLoadingFailedEvent event = (ErrorMapLoadingFailedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.WARN, event.severity());
assertEquals("KV Error Map Negotiation failed (Status 0x1)", event.description());
assertNull(channel.attr(ChannelAttributes.ERROR_MAP_KEY).get());
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method decodeAndPropagateSuccessHelloResponse.
/**
* This test verifies that a successful hello response is properly handled.
*/
@Test
void decodeAndPropagateSuccessHelloResponse() {
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("success_hello_response.txt", FeatureNegotiatingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
assertEquals(1, eventBus.publishedEvents().size());
FeaturesNegotiatedEvent event = (FeaturesNegotiatedEvent) eventBus.publishedEvents().get(0);
assertEquals("Negotiated [TCPNODELAY, XATTR, XERROR, SELECT_BUCKET, SNAPPY, TRACING]", event.description());
assertEquals(Event.Severity.DEBUG, event.severity());
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.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method decodesSuccessfulSaslMechsList.
@Test
void decodesSuccessfulSaslMechsList() {
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(SaslListMechanismsHandler.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.SASL_LIST_MECHS.opcode(), false, false, false);
assertNotNull(channel.pipeline().get(SaslListMechanismsHandler.class));
ReferenceCountUtil.release(writtenRequest);
ByteBuf response = decodeHexDump(readResource("success_sasl_list_mechs_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
Set<SaslMechanism> saslMechanisms = channel.attr(ChannelAttributes.SASL_MECHS_KEY).get();
assertEquals(saslMechanisms, EnumSet.of(SaslMechanism.PLAIN, SaslMechanism.SCRAM_SHA1, SaslMechanism.SCRAM_SHA256, SaslMechanism.SCRAM_SHA512));
assertTrue(eventBus.publishedEvents().get(0) instanceof SaslMechanismsListedEvent);
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method failConnectIfSaslMechsListEmpty.
@Test
void failConnectIfSaslMechsListEmpty() {
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(SaslListMechanismsHandler.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.SASL_LIST_MECHS.opcode(), false, false, false);
assertNotNull(channel.pipeline().get(SaslListMechanismsHandler.class));
ReferenceCountUtil.release(writtenRequest);
ByteBuf response = decodeHexDump(readResource("success_sasl_list_mechs_empty_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertFalse(connectFuture.isSuccess());
AuthenticationFailureException cause = (AuthenticationFailureException) connectFuture.cause();
assertTrue(cause.getMessage().contains("Received empty mechanism list from server"));
}
Aggregations