Details
Description
The following unit test method fails because sessionOpened can be called before sessionCreated.
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
@Override
public void sessionOpened(IoSession session) throws Exception
@Override
public void messageReceived(IoSession session, Object message)
throws Exception
@Override
public void sessionClosed(IoSession session) throws Exception
});
vmPipeAcceptor.bind(vmPipeAddress);
final VmPipeConnector vmPipeConnector = new VmPipeConnector();
vmPipeConnector.getFilterChain().addLast("executor", new ExecutorFilter());
vmPipeConnector.setHandler(new IoHandlerAdapter() {
@Override
public void sessionOpened(IoSession session) throws Exception
});
ConnectFuture connectFuture = vmPipeConnector.connect(vmPipeAddress).awaitUninterruptibly();
Thread.sleep(3000);
connectFuture.getSession().close();
semaphore.tryAcquire(1, TimeUnit.SECONDS);
vmPipeAcceptor.unbind(vmPipeAddress);
Assert.assertEquals("ABCD", stringBuffer.toString());
}