Search in sources :

Example 1 with Http2FrameStream

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

the class Http2FrameCodecTest method streamIdentifiersExhausted.

@Test
public void streamIdentifiersExhausted() throws Http2Exception {
    int maxServerStreamId = Integer.MAX_VALUE - 1;
    assertNotNull(frameCodec.connection().local().createStream(maxServerStreamId, false));
    Http2FrameStream stream = frameCodec.newStream();
    assertNotNull(stream);
    ChannelPromise writePromise = channel.newPromise();
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream), writePromise);
    Http2GoAwayFrame goAwayFrame = inboundHandler.readInbound();
    assertNotNull(goAwayFrame);
    assertEquals(NO_ERROR.code(), goAwayFrame.errorCode());
    assertEquals(Integer.MAX_VALUE, goAwayFrame.lastStreamId());
    goAwayFrame.release();
    assertThat(writePromise.cause(), instanceOf(Http2NoMoreStreamIdsException.class));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) Http2TestUtil.anyChannelPromise(io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise) Test(org.junit.jupiter.api.Test)

Example 2 with Http2FrameStream

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

the class Http2FrameCodecTest method newOutboundStream.

@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void newOutboundStream() {
    final Http2FrameStream stream = frameCodec.newStream();
    assertNotNull(stream);
    assertFalse(isStreamIdValid(stream.id()));
    final Promise<Void> listenerExecuted = new DefaultPromise<Void>(GlobalEventExecutor.INSTANCE);
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers(), false).stream(stream)).addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            assertTrue(future.isSuccess());
            assertTrue(isStreamIdValid(stream.id()));
            listenerExecuted.setSuccess(null);
        }
    });
    ByteBuf data = Unpooled.buffer().writeZero(100);
    ChannelFuture f = channel.writeAndFlush(new DefaultHttp2DataFrame(data).stream(stream));
    assertTrue(f.isSuccess());
    listenerExecuted.syncUninterruptibly();
    assertTrue(listenerExecuted.isSuccess());
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultPromise(io.netty.util.concurrent.DefaultPromise) ByteBuf(io.netty.buffer.ByteBuf) ChannelFutureListener(io.netty.channel.ChannelFutureListener) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) UnsupportedMessageTypeException(io.netty.handler.codec.UnsupportedMessageTypeException) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 3 with Http2FrameStream

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

the class Http2FrameCodecTest method doNotLeakOnFailedInitializationForChannels.

@Test
public void doNotLeakOnFailedInitializationForChannels() throws Exception {
    setUp(Http2FrameCodecBuilder.forServer(), new Http2Settings().maxConcurrentStreams(2));
    Http2FrameStream stream1 = frameCodec.newStream();
    Http2FrameStream stream2 = frameCodec.newStream();
    ChannelPromise stream1HeaderPromise = channel.newPromise();
    ChannelPromise stream2HeaderPromise = channel.newPromise();
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream1), stream1HeaderPromise);
    channel.runPendingTasks();
    frameInboundWriter.writeInboundGoAway(stream1.id(), 0L, Unpooled.EMPTY_BUFFER);
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream2), stream2HeaderPromise);
    channel.runPendingTasks();
    assertTrue(stream1HeaderPromise.syncUninterruptibly().isSuccess());
    assertTrue(stream2HeaderPromise.isDone());
    assertEquals(0, frameCodec.numInitializingStreams());
    assertFalse(channel.finishAndReleaseAll());
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) Http2TestUtil.anyChannelPromise(io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise) Http2TestUtil.anyHttp2Settings(io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings) Test(org.junit.jupiter.api.Test)

Example 4 with Http2FrameStream

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

the class Http2FrameCodecTest method writeUnknownFrame.

@Test
public void writeUnknownFrame() {
    final Http2FrameStream stream = frameCodec.newStream();
    ByteBuf buffer = Unpooled.buffer().writeByte(1);
    DefaultHttp2UnknownFrame unknownFrame = new DefaultHttp2UnknownFrame((byte) 20, new Http2Flags().ack(true), buffer);
    unknownFrame.stream(stream);
    channel.write(unknownFrame);
    verify(frameWriter).writeFrame(eqFrameCodecCtx(), eq(unknownFrame.frameType()), eq(unknownFrame.stream().id()), eq(unknownFrame.flags()), eq(buffer), any(ChannelPromise.class));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) Http2TestUtil.anyChannelPromise(io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 5 with Http2FrameStream

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

the class Http2FrameCodecTest method newOutboundStreamsShouldBeBuffered.

@Test
public void newOutboundStreamsShouldBeBuffered() throws Exception {
    setUp(Http2FrameCodecBuilder.forServer().encoderEnforceMaxConcurrentStreams(true), new Http2Settings().maxConcurrentStreams(1));
    Http2FrameStream stream1 = frameCodec.newStream();
    Http2FrameStream stream2 = frameCodec.newStream();
    ChannelPromise promise1 = channel.newPromise();
    ChannelPromise promise2 = channel.newPromise();
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream1), promise1);
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream2), promise2);
    assertTrue(isStreamIdValid(stream1.id()));
    channel.runPendingTasks();
    assertTrue(isStreamIdValid(stream2.id()));
    assertTrue(promise1.syncUninterruptibly().isSuccess());
    assertFalse(promise2.isDone());
    // Increase concurrent streams limit to 2
    frameInboundWriter.writeInboundSettings(new Http2Settings().maxConcurrentStreams(2));
    channel.flush();
    assertTrue(promise2.syncUninterruptibly().isSuccess());
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) Http2TestUtil.anyChannelPromise(io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise) Http2TestUtil.anyHttp2Settings(io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 ChannelPromise (io.netty.channel.ChannelPromise)5 Http2TestUtil.anyChannelPromise (io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise)5 Http2TestUtil.anyHttp2Settings (io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings)3 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 UnsupportedMessageTypeException (io.netty.handler.codec.UnsupportedMessageTypeException)2 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)2 DefaultHttp2DataFrame (io.netty.handler.codec.http2.DefaultHttp2DataFrame)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1 DefaultHttp2HeadersFrame (io.netty.handler.codec.http2.DefaultHttp2HeadersFrame)1 DefaultHttp2WindowUpdateFrame (io.netty.handler.codec.http2.DefaultHttp2WindowUpdateFrame)1 DefaultHttp2FrameStream (io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream)1 Http2FrameStream (io.netty.handler.codec.http2.Http2FrameStream)1 Http2Headers (io.netty.handler.codec.http2.Http2Headers)1 DefaultPromise (io.netty.util.concurrent.DefaultPromise)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SSLException (javax.net.ssl.SSLException)1 Timeout (org.junit.jupiter.api.Timeout)1