use of java.io.InterruptedIOException in project jetty.project by eclipse.
the class ClientConnectionCloseTest method test_ClientConnectionClose_ServerNoConnectionClose_ClientCloses.
@Test
public void test_ClientConnectionClose_ServerNoConnectionClose_ClientCloses() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
response.setContentLength(0);
response.flushBuffer();
try {
// Delay the server from sending the TCP FIN.
Thread.sleep(1000);
} catch (InterruptedException x) {
throw new InterruptedIOException();
}
}
});
String host = "localhost";
int port = connector.getLocalPort();
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP) client.getDestination(scheme, host, port);
DuplexConnectionPool connectionPool = (DuplexConnectionPool) destination.getConnectionPool();
ContentResponse response = client.newRequest(host, port).scheme(scheme).header(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString()).onRequestSuccess(request -> {
HttpConnectionOverHTTP connection = (HttpConnectionOverHTTP) connectionPool.getActiveConnections().iterator().next();
Assert.assertFalse(connection.getEndPoint().isOutputShutdown());
}).onResponseHeaders(r -> r.getHeaders().remove(HttpHeader.CONNECTION)).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
Assert.assertEquals(0, connectionPool.getConnectionCount());
}
use of java.io.InterruptedIOException in project jetty.project by eclipse.
the class StreamResetTest method testServerExceptionConsumesQueuedData.
@Test
public void testServerExceptionConsumesQueuedData() throws Exception {
try (StacklessLogging suppressor = new StacklessLogging(HttpChannel.class)) {
start(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
// Wait to let the data sent by the client to be queued.
Thread.sleep(1000);
throw new IllegalStateException("explictly_thrown_by_test");
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}
});
Session client = newClient(new Session.Listener.Adapter());
Log.getLogger(HttpChannel.class).info("Expecting java.lang.IllegalStateException: explictly_thrown_by_test");
MetaData.Request request = newRequest("GET", new HttpFields());
HeadersFrame frame = new HeadersFrame(request, null, false);
FuturePromise<Stream> promise = new FuturePromise<>();
client.newStream(frame, promise, new Stream.Listener.Adapter());
Stream stream = promise.get(5, TimeUnit.SECONDS);
ByteBuffer data = ByteBuffer.allocate(FlowControlStrategy.DEFAULT_WINDOW_SIZE);
CountDownLatch dataLatch = new CountDownLatch(1);
stream.data(new DataFrame(stream.getId(), data, false), new Callback() {
@Override
public void succeeded() {
dataLatch.countDown();
}
});
// The server does not read the data, so the flow control window should be zero.
Assert.assertTrue(dataLatch.await(5, TimeUnit.SECONDS));
Assert.assertEquals(0, ((ISession) client).updateSendWindow(0));
// Wait for the server process the exception, and
// for the client to process the window updates.
Thread.sleep(2000);
Assert.assertThat(((ISession) client).updateSendWindow(0), Matchers.greaterThan(0));
}
}
use of java.io.InterruptedIOException in project jetty.project by eclipse.
the class StreamResetTest method testBlockingWriteAfterStreamReceivingReset.
@Test
public void testBlockingWriteAfterStreamReceivingReset() throws Exception {
final CountDownLatch resetLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1);
start(new HttpServlet() {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Charset charset = StandardCharsets.UTF_8;
byte[] data = "AFTER RESET".getBytes(charset);
response.setStatus(200);
response.setContentType("text/plain;charset=" + charset.name());
response.setContentLength(data.length * 10);
response.flushBuffer();
try {
// Wait for the reset to happen.
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
} catch (InterruptedException x) {
throw new InterruptedIOException();
}
try {
// been reset, it should throw an exception.
for (int i = 0; i < 10; i++) {
Thread.sleep(500);
response.getOutputStream().write(data);
response.flushBuffer();
}
} catch (InterruptedException x) {
} catch (IOException x) {
dataLatch.countDown();
}
}
});
Session client = newClient(new Session.Listener.Adapter());
MetaData.Request request = newRequest("GET", new HttpFields());
HeadersFrame frame = new HeadersFrame(request, null, true);
client.newStream(frame, new FuturePromise<>(), new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
stream.reset(new ResetFrame(stream.getId(), ErrorCode.CANCEL_STREAM_ERROR.code), Callback.NOOP);
resetLatch.countDown();
}
});
Assert.assertTrue(dataLatch.await(5, TimeUnit.SECONDS));
}
use of java.io.InterruptedIOException in project jetty.project by eclipse.
the class SharedBlockingCallback method acquire.
public Blocker acquire() throws IOException {
long idle = getIdleTimeout();
_lock.lock();
try {
while (_blocker._state != IDLE) {
if (idle > 0 && (idle < Long.MAX_VALUE / 2)) {
// Wait a little bit longer than the blocker might block
if (!_idle.await(idle * 2, TimeUnit.MILLISECONDS))
throw new IOException(new TimeoutException());
} else
_idle.await();
}
_blocker._state = null;
return _blocker;
} catch (InterruptedException x) {
throw new InterruptedIOException();
} finally {
_lock.unlock();
}
}
use of java.io.InterruptedIOException in project jetty.project by eclipse.
the class HttpClientStreamTest method testDownloadWithCloseBeforeContent.
@Test(expected = AsynchronousCloseException.class)
public void testDownloadWithCloseBeforeContent() throws Exception {
final byte[] data = new byte[128 * 1024];
byte value = 3;
Arrays.fill(data, value);
final CountDownLatch latch = new CountDownLatch(1);
start(new AbstractHandler() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
response.flushBuffer();
try {
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
response.getOutputStream().write(data);
}
});
InputStreamResponseListener listener = new InputStreamResponseListener();
client.newRequest("localhost", connector.getLocalPort()).scheme(getScheme()).send(listener);
Response response = listener.get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
InputStream input = listener.getInputStream();
Assert.assertNotNull(input);
input.close();
latch.countDown();
// Throws
input.read();
}
Aggregations