public void testSessionCreated() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final StringBuffer stringBuffer = new StringBuffer();
VmPipeAcceptor vmPipeAcceptor = new VmPipeAcceptor();
final VmPipeAddress vmPipeAddress = new VmPipeAddress(12345);
vmPipeAcceptor.setHandler(new IoHandlerAdapter() {
@Override
public void sessionCreated(IoSession session) throws Exception {
// pretend we are doing some time-consuming work. For
// performance reasons, you would never want to do time
// consuming work in sessionCreated.
// However, this increases the likelihood of the timing bug.
Thread.sleep(1000);
stringBuffer.append("A");
}
@Override
public void sessionOpened(IoSession session) throws Exception {
stringBuffer.append("B");
}
@Override
public void messageReceived(IoSession session, Object message)
throws Exception {
stringBuffer.append("C");
}
@Override
public void sessionClosed(IoSession session) throws Exception {
stringBuffer.append("D");
semaphore.release();
}
});
vmPipeAcceptor.bind(vmPipeAddress);
final VmPipeConnector vmPipeConnector = new VmPipeConnector();
vmPipeConnector.getFilterChain().addLast("executor", new ExecutorFilter());
vmPipeConnector.setHandler(new IoHandlerAdapter());
ConnectFuture connectFuture = vmPipeConnector.connect(vmPipeAddress);
connectFuture.awaitUninterruptibly();
connectFuture.getSession().write(IoBuffer.wrap(new byte[1])).awaitUninterruptibly();
connectFuture.getSession().close(false).awaitUninterruptibly();