use of io.netty.channel.socket.oio.OioSocketChannel in project netty by netty.
the class SocketShutdownOutputBySelfTest method testWriteAfterShutdownOutputNoWritabilityChange.
public void testWriteAfterShutdownOutputNoWritabilityChange(Bootstrap cb) throws Throwable {
final TestHandler h = new TestHandler();
ServerSocket ss = new ServerSocket();
Socket s = null;
SocketChannel ch = null;
try {
ss.bind(newSocketAddress());
cb.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(2, 4));
ch = (SocketChannel) cb.handler(h).connect(ss.getLocalSocketAddress()).sync().channel();
assumeFalse(ch instanceof OioSocketChannel);
assertTrue(ch.isActive());
assertFalse(ch.isOutputShutdown());
s = ss.accept();
byte[] expectedBytes = new byte[] { 1, 2, 3, 4, 5, 6 };
ChannelFuture writeFuture = ch.write(Unpooled.wrappedBuffer(expectedBytes));
h.assertWritability(false);
ch.flush();
writeFuture.sync();
h.assertWritability(true);
for (int i = 0; i < expectedBytes.length; ++i) {
assertEquals(expectedBytes[i], s.getInputStream().read());
}
assertTrue(h.ch.isOpen());
assertTrue(h.ch.isActive());
assertFalse(h.ch.isInputShutdown());
assertFalse(h.ch.isOutputShutdown());
// Make the connection half-closed and ensure read() returns -1.
ch.shutdownOutput().sync();
assertEquals(-1, s.getInputStream().read());
assertTrue(h.ch.isOpen());
assertTrue(h.ch.isActive());
assertFalse(h.ch.isInputShutdown());
assertTrue(h.ch.isOutputShutdown());
try {
// If half-closed, the local endpoint shouldn't be able to write
ch.writeAndFlush(Unpooled.wrappedBuffer(new byte[] { 2 })).sync();
fail();
} catch (Throwable cause) {
checkThrowable(cause);
}
assertNull(h.writabilityQueue.poll());
} finally {
if (s != null) {
s.close();
}
if (ch != null) {
ch.close();
}
ss.close();
}
}
Aggregations