@Test void decodeSuccessfulResponseWithEmptyMap() { 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( "success_empty_errormap_response.txt", ErrorMapLoadingHandlerTest.class )); channel.writeInbound(response); channel.runPendingTasks(); assertTrue(connectFuture.isSuccess()); assertEquals(2, eventBus.publishedEvents().size()); ErrorMapUndecodableEvent undecodableEvent = (ErrorMapUndecodableEvent) eventBus.publishedEvents().get(0); assertEquals( "KV Error Map loaded but undecodable. " + "Message: \"No content in response\", Content: \"\"", undecodableEvent.description() ); ErrorMapLoadedEvent event = (ErrorMapLoadedEvent) eventBus.publishedEvents().get(1); assertEquals(Event.Severity.DEBUG, event.severity()); Optional<ErrorMap> maybeMap = event.errorMap(); assertFalse(maybeMap.isPresent()); }
@Override public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { interceptedConnectPromise = promise; ChannelPromise downstream = ctx.newPromise(); downstream.addListener(f -> { if (!f.isSuccess() && !interceptedConnectPromise.isDone()) { ConnectTimings.record(ctx.channel(), this.getClass()); interceptedConnectPromise.tryFailure(f.cause()); } }); ctx.connect(remoteAddress, localAddress, downstream); }
ErrorMapLoadingHandler extends ChannelDuplexHandler { @Override public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { interceptedConnectPromise = promise; ChannelPromise downstream = ctx.newPromise(); downstream.addListener(f -> { if (!f.isSuccess() && !interceptedConnectPromise.isDone()) { ConnectTimings.record(ctx.channel(), this.getClass()); interceptedConnectPromise.tryFailure(f.cause()); } }); ctx.connect(remoteAddress, localAddress, downstream); } }
ErrorMapLoadingHandler extends ChannelDuplexHandler { @Override public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { interceptedConnectPromise = promise; ChannelPromise downstream = ctx.newPromise(); downstream.addListener(f -> { if (!f.isSuccess() && !interceptedConnectPromise.isDone()) { ConnectTimings.record(ctx.channel(), this.getClass()); interceptedConnectPromise.tryFailure(f.cause()); } }); ctx.connect(remoteAddress, localAddress, downstream); } ErrorMapLoadingHandler(final EndpointContext endpointContext); }
ErrorMapLoadingHandler extends ChannelDuplexHandler { @Override public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { interceptedConnectPromise = promise; ChannelPromise downstream = ctx.newPromise(); downstream.addListener(f -> { if (!f.isSuccess() && !interceptedConnectPromise.isDone()) { ConnectTimings.record(ctx.channel(), this.getClass()); interceptedConnectPromise.tryFailure(f.cause()); } }); ctx.connect(remoteAddress, localAddress, downstream); } ErrorMapLoadingHandler(final EndpointContext endpointContext); @Override void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
                      final SocketAddress localAddress, final ChannelPromise promise); @Override void channelActive(final ChannelHandlerContext ctx); @Override void channelRead(final ChannelHandlerContext ctx, final Object msg); }
ErrorMapLoadingHandler extends ChannelDuplexHandler { @Override public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { interceptedConnectPromise = promise; ChannelPromise downstream = ctx.newPromise(); downstream.addListener(f -> { if (!f.isSuccess() && !interceptedConnectPromise.isDone()) { ConnectTimings.record(ctx.channel(), this.getClass()); interceptedConnectPromise.tryFailure(f.cause()); } }); ctx.connect(remoteAddress, localAddress, downstream); } ErrorMapLoadingHandler(final EndpointContext endpointContext); @Override void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
                      final SocketAddress localAddress, final ChannelPromise promise); @Override void channelActive(final ChannelHandlerContext ctx); @Override void channelRead(final ChannelHandlerContext ctx, final Object msg);  }