public void testReadTimeout() throws IOException, InterruptedException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final StreamSinkChannel response = exchange.getResponseChannel();
final StreamSourceChannel request = exchange.getRequestChannel();
try {
request.setOption(Options.READ_TIMEOUT, 100);
} catch (IOException e) {
throw new RuntimeException(e);
}
request.getReadSetter().set(ChannelListeners.drainListener(Long.MAX_VALUE, new ChannelListener<Channel>() {
@Override
public void handleEvent(final Channel channel) {
new StringWriteChannelListener("COMPLETED") {
@Override
protected void writeDone(final StreamSinkChannel channel) {
exchange.endExchange();
}
}.setup(response);
}
}, new ChannelExceptionHandler<StreamSourceChannel>() {
@Override
public void handleException(final StreamSourceChannel channel, final IOException e) {
exchange.endExchange();
exception = e;
errorLatch.countDown();
}
}
));
request.wakeupReads();
}
});
final TestHttpClient client = new TestHttpClient();