IoBuffer dest = IoBuffer.allocate(1);
assertEquals(false, dest.isAutoExpand());
}
public void testBasicBuffering() {
DummySession sess = new DummySession();
sess.getFilterChain().addFirst("peer", new IoFilterAdapter() {
private int counter;
@Override
public void filterClose(NextFilter nextFilter, IoSession session)
throws Exception {
LOGGER.debug("Filter closed !");
assertEquals(3, counter);
}
@Override
public void filterWrite(NextFilter nextFilter, IoSession session,
WriteRequest writeRequest) throws Exception {
LOGGER.debug("New buffered message written !");
counter++;
try {
IoBuffer buf = (IoBuffer) writeRequest.getMessage();
if (counter == 3) {
assertEquals(1, buf.limit());
assertEquals(0, buf.get());
} else {
assertEquals(10, buf.limit());
}
} catch (Exception ex) {
throw new AssertionError("Wrong message type");
}
}
});
sess.getFilterChain().addFirst("logger", new LoggingFilter());
BufferedWriteFilter bFilter = new BufferedWriteFilter(10);
sess.getFilterChain().addLast("buffer", bFilter);
IoBuffer data = IoBuffer.allocate(1);
for (byte i = 0; i < 20; i++) {
data.put((byte) (0x30 + i));
data.flip();
sess.write(data);
data.clear();
}
// Add one more byte to overflow the final buffer
data.put((byte) 0);
data.flip();
sess.write(data);
// Flush the final byte
bFilter.flush(sess);
sess.close(true);
}