Search in sources :

Example 6 with Endpoint

use of io.netty.handler.codec.http2.Http2Connection.Endpoint 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)

Aggregations

Endpoint (io.netty.handler.codec.http2.Http2Connection.Endpoint)4 Test (org.junit.Test)3 Future (io.netty.util.concurrent.Future)2 FutureListener (io.netty.util.concurrent.FutureListener)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPromise (io.netty.channel.ChannelPromise)1 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)1 Http2Stream (io.netty.handler.codec.http2.Http2Stream)1