use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest 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);
}
};
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(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 SaslListMechanismsHandlerTest method ignoresUnknownSaslMech.
@Test
void ignoresUnknownSaslMech() {
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_unknown_mech_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.SCRAM_SHA1, SaslMechanism.SCRAM_SHA256, SaslMechanism.SCRAM_SHA512));
UnknownSaslMechanismDetectedEvent event = (UnknownSaslMechanismDetectedEvent) eventBus.publishedEvents().get(0);
assertEquals("FLAUN", event.mechanism());
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method failConnectIfPromiseTimesOut.
/**
* This test makes sure that the timer fires if the connect future is not completed
* otherwise.
*/
@Test
void failConnectIfPromiseTimesOut() throws Exception {
channel = new EmbeddedChannel();
eventBus = new SimpleEventBus(true);
CoreEnvironment env = mock(CoreEnvironment.class);
TimeoutConfig timeoutConfig = mock(TimeoutConfig.class);
when(env.eventBus()).thenReturn(eventBus);
when(env.timeoutConfig()).thenReturn(timeoutConfig);
when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(100));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
EndpointContext endpointContext = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
channel.pipeline().addLast(handler);
final ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
Thread.sleep(Duration.ofMillis(100).toMillis() + 5);
channel.runScheduledPendingTasks();
assertTrue(connect.isDone());
assertTrue(connect.cause() instanceof TimeoutException);
assertEquals("SASL Mechanism listing timed out after 100ms", connect.cause().getMessage());
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method failConnectIfStatusNotSuccess.
@Test
void failConnectIfStatusNotSuccess() {
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("error_sasl_list_mechs_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertFalse(connectFuture.isSuccess());
AuthenticationFailureException cause = (AuthenticationFailureException) connectFuture.cause();
assertTrue(cause.getMessage().contains("Received non-success status from server"));
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelFuture in project couchbase-jvm-clients by couchbase.
the class SelectBucketHandlerTest 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);
}
};
SelectBucketHandler handler = new SelectBucketHandler(endpointContext, "bucket");
channel.pipeline().addLast(failingHandler).addLast(handler);
ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
assertEquals(connectException, connect.awaitUninterruptibly().cause());
}
Aggregations