use of io.netty.handler.codec.http2.Http2LocalFlowController in project netty by netty.
the class DefaultHttp2ConnectionTest method removeAllStreamsWhileIteratingActiveStreamsAndExceptionOccurs.
@Test
public void removeAllStreamsWhileIteratingActiveStreamsAndExceptionOccurs() 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(1);
try {
client.forEachActiveStream(new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) throws Http2Exception {
// This close call is basically a noop, because the following statement will throw an exception.
client.close(promise);
// Do an invalid operation while iterating.
remote.createStream(3, false);
return true;
}
});
} catch (Http2Exception ignored) {
client.close(promise).addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
assertTrue(promise.isDone());
latch.countDown();
}
});
}
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of io.netty.handler.codec.http2.Http2LocalFlowController in project netty by netty.
the class Http2FrameWriterBenchmark method boostrapEnvWithTransport.
private static Environment boostrapEnvWithTransport(final EnvironmentType environmentType) {
final EnvironmentParameters params = environmentType.params();
ServerBootstrap sb = new ServerBootstrap();
Bootstrap cb = new Bootstrap();
final TransportEnvironment environment = new TransportEnvironment(cb, sb);
EventLoopGroup serverEventLoopGroup = params.newEventLoopGroup();
sb.group(serverEventLoopGroup, serverEventLoopGroup);
sb.channel(params.serverChannelClass());
sb.option(ChannelOption.ALLOCATOR, params.serverAllocator());
sb.childOption(ChannelOption.ALLOCATOR, params.serverAllocator());
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
}
});
cb.group(params.newEventLoopGroup());
cb.channel(params.clientChannelClass());
cb.option(ChannelOption.ALLOCATOR, params.clientAllocator());
final CountDownLatch latch = new CountDownLatch(1);
cb.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
Http2Connection connection = new DefaultHttp2Connection(false);
Http2RemoteFlowController remoteFlowController = params.remoteFlowController();
if (remoteFlowController != null) {
connection.remote().flowController(params.remoteFlowController());
}
Http2LocalFlowController localFlowController = params.localFlowController();
if (localFlowController != null) {
connection.local().flowController(localFlowController);
}
environment.writer(new DefaultHttp2FrameWriter());
Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, environment.writer());
Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, new DefaultHttp2FrameReader());
Http2ConnectionHandler connectionHandler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).frameListener(new Http2FrameAdapter()).codec(decoder, encoder).build();
p.addLast(connectionHandler);
environment.context(p.lastContext());
// Must wait for context to be set.
latch.countDown();
}
});
environment.serverChannel(sb.bind(params.address()));
params.address(environment.serverChannel().localAddress());
environment.clientChannel(cb.connect(params.address()));
try {
if (!latch.await(5, SECONDS)) {
throw new RuntimeException("Channel did not initialize in time");
}
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
return environment;
}
use of io.netty.handler.codec.http2.Http2LocalFlowController in project netty by netty.
the class DefaultHttp2ConnectionTest method removeAllStreamsWithManyActiveStreams.
@Test
public void removeAllStreamsWithManyActiveStreams() throws InterruptedException, Http2Exception {
Endpoint<Http2RemoteFlowController> remote = client.remote();
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);
}
testRemoveAllStreams();
}
use of io.netty.handler.codec.http2.Http2LocalFlowController in project grpc-java by grpc.
the class NettyHandlerTestBase method windowShouldNotExceedMaxWindowSize.
@Test
public void windowShouldNotExceedMaxWindowSize() throws Exception {
makeStream();
AbstractNettyHandler handler = (AbstractNettyHandler) handler();
handler.setAutoTuneFlowControl(true);
Http2Stream connectionStream = connection().connectionStream();
Http2LocalFlowController localFlowController = connection().local().flowController();
int maxWindow = handler.flowControlPing().maxWindow();
handler.flowControlPing().setDataSizeSincePing(maxWindow);
int payload = handler.flowControlPing().payload();
ByteBuf buffer = handler.ctx().alloc().buffer(8);
buffer.writeLong(payload);
channelRead(pingFrame(true, buffer));
assertEquals(maxWindow, localFlowController.initialWindowSize(connectionStream));
}
use of io.netty.handler.codec.http2.Http2LocalFlowController in project grpc-java by grpc.
the class NettyServerHandlerTest method connectionWindowShouldBeOverridden.
@Test
@Ignore("Re-enable once https://github.com/grpc/grpc-java/issues/1175 is fixed")
public void connectionWindowShouldBeOverridden() throws Exception {
// 1MiB
flowControlWindow = 1048576;
setUp();
Http2Stream connectionStream = connection().connectionStream();
Http2LocalFlowController localFlowController = connection().local().flowController();
int actualInitialWindowSize = localFlowController.initialWindowSize(connectionStream);
int actualWindowSize = localFlowController.windowSize(connectionStream);
assertEquals(flowControlWindow, actualWindowSize);
assertEquals(flowControlWindow, actualInitialWindowSize);
}
Aggregations