use of org.eclipse.jetty.http2.frames.ResetFrame 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 org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class StreamResetTest method testStreamReceivingResetIsRemoved.
@Test
public void testStreamReceivingResetIsRemoved() throws Exception {
final AtomicReference<Stream> streamRef = new AtomicReference<>();
final CountDownLatch resetLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
return new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
Assert.assertNotNull(stream);
Assert.assertTrue(stream.isReset());
streamRef.set(stream);
resetLatch.countDown();
}
};
}
});
Session client = newClient(new Session.Listener.Adapter());
MetaData.Request request = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(request, null, false);
FuturePromise<Stream> promise = new FuturePromise<>();
client.newStream(requestFrame, promise, new Stream.Listener.Adapter());
Stream stream = promise.get(5, TimeUnit.SECONDS);
ResetFrame resetFrame = new ResetFrame(stream.getId(), ErrorCode.CANCEL_STREAM_ERROR.code);
stream.reset(resetFrame, Callback.NOOP);
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
// Wait a while to let the server remove the
// stream after returning from onReset().
Thread.sleep(1000);
Stream serverStream = streamRef.get();
Assert.assertEquals(0, serverStream.getSession().getStreams().size());
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testRequestIdleTimeoutSendsResetFrame.
@Test
public void testRequestIdleTimeoutSendsResetFrame() throws Exception {
CountDownLatch resetLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
return new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
resetLatch.countDown();
}
};
}
});
try {
long idleTimeout = 1000;
client.newRequest("localhost", connector.getLocalPort()).idleTimeout(idleTimeout, TimeUnit.MILLISECONDS).send();
Assert.fail();
} catch (ExecutionException e) {
// Expected.
}
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testResponseAbortSendsResetFrame.
@Test
public void testResponseAbortSendsResetFrame() throws Exception {
CountDownLatch resetLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), metaData, null, false), new Callback() {
@Override
public void succeeded() {
ByteBuffer data = ByteBuffer.allocate(1024);
stream.data(new DataFrame(stream.getId(), data, false), NOOP);
}
});
return new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
resetLatch.countDown();
}
};
}
});
try {
client.newRequest("localhost", connector.getLocalPort()).onResponseContent((response, buffer) -> response.abort(new Exception("explicitly_aborted_by_test"))).send();
Assert.fail();
} catch (ExecutionException x) {
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
}
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class PushedResourcesTest method testPushedResourceCancelled.
@Test
public void testPushedResourceCancelled() throws Exception {
String pushPath = "/secondary";
CountDownLatch latch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
HttpURI pushURI = new HttpURI("http://localhost:" + connector.getLocalPort() + pushPath);
MetaData.Request pushRequest = new MetaData.Request(HttpMethod.GET.asString(), pushURI, HttpVersion.HTTP_2, new HttpFields());
stream.push(new PushPromiseFrame(stream.getId(), 0, pushRequest), new Promise.Adapter<Stream>() {
@Override
public void succeeded(Stream pushStream) {
// Just send the normal response and wait for the reset.
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
}
}, new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
latch.countDown();
}
});
return null;
}
});
HttpRequest request = (HttpRequest) client.newRequest("localhost", connector.getLocalPort());
ContentResponse response = request.pushListener((mainRequest, pushedRequest) -> null).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Aggregations