DefaultBackendSession extends AbstractSession implements BackendSession { protected void onChannelEstablished(Channel channel) { setChannel(channel); if(endpoint.isProxyProtocolSupported()) { getChannel().writeAndFlush(tunnel().getProxyProtocol().output()); } ProxyConfig config = resourceManager.getProxyConfig(); if(config.isCompressEnabled()) { logger.info("Backend compress codec installed: {}", ChannelUtil.getDesc(channel)); channel.pipeline().addBefore(BACKEND_SESSION_HANDLER, BACKEND_COMPRESS_DECODER, config.getCompressDecoder()); channel.pipeline().addBefore(BACKEND_SESSION_HANDLER, BACKEND_COMPRESS_ENCODER, config.getCompressEncoder()); } if(sendAfterProtocol != null) { while(!sendAfterProtocol.isEmpty()) { getChannel().writeAndFlush(sendAfterProtocol.poll()); } sendAfterProtocol = null; } setSessionState(new SessionEstablished(DefaultBackendSession.this)); onSessionEstablished(); } DefaultBackendSession(Tunnel tunnel, EventLoopGroup eventLoopGroup, long trafficReportIntervalMillis,
                                 ResourceManager resourceManager); @Override void sendAfterProtocol(ByteBuf byteBuf); @Override SESSION_TYPE getSessionType(); SessionState getSessionState(); @Override SessionMonitor getSessionMonitor();  }
@Test public void onChannelEstablished() { EmbeddedChannel channel = new EmbeddedChannel(); session.endpoint = new DefaultProxyEndpoint("TCP: SessionEventHandler handler = mock(SessionEventHandler.class); session.addSessionEventHandler(handler); session.onChannelEstablished(channel); verify(handler).onEstablished(); }