use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class SmallThreadPoolLoadTest method test.
private boolean test(Session session, CountDownLatch latch) throws Exception {
ThreadLocalRandom random = ThreadLocalRandom.current();
// Choose a random method
boolean download = random.nextBoolean();
HttpMethod method = download ? HttpMethod.GET : HttpMethod.POST;
int maxContentLength = 128 * 1024;
int contentLength = random.nextInt(maxContentLength) + 1;
long requestId = requestIds.incrementAndGet();
MetaData.Request request = newRequest(method.asString(), "/" + requestId, new HttpFields());
if (download)
request.getFields().put("X-Download", String.valueOf(contentLength));
HeadersFrame requestFrame = new HeadersFrame(request, null, download);
FuturePromise<Stream> promise = new FuturePromise<>();
CountDownLatch requestLatch = new CountDownLatch(1);
AtomicBoolean reset = new AtomicBoolean();
session.newStream(requestFrame, promise, new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
if (frame.isEndStream())
requestLatch.countDown();
}
@Override
public void onData(Stream stream, DataFrame frame, Callback callback) {
callback.succeeded();
if (frame.isEndStream())
requestLatch.countDown();
}
@Override
public void onReset(Stream stream, ResetFrame frame) {
reset.set(true);
requestLatch.countDown();
}
});
if (!download) {
Stream stream = promise.get(5, TimeUnit.SECONDS);
stream.data(new DataFrame(stream.getId(), ByteBuffer.allocate(contentLength), true), Callback.NOOP);
}
boolean success = requestLatch.await(5, TimeUnit.SECONDS);
if (success)
latch.countDown();
else
logger.warn("Request {} took too long{}Server:{}{}{}Client:{}{}", requestId, System.lineSeparator(), System.lineSeparator(), server.dump(), System.lineSeparator(), System.lineSeparator(), client.dump());
return !reset.get();
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class IdleTimeoutTest method testStreamIdleTimeoutIsNotEnforcedWhenSending.
@Test
public void testStreamIdleTimeoutIsNotEnforcedWhenSending() throws Exception {
final CountDownLatch resetLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
return null;
}
@Override
public void onReset(Session session, ResetFrame frame) {
resetLatch.countDown();
}
});
Session session = newClient(new Session.Listener.Adapter());
MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(metaData, null, false);
FuturePromise<Stream> promise = new FuturePromise<Stream>() {
@Override
public void succeeded(Stream stream) {
stream.setIdleTimeout(idleTimeout);
super.succeeded(stream);
}
};
session.newStream(requestFrame, promise, new Stream.Listener.Adapter());
final Stream stream = promise.get(5, TimeUnit.SECONDS);
Callback.Completable completable1 = new Callback.Completable();
sleep(idleTimeout / 2);
stream.data(new DataFrame(stream.getId(), ByteBuffer.allocate(1), false), completable1);
completable1.thenCompose(nil -> {
Callback.Completable completable2 = new Callback.Completable();
sleep(idleTimeout / 2);
stream.data(new DataFrame(stream.getId(), ByteBuffer.allocate(1), false), completable2);
return completable2;
}).thenRun(() -> {
sleep(idleTimeout / 2);
stream.data(new DataFrame(stream.getId(), ByteBuffer.allocate(1), true), Callback.NOOP);
});
Assert.assertFalse(resetLatch.await(1, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class HTTP2Session method createRemoteStream.
protected IStream createRemoteStream(int streamId) {
// SPEC: exceeding max concurrent streams is treated as stream error.
while (true) {
int remoteCount = remoteStreamCount.get();
int maxCount = getMaxRemoteStreams();
if (maxCount >= 0 && remoteCount >= maxCount) {
reset(new ResetFrame(streamId, ErrorCode.REFUSED_STREAM_ERROR.code), Callback.NOOP);
return null;
}
if (remoteStreamCount.compareAndSet(remoteCount, remoteCount + 1))
break;
}
IStream stream = newStream(streamId, false);
// SPEC: duplicate stream is treated as connection error.
if (streams.putIfAbsent(streamId, stream) == null) {
updateLastStreamId(streamId);
stream.setIdleTimeout(getStreamIdleTimeout());
flowControl.onStreamCreated(stream);
if (LOG.isDebugEnabled())
LOG.debug("Created remote {}", stream);
return stream;
} else {
close(ErrorCode.PROTOCOL_ERROR.code, "duplicate_stream", Callback.NOOP);
return null;
}
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class ResetBodyParser method onReset.
private boolean onReset(int error) {
ResetFrame frame = new ResetFrame(getStreamId(), error);
reset();
notifyReset(frame);
return true;
}
use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.
the class IdleTimeoutTest method testServerEnforcingStreamIdleTimeout.
@Test
public void testServerEnforcingStreamIdleTimeout() throws Exception {
final CountDownLatch timeoutLatch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
stream.setIdleTimeout(idleTimeout);
return new Stream.Listener.Adapter() {
@Override
public boolean onIdleTimeout(Stream stream, Throwable x) {
timeoutLatch.countDown();
return true;
}
};
}
});
final CountDownLatch resetLatch = new CountDownLatch(1);
Session session = newClient(new Session.Listener.Adapter());
MetaData.Request metaData = newRequest("GET", new HttpFields());
// Stream does not end here, but we won't send any DATA frame.
HeadersFrame requestFrame = new HeadersFrame(metaData, null, false);
session.newStream(requestFrame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {
@Override
public void onReset(Stream stream, ResetFrame frame) {
resetLatch.countDown();
}
});
Assert.assertTrue(timeoutLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
// Stream must be gone.
Assert.assertTrue(session.getStreams().isEmpty());
// Session must not be closed, nor disconnected.
Assert.assertFalse(session.isClosed());
Assert.assertFalse(((HTTP2Session) session).isDisconnected());
}
Aggregations