Socks5AcceptorHandler extends IoHandlerAdapter { public void exceptionCaught(IoSession session, Throwable cause) throws Exception { log.error("Exception caused in SOCKS5 proxy, probably a bug in Vysper", cause); Socks5Pair pair = getPair(session); if(pair != null) { pair.close(); } else { session.close(false); } } Socks5AcceptorHandler(Socks5ConnectionsRegistry connections); void sessionOpened(IoSession session); void sessionIdle(IoSession session, IdleStatus status); void messageReceived(final IoSession session, Object message); void sessionClosed(IoSession session); void exceptionCaught(IoSession session, Throwable cause); static final AttributeKey STATE_KEY; static final AttributeKey PAIR_KEY; }
@Test public void exceptionCaughtPairEstablished() throws Exception { IoSession other = mock(IoSession.class); Socks5Pair pair = new Socks5Pair(session, connectionsRegistry, "foo"); pair.setRequester(other); when(session.getAttribute(Socks5AcceptorHandler.PAIR_KEY)).thenReturn(pair); handler.exceptionCaught(session, new Exception()); verify(session).close(false); verify(other).close(false); }
@Test public void exceptionCaughtPairNotEstablished() throws Exception { handler.exceptionCaught(session, new Exception()); verify(session).close(false); }