// Private -------------------------------------------------------
private void keepAliveFilterForIdleStatus(IdleStatus status)
throws Exception {
NioSocketConnector connector = new NioSocketConnector();
KeepAliveFilter filter = new KeepAliveFilter(new ClientFactory(),
status, EXCEPTION, INTERVAL, TIMEOUT);
filter.setForwardEvent(true);
connector.getFilterChain().addLast("keep-alive", filter);
final AtomicBoolean gotException = new AtomicBoolean(false);
connector.setHandler(new IoHandlerAdapter() {
@Override
public void exceptionCaught(IoSession session, Throwable cause)
throws Exception {
//cause.printStackTrace();
gotException.set(true);
}
@Override
public void sessionIdle(IoSession session, IdleStatus status)
throws Exception {
// Do nothing
}
});
ConnectFuture future = connector.connect(
new InetSocketAddress("127.0.0.1", port)).awaitUninterruptibly();
IoSession session = future.getSession();
assertNotNull(session);
Thread.sleep((INTERVAL + TIMEOUT + 1) * 1000);
assertFalse("got an exception on the client", gotException.get());
session.close(true);
connector.dispose();
}