use of java.util.concurrent.BlockingQueue in project jetty.project by eclipse.
the class ServerTimeoutsTest method testBlockingTimeoutSmallerThanIdleTimeoutBlockingWriteBlockingTimeoutFires.
@Test
public void testBlockingTimeoutSmallerThanIdleTimeoutBlockingWriteBlockingTimeoutFires() throws Exception {
long blockingTimeout = 2500;
httpConfig.setBlockingTimeout(blockingTimeout);
CountDownLatch handlerLatch = new CountDownLatch(1);
start(new BlockingWriteHandler(handlerLatch));
long idleTimeout = 3 * blockingTimeout;
setServerIdleTimeout(idleTimeout);
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
BlockingQueue<Callback> callbacks = new LinkedBlockingQueue<>();
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI()).onResponseContentAsync((response, content, callback) -> {
// Do not succeed the callback so the server will block writing.
callbacks.offer(callback);
}).send(result -> {
if (result.isFailed())
resultLatch.countDown();
});
// Blocking write should timeout.
Assert.assertTrue(handlerLatch.await(2 * blockingTimeout, TimeUnit.MILLISECONDS));
// After the server stopped sending, consume on the client to read the early EOF.
while (true) {
Callback callback = callbacks.poll(1, TimeUnit.SECONDS);
if (callback == null)
break;
callback.succeeded();
}
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
}
use of java.util.concurrent.BlockingQueue in project jetty.project by eclipse.
the class ServerTimeoutsTest method testAsyncWriteIdleTimeoutFires.
@Test
public void testAsyncWriteIdleTimeoutFires() throws Exception {
CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(0);
ServletOutputStream output = response.getOutputStream();
output.setWriteListener(new WriteListener() {
@Override
public void onWritePossible() throws IOException {
output.write(new byte[64 * 1024 * 1024]);
}
@Override
public void onError(Throwable failure) {
if (failure instanceof TimeoutException) {
asyncContext.complete();
handlerLatch.countDown();
}
}
});
}
});
long idleTimeout = 2500;
setServerIdleTimeout(idleTimeout);
BlockingQueue<Callback> callbacks = new LinkedBlockingQueue<>();
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI()).onResponseContentAsync((response, content, callback) -> {
// Do not succeed the callback so the server will block writing.
callbacks.offer(callback);
}).send(result -> {
if (result.isFailed())
resultLatch.countDown();
});
// Async write should timeout.
Assert.assertTrue(handlerLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
// After the server stopped sending, consume on the client to read the early EOF.
while (true) {
Callback callback = callbacks.poll(1, TimeUnit.SECONDS);
if (callback == null)
break;
callback.succeeded();
}
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
use of java.util.concurrent.BlockingQueue in project jetty.project by eclipse.
the class ServerTimeoutsTest method testBlockingTimeoutLargerThanIdleTimeoutBlockingWriteIdleTimeoutFires.
@Test
public void testBlockingTimeoutLargerThanIdleTimeoutBlockingWriteIdleTimeoutFires() throws Exception {
long idleTimeout = 2500;
long blockingTimeout = 3 * idleTimeout;
httpConfig.setBlockingTimeout(blockingTimeout);
CountDownLatch handlerLatch = new CountDownLatch(1);
start(new BlockingWriteHandler(handlerLatch));
setServerIdleTimeout(idleTimeout);
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
BlockingQueue<Callback> callbacks = new LinkedBlockingQueue<>();
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI()).onResponseContentAsync((response, content, callback) -> {
// Do not succeed the callback so the server will block writing.
callbacks.offer(callback);
}).send(result -> {
if (result.isFailed())
resultLatch.countDown();
});
// Blocking read should timeout.
Assert.assertTrue(handlerLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
// After the server stopped sending, consume on the client to read the early EOF.
while (true) {
Callback callback = callbacks.poll(1, TimeUnit.SECONDS);
if (callback == null)
break;
callback.succeeded();
}
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
}
use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.
the class BlockingQueueTest method testDrainToNullN.
/**
* drainTo(null, n) throws NullPointerException
*/
public void testDrainToNullN() {
final BlockingQueue q = emptyCollection();
try {
q.drainTo(null, 0);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.
the class BlockingQueueTest method testDrainToNull.
/**
* drainTo(null) throws NullPointerException
*/
public void testDrainToNull() {
final BlockingQueue q = emptyCollection();
try {
q.drainTo(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
Aggregations