* @author The Apache MINA Project Team (dev@mina.apache.org)
* @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
*/
public class VmPipeEventOrderTest extends TestCase {
public void testServerToClient() throws Exception {
IoAcceptor acceptor = new VmPipeAcceptor();
acceptor.getDefaultConfig().setThreadModel(ThreadModel.MANUAL);
//acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
IoConnector connector = new VmPipeConnector();
connector.getDefaultConfig().setThreadModel(ThreadModel.MANUAL);
//connector.getFilterChain().addLast( "logger", new LoggingFilter() );
acceptor.bind(new VmPipeAddress(1), new IoHandlerAdapter() {
public void sessionOpened(IoSession session) throws Exception {
session.write("B");
}
public void messageSent(IoSession session, Object message)
throws Exception {
session.close();
}
});
final StringBuffer actual = new StringBuffer();
ConnectFuture future = connector.connect(new VmPipeAddress(1),
new IoHandlerAdapter() {
public void messageReceived(IoSession session,
Object message) throws Exception {
actual.append(message);
}
public void sessionClosed(IoSession session)
throws Exception {
actual.append("C");
}
public void sessionOpened(IoSession session)
throws Exception {
actual.append("A");
}
});
future.join();
future.getSession().getCloseFuture().join();
acceptor.unbindAll();
// sessionClosed() might not be invoked yet
// even if the connection is closed.
while (actual.indexOf("C") < 0) {
Thread.yield();