@Ignore
@Test
public void testExceptionOnWrite() throws Exception {
final Executor ex = Executors.newFixedThreadPool(1);
IoConnector connector = new NioSocketConnector(
new AbstractPollingIoProcessor<NioSession>(ex) {
private NioProcessor proc = new NioProcessor(ex);
@Override
protected Iterator<NioSession> allSessions() {
return proc.allSessions();
}
@Override
protected void destroy(NioSession session) throws Exception {
proc.destroy(session);
}
@Override
protected void dispose0() throws Exception {
proc.dispose0();
}
@Override
protected void init(NioSession session) throws Exception {
proc.init(session);
}
@Override
protected boolean isInterestedInRead(NioSession session) {
return proc.isInterestedInRead(session);
}
@Override
protected boolean isInterestedInWrite(NioSession session) {
return proc.isInterestedInWrite(session);
}
@Override
protected boolean isReadable(NioSession session) {
return proc.isReadable(session);
}
@Override
protected boolean isSelectorEmpty() {
return proc.isSelectorEmpty();
}
@Override
protected boolean isWritable(NioSession session) {
return proc.isWritable(session);
}
@Override
protected int read(NioSession session, IoBuffer buf)
throws Exception {
return proc.read(session, buf);
}
@Override
protected int select(long timeout) throws Exception {
return proc.select(timeout);
}
@Override
protected int select() throws Exception {
return proc.select();
}
@Override
protected Iterator<NioSession> selectedSessions() {
return proc.selectedSessions();
}
@Override
protected void setInterestedInRead(NioSession session,
boolean interested) throws Exception {
proc.setInterestedInRead(session, interested);
}
@Override
protected void setInterestedInWrite(NioSession session,
boolean interested) throws Exception {
proc.setInterestedInWrite(session, interested);
}
@Override
protected SessionState getState(NioSession session) {
return proc.getState(session);
}
@Override
protected int transferFile(NioSession session,
FileRegion region, int length) throws Exception {
return proc.transferFile(session, region, length);
}
@Override
protected void wakeup() {
proc.wakeup();
}
@Override
protected int write(NioSession session, IoBuffer buf,
int length) throws Exception {
throw new NoRouteToHostException(
"No Route To Host Test");
}
@Override
protected boolean isBrokenConnection() throws IOException {
return proc.isBrokenConnection();
}
@Override
protected void registerNewSelector() throws IOException {
proc.registerNewSelector();
}
});
connector.setHandler(new IoHandlerAdapter());
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.setHandler(new IoHandlerAdapter());
InetSocketAddress addr = new InetSocketAddress("localhost",
AvailablePortFinder.getNextAvailable(20000));
acceptor.bind(addr);
ConnectFuture future = connector.connect(addr);
future.awaitUninterruptibly();
IoSession session = future.getSession();
WriteFuture wf = session.write(IoBuffer.allocate(1))
.awaitUninterruptibly();
assertNotNull(wf.getException());
connector.dispose();
acceptor.dispose();
}