use of com.linkedin.d2.D2TransportClientProperties in project rest.li by linkedin.
the class TransportClientPropertiesConverterTest method testTransportClientPropertiesConverter.
@Test
public void testTransportClientPropertiesConverter() {
final Integer queryPostThreshold = 8192;
final Long requestTimeout = 10000L;
final Long maxResponseSize = 1003300L;
final Integer poolSize = 200;
final Integer poolWaiterSize = 32768;
final Long idleTimeout = 600000L;
final Long sslIdleTimeout = 900000L;
final Long shutdownTimeout = 50000L;
final Long gracefulShutdownTimeout = 30000L;
final StringArray responseCompressionRaw = new StringArray("finder:*");
final StringArray responseContentEncoding = new StringArray("gzip", "snappy");
final StringArray requestContentEncoding = new StringArray("lz4", "identity");
final Boolean useResponseCompression = true;
final Integer maxHeaderSize = 8192;
final Integer maxChunkSize = 4096;
final poolStrategyType poolStrategy = poolStrategyType.LRU;
final Integer minPoolSize = 5;
final String poolStatsNamePrefix = "poolStats";
final Integer maxConcurrentConnections = 1000;
final Boolean tcpNoDelay = true;
final HttpProtocolVersionType protocolVersion = HttpProtocolVersionType.HTTP_1_1;
final StringArray allowedClientOverrideKeys = new StringArray(PropertyKeys.HTTP_REQUEST_TIMEOUT, PropertyKeys.HTTP_QUERY_POST_THRESHOLD);
final Double maxClientRequestRetryRatio = 0.2;
Map<String, Object> transportClientProperties = new HashMap<>();
transportClientProperties.put(PropertyKeys.HTTP_QUERY_POST_THRESHOLD, queryPostThreshold.toString());
transportClientProperties.put(PropertyKeys.HTTP_REQUEST_TIMEOUT, requestTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_RESPONSE_SIZE, maxResponseSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_SIZE, poolSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_WAITER_SIZE, poolWaiterSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_IDLE_TIMEOUT, idleTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_SSL_IDLE_TIMEOUT, sslIdleTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_SHUTDOWN_TIMEOUT, shutdownTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_GRACEFUL_SHUTDOWN_TIMEOUT, gracefulShutdownTimeout.toString());
transportClientProperties.put(PropertyKeys.HTTP_RESPONSE_COMPRESSION_OPERATIONS, String.join(",", responseCompressionRaw));
transportClientProperties.put(PropertyKeys.HTTP_RESPONSE_CONTENT_ENCODINGS, String.join(",", responseContentEncoding));
transportClientProperties.put(PropertyKeys.HTTP_REQUEST_CONTENT_ENCODINGS, String.join(",", requestContentEncoding));
transportClientProperties.put(PropertyKeys.HTTP_USE_RESPONSE_COMPRESSION, useResponseCompression.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_HEADER_SIZE, maxHeaderSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_MAX_CHUNK_SIZE, maxChunkSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_STRATEGY, poolStrategy.name());
transportClientProperties.put(PropertyKeys.HTTP_POOL_MIN_SIZE, minPoolSize.toString());
transportClientProperties.put(PropertyKeys.HTTP_POOL_STATS_NAME_PREFIX, poolStatsNamePrefix);
transportClientProperties.put(PropertyKeys.HTTP_MAX_CONCURRENT_CONNECTIONS, maxConcurrentConnections.toString());
transportClientProperties.put(PropertyKeys.HTTP_TCP_NO_DELAY, tcpNoDelay.toString());
transportClientProperties.put(PropertyKeys.HTTP_PROTOCOL_VERSION, protocolVersion.name());
transportClientProperties.put(PropertyKeys.ALLOWED_CLIENT_OVERRIDE_KEYS, String.join(",", allowedClientOverrideKeys));
transportClientProperties.put(PropertyKeys.HTTP_MAX_CLIENT_REQUEST_RETRY_RATIO, maxClientRequestRetryRatio.toString());
D2TransportClientProperties d2TransportClientProperties = new D2TransportClientProperties().setQueryPostThreshold(queryPostThreshold).setRequestTimeout(requestTimeout).setMaxResponseSize(maxResponseSize).setPoolSize(poolSize).setPoolWaiterSize(poolWaiterSize).setIdleTimeout(idleTimeout).setSslIdleTimeout(sslIdleTimeout).setShutdownTimeout(shutdownTimeout).setGracefulShutdownTimeout(gracefulShutdownTimeout).setResponseCompressionOperations(responseCompressionRaw).setResponseContentEncodings(responseContentEncoding).setRequestContentEncodings(requestContentEncoding).setUseResponseCompression(useResponseCompression).setMaxHeaderSize(maxHeaderSize).setMaxChunkSize(maxChunkSize).setPoolStrategy(poolStrategy).setMinPoolSize(minPoolSize).setPoolStatsNamePrefix(poolStatsNamePrefix).setMaxConcurrentConnections(maxConcurrentConnections).setProtocolVersion(protocolVersion).setTcpNoDelay(tcpNoDelay).setAllowedClientOverrideKeys(allowedClientOverrideKeys).setMaxClientRequestRetryRatio(maxClientRequestRetryRatio);
Assert.assertEquals(TransportClientPropertiesConverter.toConfig(transportClientProperties), d2TransportClientProperties);
Assert.assertEquals(TransportClientPropertiesConverter.toProperties(d2TransportClientProperties), transportClientProperties);
}
use of com.linkedin.d2.D2TransportClientProperties in project rest.li by linkedin.
the class DarkClustersConverter method toConfig.
public static DarkClusterConfigMap toConfig(Map<String, Object> properties) {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String darkClusterName = entry.getKey();
DarkClusterConfig darkClusterConfig = new DarkClusterConfig();
@SuppressWarnings("unchecked") Map<String, Object> props = (Map<String, Object>) entry.getValue();
if (props.containsKey(PropertyKeys.DARK_CLUSTER_MULTIPLIER)) {
darkClusterConfig.setMultiplier(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_MULTIPLIER), Float.class));
} else {
// to maintain backwards compatibility with previously ser/de, set the default on deserialization
darkClusterConfig.setMultiplier(DARK_CLUSTER_DEFAULT_MULTIPLIER);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_OUTBOUND_TARGET_RATE)) {
darkClusterConfig.setDispatcherOutboundTargetRate(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_OUTBOUND_TARGET_RATE), Float.class));
} else {
darkClusterConfig.setDispatcherOutboundTargetRate(DARK_CLUSTER_DEFAULT_TARGET_RATE);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_MAX_REQUESTS_TO_BUFFER)) {
darkClusterConfig.setDispatcherMaxRequestsToBuffer(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_MAX_REQUESTS_TO_BUFFER), Integer.class));
} else {
darkClusterConfig.setDispatcherMaxRequestsToBuffer(DARK_CLUSTER_DEFAULT_MAX_REQUESTS_TO_BUFFER);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_BUFFERED_REQUEST_EXPIRY_IN_SECONDS)) {
darkClusterConfig.setDispatcherBufferedRequestExpiryInSeconds(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_BUFFERED_REQUEST_EXPIRY_IN_SECONDS), Integer.class));
} else {
darkClusterConfig.setDispatcherBufferedRequestExpiryInSeconds(DARK_CLUSTER_DEFAULT_BUFFERED_REQUEST_EXPIRY_IN_SECONDS);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST)) {
DataList dataList = new DataList();
@SuppressWarnings("unchecked") List<String> strategyList = (List<String>) props.get(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST);
dataList.addAll(strategyList);
DarkClusterStrategyNameArray darkClusterStrategyNameArray = new DarkClusterStrategyNameArray(dataList);
darkClusterConfig.setDarkClusterStrategyPrioritizedList(darkClusterStrategyNameArray);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_TRANSPORT_CLIENT_PROPERTIES)) {
@SuppressWarnings("unchecked") D2TransportClientProperties transportClientProperties = TransportClientPropertiesConverter.toConfig((Map<String, Object>) props.get(PropertyKeys.DARK_CLUSTER_TRANSPORT_CLIENT_PROPERTIES));
darkClusterConfig.setTransportClientProperties(transportClientProperties);
}
configMap.put(darkClusterName, darkClusterConfig);
}
return configMap;
}
use of com.linkedin.d2.D2TransportClientProperties in project rest.li by linkedin.
the class DarkClustersConverterTest method testEntriesInClusterConfig.
@Test
public void testEntriesInClusterConfig() {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
DarkClusterStrategyNameArray multiplierStrategyTypeArray = new DarkClusterStrategyNameArray();
multiplierStrategyTypeArray.add(DarkClusterStrategyName.RELATIVE_TRAFFIC.RELATIVE_TRAFFIC);
D2TransportClientProperties transportClientProperties = new D2TransportClientProperties().setRequestTimeout(1000);
DarkClusterConfig config = new DarkClusterConfig().setDarkClusterStrategyPrioritizedList(multiplierStrategyTypeArray).setTransportClientProperties(transportClientProperties);
configMap.put(DARK_CLUSTER_KEY, config);
DarkClusterConfigMap expectedConfigMap = new DarkClusterConfigMap();
DarkClusterConfig expectedConfig = new DarkClusterConfig(config.data());
expectedConfig.setMultiplier(0);
expectedConfig.setDispatcherOutboundTargetRate(0);
expectedConfig.setDispatcherMaxRequestsToBuffer(1);
expectedConfig.setDispatcherBufferedRequestExpiryInSeconds(1);
expectedConfigMap.put(DARK_CLUSTER_KEY, expectedConfig);
DarkClusterConfigMap resultConfigMap = DarkClustersConverter.toConfig(DarkClustersConverter.toProperties(configMap));
Assert.assertEquals(resultConfigMap, expectedConfigMap);
// verify values are converted properly.
DarkClusterConfig darkClusterConfig = resultConfigMap.get(DARK_CLUSTER_KEY);
Assert.assertEquals(darkClusterConfig.getMultiplier(), DARK_CLUSTER_DEFAULT_MULTIPLIER, "unexpected multiplier");
Assert.assertEquals(darkClusterConfig.getDarkClusterStrategyPrioritizedList().size(), 1, "there should be one strategy");
Assert.assertEquals(darkClusterConfig.getDarkClusterStrategyPrioritizedList().get(0), DarkClusterStrategyName.RELATIVE_TRAFFIC, "expected RELATIVE_TRAFFIC strategy");
Assert.assertTrue(darkClusterConfig.hasTransportClientProperties());
D2TransportClientProperties returnedTransportClientProperties = darkClusterConfig.getTransportClientProperties();
Assert.assertNotNull(returnedTransportClientProperties);
Assert.assertTrue(returnedTransportClientProperties.hasRequestTimeout());
Assert.assertEquals(Objects.requireNonNull(returnedTransportClientProperties.getRequestTimeout()).longValue(), 1000, "expected 1000 request Timeout");
}
Aggregations