use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class TestABCase4 method testParserControlOpCode11Case4_2_1.
@Test
public void testParserControlOpCode11Case4_2_1() throws Exception {
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x8b, 0x00 });
expected.flip();
IncomingFramesCapture capture = new IncomingFramesCapture();
try (StacklessLogging logging = new StacklessLogging(Parser.class)) {
Parser parser = new UnitParser(policy);
parser.setIncomingFramesHandler(capture);
try {
parser.parse(expected);
} catch (ProtocolException ignore) {
// ignore
}
}
Assert.assertEquals("error on undefined opcode", 1, capture.getErrorCount(WebSocketException.class));
Throwable known = capture.getErrors().poll();
Assert.assertTrue("undefined option should be in message", known.getMessage().contains("Unknown opcode: 11"));
}
use of org.eclipse.jetty.util.log.StacklessLogging 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 org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class ServerTimeoutsTest method testBlockingReadHttpIdleTimeoutOverridesIdleTimeout.
@Test
public void testBlockingReadHttpIdleTimeoutOverridesIdleTimeout() throws Exception {
long httpIdleTimeout = 2500;
long idleTimeout = 3 * httpIdleTimeout;
httpConfig.setIdleTimeout(httpIdleTimeout);
CountDownLatch handlerLatch = new CountDownLatch(1);
start(new BlockingReadHandler(handlerLatch));
setServerIdleTimeout(idleTimeout);
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
DeferredContentProvider contentProvider = new DeferredContentProvider(ByteBuffer.allocate(1));
CountDownLatch resultLatch = new CountDownLatch(1);
client.POST(newURI()).content(contentProvider).send(result -> {
if (result.getResponse().getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500)
resultLatch.countDown();
});
// Blocking read should timeout.
Assert.assertTrue(handlerLatch.await(2 * httpIdleTimeout, TimeUnit.MILLISECONDS));
// Complete the request.
contentProvider.close();
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class ServerTimeoutsTest method testBlockingTimeoutWithSlowRead.
@Test
public void testBlockingTimeoutWithSlowRead() throws Exception {
long idleTimeout = 2500;
long blockingTimeout = 2 * idleTimeout;
httpConfig.setBlockingTimeout(blockingTimeout);
CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
baseRequest.setHandled(true);
ServletInputStream input = request.getInputStream();
while (true) {
int read = input.read();
if (read < 0)
break;
}
} catch (IOException x) {
handlerLatch.countDown();
throw x;
}
}
});
setServerIdleTimeout(idleTimeout);
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
DeferredContentProvider contentProvider = new DeferredContentProvider();
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI()).content(contentProvider).send(result -> {
if (result.getResponse().getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500)
resultLatch.countDown();
});
// The writes should be slow but not trigger the idle timeout.
long period = idleTimeout / 2;
long writes = 2 * (blockingTimeout / period);
for (long i = 0; i < writes; ++i) {
contentProvider.offer(ByteBuffer.allocate(1));
Thread.sleep(period);
}
contentProvider.close();
// Blocking read should timeout.
Assert.assertTrue(handlerLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
}
use of org.eclipse.jetty.util.log.StacklessLogging 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));
}
}
Aggregations