use of io.netty.handler.codec.http2.Http2Stream in project netty by netty.
the class DefaultHttp2ConnectionTest method removeAllStreamsWhileIteratingActiveStreams.
@Test
public void removeAllStreamsWhileIteratingActiveStreams() throws Exception {
final Endpoint<Http2RemoteFlowController> remote = client.remote();
final Endpoint<Http2LocalFlowController> local = client.local();
for (int c = 3, s = 2; c < 5000; c += 2, s += 2) {
local.createStream(c, false);
remote.createStream(s, false);
}
final Promise<Void> promise = group.next().newPromise();
final CountDownLatch latch = new CountDownLatch(client.numActiveStreams());
client.forEachActiveStream(new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) {
client.close(promise).addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
assertTrue(promise.isDone());
latch.countDown();
}
});
return true;
}
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of io.netty.handler.codec.http2.Http2Stream in project netty by netty.
the class DefaultHttp2ConnectionEncoderTest method canWriteDataFrameAfterGoAwaySent.
@Test
public void canWriteDataFrameAfterGoAwaySent() throws Exception {
Http2Stream stream = createStream(STREAM_ID, false);
connection.goAwaySent(0, 0, EMPTY_BUFFER);
ByteBuf data = mock(ByteBuf.class);
encoder.writeData(ctx, STREAM_ID, data, 0, false, newPromise());
verify(remoteFlow).addFlowControlled(eq(stream), any(FlowControlled.class));
}
use of io.netty.handler.codec.http2.Http2Stream in project netty by netty.
the class Http2ConnectionHandler method resetStream.
private ChannelFuture resetStream(final ChannelHandlerContext ctx, final Http2Stream stream, long errorCode, ChannelPromise promise) {
promise = promise.unvoid();
if (stream.isResetSent()) {
// Don't write a RST_STREAM frame if we have already written one.
return promise.setSuccess();
}
// Synchronously set the resetSent flag to prevent any subsequent calls
// from resulting in multiple reset frames being sent.
//
// This needs to be done before we notify the promise as the promise may have a listener attached that
// call resetStream(...) again.
stream.resetSent();
final ChannelFuture future;
// https://tools.ietf.org/html/rfc7540#section-6.4.
if (stream.state() == IDLE || connection().local().created(stream) && !stream.isHeadersSent() && !stream.isPushPromiseSent()) {
future = promise.setSuccess();
} else {
future = frameWriter().writeRstStream(ctx, stream.id(), errorCode, promise);
}
if (future.isDone()) {
processRstStreamWriteResult(ctx, stream, future);
} else {
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
processRstStreamWriteResult(ctx, stream, future);
}
});
}
return future;
}
use of io.netty.handler.codec.http2.Http2Stream in project netty by netty.
the class UniformStreamByteDistributorTest method initState.
private void initState(final int streamId, final long pendingBytes, final boolean hasFrame, final boolean isWriteAllowed) {
final Http2Stream stream = stream(streamId);
TestStreamByteDistributorStreamState state = new TestStreamByteDistributorStreamState(stream, pendingBytes, hasFrame, isWriteAllowed);
stateMap.put(streamId, state);
distributor.updateStreamableBytes(state);
}
use of io.netty.handler.codec.http2.Http2Stream in project netty by netty.
the class UniformStreamByteDistributorTest method writeAnswer.
private Answer<Void> writeAnswer() {
return new Answer<Void>() {
@Override
public Void answer(InvocationOnMock in) throws Throwable {
Http2Stream stream = in.getArgument(0);
int numBytes = in.getArgument(1);
TestStreamByteDistributorStreamState state = stateMap.get(stream.id());
state.pendingBytes -= numBytes;
state.hasFrame = state.pendingBytes > 0;
distributor.updateStreamableBytes(state);
return null;
}
};
}
Aggregations