use of software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool in project aws-sdk-java-v2 by aws.
the class NettyNioAsyncHttpClientWireMockTest method closeClient_shouldCloseUnderlyingResources.
@Test
public void closeClient_shouldCloseUnderlyingResources() {
SdkEventLoopGroup eventLoopGroup = SdkEventLoopGroup.builder().build();
SdkChannelPool channelPool = mock(SdkChannelPool.class);
SdkChannelPoolMap<URI, SdkChannelPool> sdkChannelPoolMap = new SdkChannelPoolMap<URI, SdkChannelPool>() {
@Override
protected SdkChannelPool newPool(URI key) {
return channelPool;
}
};
sdkChannelPoolMap.get(URI.create("http://blah"));
NettyConfiguration nettyConfiguration = new NettyConfiguration(AttributeMap.empty());
SdkAsyncHttpClient customerClient = new NettyNioAsyncHttpClient(eventLoopGroup, sdkChannelPoolMap, nettyConfiguration);
customerClient.close();
assertThat(eventLoopGroup.eventLoopGroup().isShuttingDown()).isTrue();
assertThat(eventLoopGroup.eventLoopGroup().isTerminated()).isTrue();
assertThat(sdkChannelPoolMap).isEmpty();
Mockito.verify(channelPool).close();
}
use of software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool in project aws-sdk-java-v2 by aws.
the class HttpOrHttp2ChannelPool method configureProtocol.
private void configureProtocol(Channel newChannel, Protocol protocol) {
if (Protocol.HTTP1_1 == protocol) {
// For HTTP/1.1 we use a traditional channel pool without multiplexing
SdkChannelPool idleConnectionMetricChannelPool = new IdleConnectionCountingChannelPool(eventLoop, delegatePool);
protocolImpl = BetterFixedChannelPool.builder().channelPool(idleConnectionMetricChannelPool).executor(eventLoop).acquireTimeoutAction(BetterFixedChannelPool.AcquireTimeoutAction.FAIL).acquireTimeoutMillis(configuration.connectionAcquireTimeoutMillis()).maxConnections(maxConcurrency).maxPendingAcquires(configuration.maxPendingConnectionAcquires()).build();
} else {
Duration idleConnectionTimeout = configuration.reapIdleConnections() ? Duration.ofMillis(configuration.idleTimeoutMillis()) : null;
SdkChannelPool h2Pool = new Http2MultiplexedChannelPool(delegatePool, eventLoopGroup, idleConnectionTimeout);
protocolImpl = BetterFixedChannelPool.builder().channelPool(h2Pool).executor(eventLoop).acquireTimeoutAction(BetterFixedChannelPool.AcquireTimeoutAction.FAIL).acquireTimeoutMillis(configuration.connectionAcquireTimeoutMillis()).maxConnections(maxConcurrency).maxPendingAcquires(configuration.maxPendingConnectionAcquires()).build();
}
// Give the channel back so it can be acquired again by protocolImpl
// Await the release completion to ensure we do not unnecessarily acquire a second channel
delegatePool.release(newChannel).addListener(runOrPropagate(protocolImplPromise, () -> {
protocolImplPromise.trySuccess(protocolImpl);
}));
}
Aggregations