Search in sources :

Example 36 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.Test)

Example 37 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 InterruptedException, Http2Exception {
    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.Test)

Example 38 with Http2Stream

use of io.netty.handler.codec.http2.Http2Stream in project netty by netty.

the class Http2FrameCodecTest method streamErrorShouldFireUserEvent.

@Test
public void streamErrorShouldFireUserEvent() throws Exception {
    frameListener.onHeadersRead(http2HandlerCtx, 3, request, 31, false);
    Http2Stream stream = framingCodec.connectionHandler().connection().stream(3);
    assertNotNull(stream);
    Http2StreamActiveEvent activeEvent = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(activeEvent);
    assertEquals(stream.id(), activeEvent.streamId());
    StreamException streamEx = new StreamException(3, Http2Error.INTERNAL_ERROR, "foo");
    framingCodec.connectionHandler().onError(http2HandlerCtx, streamEx);
    Http2HeadersFrame headersFrame = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(headersFrame);
    try {
        inboundHandler.checkException();
        fail("stream exception expected");
    } catch (StreamException e) {
        assertEquals(streamEx, e);
    }
    Http2StreamClosedEvent closedEvent = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(closedEvent);
    assertEquals(stream.id(), closedEvent.streamId());
    assertNull(inboundHandler.readInboundMessageOrUserEvent());
}
Also used : StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.Test)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)21 Test (org.junit.Test)16 Http2Exception (io.netty.handler.codec.http2.Http2Exception)9 ByteBuf (io.netty.buffer.ByteBuf)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)5 Metadata (io.grpc.Metadata)4 ChannelFuture (io.netty.channel.ChannelFuture)4 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)4 Endpoint (io.netty.handler.codec.http2.Http2Connection.Endpoint)3 FlowControlled (io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled)3 HttpFields (org.eclipse.jetty.http.HttpFields)3 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)3 HTTP2Stream (org.eclipse.jetty.http2.HTTP2Stream)3 Session (org.eclipse.jetty.http2.api.Session)3 Stream (org.eclipse.jetty.http2.api.Stream)3 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)3 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)3 FuturePromise (org.eclipse.jetty.util.FuturePromise)3 Status (io.grpc.Status)2