Socks5AcceptorHandler extends IoHandlerAdapter { public void sessionIdle(IoSession session, IdleStatus status) throws Exception { log.info("SOCKS5 connection idle, will be closed"); Socks5Pair pair = getPair(session); if (pair != null) { pair.close(); } } 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 sessionIdle() throws Exception { IoSession other = mock(IoSession.class); String hash = "foo"; Socks5Pair pair = new Socks5Pair(session, connectionsRegistry, hash); pair.setRequester(other); when(session.getAttribute(Socks5AcceptorHandler.PAIR_KEY)).thenReturn(pair); handler.sessionIdle(session, IdleStatus.READER_IDLE); verify(session).close(false); verify(other).close(false); }