Search in sources :

Example 51 with Http2Stream

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));
}
Also used : FutureListener(io.netty.util.concurrent.FutureListener) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint) Future(io.netty.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 52 with Http2Stream

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));
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) FlowControlled(io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled) Test(org.junit.jupiter.api.Test)

Example 53 with Http2Stream

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;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelFutureListener(io.netty.channel.ChannelFutureListener) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) CompositeStreamException(io.netty.handler.codec.http2.Http2Exception.CompositeStreamException)

Example 54 with Http2Stream

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);
}
Also used : TestStreamByteDistributorStreamState(io.netty.handler.codec.http2.Http2TestUtil.TestStreamByteDistributorStreamState)

Example 55 with Http2Stream

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;
        }
    };
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestStreamByteDistributorStreamState(io.netty.handler.codec.http2.Http2TestUtil.TestStreamByteDistributorStreamState)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)44 Http2Exception (io.netty.handler.codec.http2.Http2Exception)15 ByteBuf (io.netty.buffer.ByteBuf)12 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)9 Http2Connection (io.netty.handler.codec.http2.Http2Connection)8 ChannelFuture (io.netty.channel.ChannelFuture)7 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Metadata (io.grpc.Metadata)6 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)6 Status (io.grpc.Status)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)5 Channel (io.netty.channel.Channel)4 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)4 Http2Headers (io.netty.handler.codec.http2.Http2Headers)4 AsyncResult (io.vertx.core.AsyncResult)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Bootstrap (io.netty.bootstrap.Bootstrap)3