use of com.linkedin.r2.transport.http.client.common.ChannelPoolManager in project rest.li by linkedin.
the class TestChannelPoolManagerFactorySharingConnection method testSuccessfulRequests.
/**
* End to end test. Testing all the client combinations (http/https stream/rest sharing/not sharing) and check they
* are using the same channelPoolManager
*/
@Test(dataProvider = "configsOpenedConnections")
public void testSuccessfulRequests(boolean restOverStream, String protocolVersion, boolean shareConnection) throws Exception {
makeRequestsWithClients(shareConnection, (clients, clientFactory) -> {
// standard
HashMap<String, String> properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocolVersion);
properties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(10000));
clients.add(new TransportClientAdapter(clientFactory.getClient(properties), restOverStream));
// with parameter that should NOT create a new ChannelPoolManager
properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocolVersion);
// property NOT of the ChannelPoolManager
properties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(2000));
clients.add(new TransportClientAdapter(clientFactory.getClient(properties), restOverStream));
}, // since the two clients have the same settings, with sharing, it should just open 1 connections
1);
}
use of com.linkedin.r2.transport.http.client.common.ChannelPoolManager in project rest.li by linkedin.
the class TestChannelPoolManagerFactorySharingConnection method testSuccessfulRequestds.
/**
* End to end test. Testing all the client combinations (http/https stream/rest sharing/not sharing) and check they
* are NOT using the same channelPoolManager
*/
@Test(dataProvider = "configsOpenedConnections", groups = { "ci-flaky" })
public void testSuccessfulRequestds(boolean restOverStream, String protocolVersion, boolean shareConnection) throws Exception {
makeRequestsWithClients(shareConnection, (clients, clientFactory) -> {
// standard
HashMap<String, String> properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocolVersion);
properties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(10000));
clients.add(new TransportClientAdapter(clientFactory.getClient(properties), restOverStream));
// with parameter that SHOULD create a new ChannelPoolManager
properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocolVersion);
// property of the ChannelPoolManager
properties.put(HttpClientFactory.HTTP_MAX_CHUNK_SIZE, String.valueOf(100));
properties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(10000));
clients.add(new TransportClientAdapter(clientFactory.getClient(properties), restOverStream));
}, // since the two clients have different settings, with sharing, it should just open 2 connections
2);
}
use of com.linkedin.r2.transport.http.client.common.ChannelPoolManager in project rest.li by linkedin.
the class TestEventChannelPoolManagerFactory method testBuildChannelPoolManagers.
@Test
public void testBuildChannelPoolManagers() {
ChannelPoolManagerFactory channelPoolManagerFactory = getChannelPoolManagerFactory();
EventProviderRegistry eventProviderRegistry = mock(EventProviderRegistry.class);
ChannelPoolManagerKey anyChannelPoolManagerKey = mock(ChannelPoolManagerKey.class);
EventAwareChannelPoolManagerFactory factory = new EventAwareChannelPoolManagerFactory(channelPoolManagerFactory, eventProviderRegistry);
ChannelPoolManager actualRestManager = factory.buildRest(anyChannelPoolManagerKey);
ChannelPoolManager actualStreamManager = factory.buildStream(anyChannelPoolManagerKey);
ChannelPoolManager actualHttp2StreamManager = factory.buildHttp2Stream(anyChannelPoolManagerKey);
// Expects event provider to have been registered for three times and none is unregistered
verify(eventProviderRegistry, times(3)).registerChannelPoolEventProvider(any());
verify(eventProviderRegistry, times(0)).unregisterChannelPoolEventProvider(any());
actualRestManager.shutdown(Callbacks.empty(), mock(Runnable.class), mock(Runnable.class), 0L);
actualStreamManager.shutdown(Callbacks.empty(), mock(Runnable.class), mock(Runnable.class), 0L);
actualHttp2StreamManager.shutdown(Callbacks.empty(), mock(Runnable.class), mock(Runnable.class), 0L);
// Expects event provider to have been registered for three times and unregistered for three times
verify(eventProviderRegistry, times(3)).registerChannelPoolEventProvider(any());
verify(eventProviderRegistry, times(3)).unregisterChannelPoolEventProvider(any());
}
use of com.linkedin.r2.transport.http.client.common.ChannelPoolManager in project rest.li by linkedin.
the class TestChannelPoolManager method test.
@Test
public void test() {
ChannelPoolFactory factory = new ChannelPoolFactory() {
@Override
public AsyncPool<Channel> getPool(SocketAddress address) {
return new FakePool<>();
}
};
ChannelPoolManager m = new ChannelPoolManagerImpl(factory, null, null);
final int NUM = 100;
List<SocketAddress> addresses = new ArrayList<>(NUM);
for (int i = 0; i < NUM; i++) {
addresses.add(new InetSocketAddress(i));
}
List<AsyncPool<Channel>> pools = new ArrayList<>(NUM);
for (int i = 0; i < NUM; i++) {
pools.add(m.getPoolForAddress(addresses.get(i)));
}
for (int i = 0; i < NUM; i++) {
Assert.assertEquals(m.getPoolForAddress(addresses.get(i)), pools.get(i));
}
}
use of com.linkedin.r2.transport.http.client.common.ChannelPoolManager in project rest.li by linkedin.
the class HttpClientFactory method getRawClient.
TransportClient getRawClient(Map<String, ? extends Object> properties, SSLContext sslContext, SSLParameters sslParameters) {
// key which identifies and contains the set of transport properties to create a channel pool manager
ChannelPoolManagerKey key = createChannelPoolManagerKey(properties, null, null);
ChannelPoolManagerKey sslKey = createChannelPoolManagerKey(properties, sslContext, sslParameters);
// Raw Client properties
int shutdownTimeout = chooseNewOverDefault(getIntValue(properties, HTTP_SHUTDOWN_TIMEOUT), DEFAULT_SHUTDOWN_TIMEOUT);
int requestTimeout = chooseNewOverDefault(getIntValue(properties, HTTP_REQUEST_TIMEOUT), DEFAULT_REQUEST_TIMEOUT);
int streamingTimeout = chooseNewOverDefault(getIntValue(properties, HTTP_STREAMING_TIMEOUT), DEFAULT_STREAMING_TIMEOUT);
if (streamingTimeout > DEFAULT_STREAMING_TIMEOUT) {
// Minimum value for idle timeout so we don't have a busy thread checking for idle timeout too frequently!
if (streamingTimeout < DEFAULT_MINIMUM_STREAMING_TIMEOUT) {
streamingTimeout = DEFAULT_MINIMUM_STREAMING_TIMEOUT;
LOG.warn("Streaming timeout is too small, resetting to the minimum allowed timeout value of {}ms", DEFAULT_MINIMUM_STREAMING_TIMEOUT);
}
}
String httpServiceName = (String) properties.get(HTTP_SERVICE_NAME);
HttpProtocolVersion httpProtocolVersion = chooseNewOverDefault(getHttpProtocolVersion(properties, HTTP_PROTOCOL_VERSION), _defaultHttpVersion);
LOG.info("The service '{}' has been assigned to the ChannelPoolManager with key '{}', http.protocolVersion={}, usePipelineV2={}, requestTimeout={}ms, streamingTimeout={}ms", httpServiceName, key.getName(), httpProtocolVersion, _usePipelineV2, requestTimeout, streamingTimeout);
if (_usePipelineV2) {
ChannelPoolManager channelPoolManager;
ChannelPoolManager sslChannelPoolManager;
switch(httpProtocolVersion) {
case HTTP_1_1:
channelPoolManager = _channelPoolManagerFactory.buildStream(key);
sslChannelPoolManager = _channelPoolManagerFactory.buildStream(sslKey);
break;
case HTTP_2:
channelPoolManager = _channelPoolManagerFactory.buildHttp2Stream(key);
sslChannelPoolManager = _channelPoolManagerFactory.buildHttp2Stream(sslKey);
break;
default:
throw new IllegalArgumentException("Unrecognized HTTP protocol version " + httpProtocolVersion);
}
return new com.linkedin.r2.netty.client.HttpNettyClient(_eventLoopGroup, _executor, _callbackExecutorGroup, channelPoolManager, sslChannelPoolManager, httpProtocolVersion, SystemClock.instance(), requestTimeout, streamingTimeout, shutdownTimeout);
}
TransportClient streamClient;
switch(httpProtocolVersion) {
case HTTP_1_1:
streamClient = new HttpNettyStreamClient(_eventLoopGroup, _executor, requestTimeout, shutdownTimeout, _callbackExecutorGroup, _jmxManager, _channelPoolManagerFactory.buildStream(key), _channelPoolManagerFactory.buildStream(sslKey));
break;
case HTTP_2:
streamClient = new Http2NettyStreamClient(_eventLoopGroup, _executor, requestTimeout, shutdownTimeout, _callbackExecutorGroup, _jmxManager, _channelPoolManagerFactory.buildHttp2Stream(key), _channelPoolManagerFactory.buildHttp2Stream(sslKey));
break;
default:
throw new IllegalArgumentException("Unrecognized HTTP protocol version " + httpProtocolVersion);
}
HttpNettyClient legacyClient = new HttpNettyClient(_eventLoopGroup, _executor, requestTimeout, shutdownTimeout, _callbackExecutorGroup, _jmxManager, _channelPoolManagerFactory.buildRest(key), _channelPoolManagerFactory.buildRest(sslKey));
return new MixedClient(legacyClient, streamClient);
}
Aggregations