From e5e01b5169fb72368baf71739b57ee75419857c7 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Fri, 8 Mar 2019 14:11:13 -0800 Subject: [PATCH] core,grpclb: use better generics on service config --- core/src/main/java/io/grpc/LoadBalancer.java | 2 +- .../AutoConfiguredLoadBalancerFactory.java | 10 +- .../io/grpc/internal/DnsNameResolver.java | 27 ++--- .../java/io/grpc/internal/GrpcAttributes.java | 2 +- .../java/io/grpc/internal/JsonParser.java | 6 +- .../io/grpc/internal/ManagedChannelImpl.java | 5 +- .../internal/ServiceConfigInterceptor.java | 20 ++-- .../io/grpc/internal/ServiceConfigUtil.java | 107 +++++++++--------- .../io/grpc/util/RoundRobinLoadBalancer.java | 3 +- ...AutoConfiguredLoadBalancerFactoryTest.java | 44 +++---- .../io/grpc/internal/DnsNameResolverTest.java | 30 ++--- .../io/grpc/internal/HedgingPolicyTest.java | 4 +- .../grpc/internal/ManagedChannelImplTest.java | 4 +- .../io/grpc/internal/RetryPolicyTest.java | 6 +- .../grpc/util/RoundRobinLoadBalancerTest.java | 16 +-- .../io/grpc/grpclb/GrpclbLoadBalancer.java | 4 +- .../grpc/grpclb/GrpclbLoadBalancerTest.java | 4 +- .../HealthCheckingLoadBalancerFactory.java | 2 +- ...HealthCheckingLoadBalancerFactoryTest.java | 3 +- .../java/io/grpc/xds/XdsLoadBalancer.java | 4 +- .../java/io/grpc/xds/FallbackManagerTest.java | 2 +- .../java/io/grpc/xds/XdsLoadBalancerTest.java | 24 ++-- 22 files changed, 162 insertions(+), 167 deletions(-) diff --git a/core/src/main/java/io/grpc/LoadBalancer.java b/core/src/main/java/io/grpc/LoadBalancer.java index da9e8bee14..48d26462d3 100644 --- a/core/src/main/java/io/grpc/LoadBalancer.java +++ b/core/src/main/java/io/grpc/LoadBalancer.java @@ -109,7 +109,7 @@ public abstract class LoadBalancer { *

{@link NameResolver}s should not produce this attribute. */ @NameResolver.ResolutionResultAttr - public static final Attributes.Key> ATTR_LOAD_BALANCING_CONFIG = + public static final Attributes.Key> ATTR_LOAD_BALANCING_CONFIG = Attributes.Key.create("io.grpc.LoadBalancer.loadBalancingConfig"); /** diff --git a/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java b/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java index 291ac78de1..e6d7e5e40e 100644 --- a/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java +++ b/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java @@ -106,7 +106,7 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor "Unexpected ATTR_LOAD_BALANCING_CONFIG from upstream: " + attributes.get(ATTR_LOAD_BALANCING_CONFIG)); } - Map configMap = attributes.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); + Map configMap = attributes.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); PolicySelection selection; try { selection = decideLoadBalancerProvider(servers, configMap); @@ -202,7 +202,7 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor */ @VisibleForTesting PolicySelection decideLoadBalancerProvider( - List servers, @Nullable Map config) + List servers, @Nullable Map config) throws PolicyException { // Check for balancer addresses boolean haveBalancerAddress = false; @@ -217,7 +217,7 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor List lbConfigs = null; if (config != null) { - List> rawLbConfigs = + List> rawLbConfigs = ServiceConfigUtil.getLoadBalancingConfigsFromServiceConfig(config); lbConfigs = ServiceConfigUtil.unwrapLoadBalancingConfigList(rawLbConfigs); } @@ -304,11 +304,11 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor static final class PolicySelection { final LoadBalancerProvider provider; final List serverList; - @Nullable final Map config; + @Nullable final Map config; PolicySelection( LoadBalancerProvider provider, List serverList, - @Nullable Map config) { + @Nullable Map config) { this.provider = checkNotNull(provider, "provider"); this.serverList = Collections.unmodifiableList(checkNotNull(serverList, "serverList")); this.config = config; diff --git a/core/src/main/java/io/grpc/internal/DnsNameResolver.java b/core/src/main/java/io/grpc/internal/DnsNameResolver.java index 0ef208193c..8c874cc679 100644 --- a/core/src/main/java/io/grpc/internal/DnsNameResolver.java +++ b/core/src/main/java/io/grpc/internal/DnsNameResolver.java @@ -285,10 +285,9 @@ final class DnsNameResolver extends NameResolver { Attributes.Builder attrs = Attributes.newBuilder(); if (!resolutionResults.txtRecords.isEmpty()) { - Map serviceConfig = null; + Map serviceConfig = null; try { - for (Map possibleConfig : - parseTxtResults(resolutionResults.txtRecords)) { + for (Map possibleConfig : parseTxtResults(resolutionResults.txtRecords)) { try { serviceConfig = maybeChooseServiceConfig(possibleConfig, random, getLocalHostname()); @@ -406,23 +405,23 @@ final class DnsNameResolver extends NameResolver { @SuppressWarnings("unchecked") @VisibleForTesting - static List> parseTxtResults(List txtRecords) { - List> serviceConfigs = new ArrayList<>(); + static List> parseTxtResults(List txtRecords) { + List> serviceConfigs = new ArrayList<>(); for (String txtRecord : txtRecords) { if (txtRecord.startsWith(SERVICE_CONFIG_PREFIX)) { - List> choices; + List> choices; try { Object rawChoices = JsonParser.parse(txtRecord.substring(SERVICE_CONFIG_PREFIX.length())); if (!(rawChoices instanceof List)) { throw new IOException("wrong type " + rawChoices); } - List listChoices = (List) rawChoices; + List listChoices = (List) rawChoices; for (Object obj : listChoices) { if (!(obj instanceof Map)) { throw new IOException("wrong element type " + rawChoices); } } - choices = (List>) (List) listChoices; + choices = (List>) listChoices; } catch (IOException e) { logger.log(Level.WARNING, "Bad service config: " + txtRecord, e); continue; @@ -436,8 +435,7 @@ final class DnsNameResolver extends NameResolver { } @Nullable - private static final Double getPercentageFromChoice( - Map serviceConfigChoice) { + private static final Double getPercentageFromChoice(Map serviceConfigChoice) { if (!serviceConfigChoice.containsKey(SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY)) { return null; } @@ -446,7 +444,7 @@ final class DnsNameResolver extends NameResolver { @Nullable private static final List getClientLanguagesFromChoice( - Map serviceConfigChoice) { + Map serviceConfigChoice) { if (!serviceConfigChoice.containsKey(SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY)) { return null; } @@ -455,8 +453,7 @@ final class DnsNameResolver extends NameResolver { } @Nullable - private static final List getHostnamesFromChoice( - Map serviceConfigChoice) { + private static final List getHostnamesFromChoice(Map serviceConfigChoice) { if (!serviceConfigChoice.containsKey(SERVICE_CONFIG_CHOICE_CLIENT_HOSTNAME_KEY)) { return null; } @@ -499,8 +496,8 @@ final class DnsNameResolver extends NameResolver { */ @Nullable @VisibleForTesting - static Map maybeChooseServiceConfig( - Map choice, Random random, String hostname) { + static Map maybeChooseServiceConfig( + Map choice, Random random, String hostname) { for (Entry entry : choice.entrySet()) { Verify.verify(SERVICE_CONFIG_CHOICE_KEYS.contains(entry.getKey()), "Bad key: %s", entry); } diff --git a/core/src/main/java/io/grpc/internal/GrpcAttributes.java b/core/src/main/java/io/grpc/internal/GrpcAttributes.java index bedc5d3842..d6fe8e56ce 100644 --- a/core/src/main/java/io/grpc/internal/GrpcAttributes.java +++ b/core/src/main/java/io/grpc/internal/GrpcAttributes.java @@ -31,7 +31,7 @@ public final class GrpcAttributes { * Attribute key for service config. */ @NameResolver.ResolutionResultAttr - public static final Attributes.Key> NAME_RESOLVER_SERVICE_CONFIG = + public static final Attributes.Key> NAME_RESOLVER_SERVICE_CONFIG = Attributes.Key.create("service-config"); /** diff --git a/core/src/main/java/io/grpc/internal/JsonParser.java b/core/src/main/java/io/grpc/internal/JsonParser.java index 90cbe44161..56d7863e4a 100644 --- a/core/src/main/java/io/grpc/internal/JsonParser.java +++ b/core/src/main/java/io/grpc/internal/JsonParser.java @@ -40,7 +40,7 @@ public final class JsonParser { private JsonParser() {} /** - * Parses a json string, returning either a {@code Map}, {@code List}, + * Parses a json string, returning either a {@code Map}, {@code List}, * {@code String}, {@code Double}, {@code Boolean}, or {@code null}. */ @SuppressWarnings("unchecked") @@ -77,7 +77,7 @@ public final class JsonParser { } } - private static Map parseJsonObject(JsonReader jr) throws IOException { + private static Map parseJsonObject(JsonReader jr) throws IOException { jr.beginObject(); Map obj = new LinkedHashMap<>(); while (jr.hasNext()) { @@ -90,7 +90,7 @@ public final class JsonParser { return Collections.unmodifiableMap(obj); } - private static List parseJsonArray(JsonReader jr) throws IOException { + private static List parseJsonArray(JsonReader jr) throws IOException { jr.beginArray(); List array = new ArrayList<>(); while (jr.hasNext()) { diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java index 635dc292de..58d808766d 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java @@ -237,7 +237,7 @@ final class ManagedChannelImpl extends ManagedChannel implements @CheckForNull private Boolean haveBackends; // a flag for doing channel tracing when flipped @Nullable - private Map lastServiceConfig; // used for channel tracing when value changed + private Map lastServiceConfig; // used for channel tracing when value changed // One instance per channel. private final ChannelBufferMeter channelBufferUsed = new ChannelBufferMeter(); @@ -1296,8 +1296,7 @@ final class ManagedChannelImpl extends ManagedChannel implements channelLogger.log(ChannelLogLevel.INFO, "Address resolved: {0}", servers); haveBackends = true; } - final Map serviceConfig = - config.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); + final Map serviceConfig = config.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); if (serviceConfig != null && !serviceConfig.equals(lastServiceConfig)) { channelLogger.log(ChannelLogLevel.INFO, "Service config changed"); lastServiceConfig = serviceConfig; diff --git a/core/src/main/java/io/grpc/internal/ServiceConfigInterceptor.java b/core/src/main/java/io/grpc/internal/ServiceConfigInterceptor.java index 0d35b4e353..c8bf1c9ce6 100644 --- a/core/src/main/java/io/grpc/internal/ServiceConfigInterceptor.java +++ b/core/src/main/java/io/grpc/internal/ServiceConfigInterceptor.java @@ -73,14 +73,14 @@ final class ServiceConfigInterceptor implements ClientInterceptor { this.maxHedgedAttemptsLimit = maxHedgedAttemptsLimit; } - void handleUpdate(@Nonnull Map serviceConfig) { + void handleUpdate(@Nonnull Map serviceConfig) { Map newServiceMethodConfigs = new HashMap<>(); Map newServiceConfigs = new HashMap<>(); // Try and do as much validation here before we swap out the existing configuration. In case // the input is invalid, we don't want to lose the existing configuration. - List> methodConfigs = + List> methodConfigs = ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig); if (methodConfigs == null) { logger.log(Level.FINE, "No method configs found, skipping"); @@ -88,16 +88,16 @@ final class ServiceConfigInterceptor implements ClientInterceptor { return; } - for (Map methodConfig : methodConfigs) { + for (Map methodConfig : methodConfigs) { MethodInfo info = new MethodInfo( methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit); - List> nameList = + List> nameList = ServiceConfigUtil.getNameListFromMethodConfig(methodConfig); checkArgument( nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig); - for (Map name : nameList) { + for (Map name : nameList) { String serviceName = ServiceConfigUtil.getServiceFromName(name); checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name"); String methodName = ServiceConfigUtil.getMethodFromName(name); @@ -141,7 +141,7 @@ final class ServiceConfigInterceptor implements ClientInterceptor { * @param retryEnabled when false, the argument maxRetryAttemptsLimit will have no effect. */ MethodInfo( - Map methodConfig, boolean retryEnabled, int maxRetryAttemptsLimit, + Map methodConfig, boolean retryEnabled, int maxRetryAttemptsLimit, int maxHedgedAttemptsLimit) { timeoutNanos = ServiceConfigUtil.getTimeoutFromMethodConfig(methodConfig); waitForReady = ServiceConfigUtil.getWaitForReadyFromMethodConfig(methodConfig); @@ -160,12 +160,12 @@ final class ServiceConfigInterceptor implements ClientInterceptor { "maxOutboundMessageSize %s exceeds bounds", maxOutboundMessageSize); } - Map retryPolicyMap = + Map retryPolicyMap = retryEnabled ? ServiceConfigUtil.getRetryPolicyFromMethodConfig(methodConfig) : null; retryPolicy = retryPolicyMap == null ? RetryPolicy.DEFAULT : retryPolicy(retryPolicyMap, maxRetryAttemptsLimit); - Map hedgingPolicyMap = + Map hedgingPolicyMap = retryEnabled ? ServiceConfigUtil.getHedgingPolicyFromMethodConfig(methodConfig) : null; hedgingPolicy = hedgingPolicyMap == null ? HedgingPolicy.DEFAULT : hedgingPolicy(hedgingPolicyMap, maxHedgedAttemptsLimit); @@ -201,7 +201,7 @@ final class ServiceConfigInterceptor implements ClientInterceptor { .toString(); } - private static RetryPolicy retryPolicy(Map retryPolicy, int maxAttemptsLimit) { + private static RetryPolicy retryPolicy(Map retryPolicy, int maxAttemptsLimit) { int maxAttempts = checkNotNull( ServiceConfigUtil.getMaxAttemptsFromRetryPolicy(retryPolicy), "maxAttempts cannot be empty"); @@ -249,7 +249,7 @@ final class ServiceConfigInterceptor implements ClientInterceptor { } private static HedgingPolicy hedgingPolicy( - Map hedgingPolicy, int maxAttemptsLimit) { + Map hedgingPolicy, int maxAttemptsLimit) { int maxAttempts = checkNotNull( ServiceConfigUtil.getMaxAttemptsFromHedgingPolicy(hedgingPolicy), "maxAttempts cannot be empty"); diff --git a/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java b/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java index 61bd2e957b..25d815b1a9 100644 --- a/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java +++ b/core/src/main/java/io/grpc/internal/ServiceConfigUtil.java @@ -74,7 +74,7 @@ public final class ServiceConfigUtil { * Fetch the health-checked service name from service config. {@code null} if can't find one. */ @Nullable - public static String getHealthCheckedServiceName(@Nullable Map serviceConfig) { + public static String getHealthCheckedServiceName(@Nullable Map serviceConfig) { String healthCheckKey = "healthCheckConfig"; String serviceNameKey = "serviceName"; if (serviceConfig == null || !serviceConfig.containsKey(healthCheckKey)) { @@ -89,7 +89,7 @@ public final class ServiceConfigUtil { } } */ - Map healthCheck = getObject(serviceConfig, healthCheckKey); + Map healthCheck = getObject(serviceConfig, healthCheckKey); if (!healthCheck.containsKey(serviceNameKey)) { return null; } @@ -97,7 +97,7 @@ public final class ServiceConfigUtil { } @Nullable - static Throttle getThrottlePolicy(@Nullable Map serviceConfig) { + static Throttle getThrottlePolicy(@Nullable Map serviceConfig) { String retryThrottlingKey = "retryThrottling"; if (serviceConfig == null || !serviceConfig.containsKey(retryThrottlingKey)) { return null; @@ -122,7 +122,7 @@ public final class ServiceConfigUtil { } */ - Map throttling = getObject(serviceConfig, retryThrottlingKey); + Map throttling = getObject(serviceConfig, retryThrottlingKey); float maxTokens = getDouble(throttling, "maxTokens").floatValue(); float tokenRatio = getDouble(throttling, "tokenRatio").floatValue(); @@ -132,7 +132,7 @@ public final class ServiceConfigUtil { } @Nullable - static Integer getMaxAttemptsFromRetryPolicy(Map retryPolicy) { + static Integer getMaxAttemptsFromRetryPolicy(Map retryPolicy) { if (!retryPolicy.containsKey(RETRY_POLICY_MAX_ATTEMPTS_KEY)) { return null; } @@ -140,7 +140,7 @@ public final class ServiceConfigUtil { } @Nullable - static Long getInitialBackoffNanosFromRetryPolicy(Map retryPolicy) { + static Long getInitialBackoffNanosFromRetryPolicy(Map retryPolicy) { if (!retryPolicy.containsKey(RETRY_POLICY_INITIAL_BACKOFF_KEY)) { return null; } @@ -153,7 +153,7 @@ public final class ServiceConfigUtil { } @Nullable - static Long getMaxBackoffNanosFromRetryPolicy(Map retryPolicy) { + static Long getMaxBackoffNanosFromRetryPolicy(Map retryPolicy) { if (!retryPolicy.containsKey(RETRY_POLICY_MAX_BACKOFF_KEY)) { return null; } @@ -166,7 +166,7 @@ public final class ServiceConfigUtil { } @Nullable - static Double getBackoffMultiplierFromRetryPolicy(Map retryPolicy) { + static Double getBackoffMultiplierFromRetryPolicy(Map retryPolicy) { if (!retryPolicy.containsKey(RETRY_POLICY_BACKOFF_MULTIPLIER_KEY)) { return null; } @@ -174,7 +174,7 @@ public final class ServiceConfigUtil { } @Nullable - static List getRetryableStatusCodesFromRetryPolicy(Map retryPolicy) { + static List getRetryableStatusCodesFromRetryPolicy(Map retryPolicy) { if (!retryPolicy.containsKey(RETRY_POLICY_RETRYABLE_STATUS_CODES_KEY)) { return null; } @@ -182,7 +182,7 @@ public final class ServiceConfigUtil { } @Nullable - static Integer getMaxAttemptsFromHedgingPolicy(Map hedgingPolicy) { + static Integer getMaxAttemptsFromHedgingPolicy(Map hedgingPolicy) { if (!hedgingPolicy.containsKey(HEDGING_POLICY_MAX_ATTEMPTS_KEY)) { return null; } @@ -190,7 +190,7 @@ public final class ServiceConfigUtil { } @Nullable - static Long getHedgingDelayNanosFromHedgingPolicy(Map hedgingPolicy) { + static Long getHedgingDelayNanosFromHedgingPolicy(Map hedgingPolicy) { if (!hedgingPolicy.containsKey(HEDGING_POLICY_HEDGING_DELAY_KEY)) { return null; } @@ -203,7 +203,7 @@ public final class ServiceConfigUtil { } @Nullable - static List getNonFatalStatusCodesFromHedgingPolicy(Map hedgingPolicy) { + static List getNonFatalStatusCodesFromHedgingPolicy(Map hedgingPolicy) { if (!hedgingPolicy.containsKey(HEDGING_POLICY_NON_FATAL_STATUS_CODES_KEY)) { return null; } @@ -211,7 +211,7 @@ public final class ServiceConfigUtil { } @Nullable - static String getServiceFromName(Map name) { + static String getServiceFromName(Map name) { if (!name.containsKey(NAME_SERVICE_KEY)) { return null; } @@ -219,7 +219,7 @@ public final class ServiceConfigUtil { } @Nullable - static String getMethodFromName(Map name) { + static String getMethodFromName(Map name) { if (!name.containsKey(NAME_METHOD_KEY)) { return null; } @@ -227,7 +227,7 @@ public final class ServiceConfigUtil { } @Nullable - static Map getRetryPolicyFromMethodConfig(Map methodConfig) { + static Map getRetryPolicyFromMethodConfig(Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_RETRY_POLICY_KEY)) { return null; } @@ -235,7 +235,7 @@ public final class ServiceConfigUtil { } @Nullable - static Map getHedgingPolicyFromMethodConfig(Map methodConfig) { + static Map getHedgingPolicyFromMethodConfig(Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_HEDGING_POLICY_KEY)) { return null; } @@ -243,7 +243,8 @@ public final class ServiceConfigUtil { } @Nullable - static List> getNameListFromMethodConfig(Map methodConfig) { + static List> getNameListFromMethodConfig( + Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_NAME_KEY)) { return null; } @@ -256,7 +257,7 @@ public final class ServiceConfigUtil { * @return duration nanoseconds, or {@code null} if it isn't present. */ @Nullable - static Long getTimeoutFromMethodConfig(Map methodConfig) { + static Long getTimeoutFromMethodConfig(Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_TIMEOUT_KEY)) { return null; } @@ -269,7 +270,7 @@ public final class ServiceConfigUtil { } @Nullable - static Boolean getWaitForReadyFromMethodConfig(Map methodConfig) { + static Boolean getWaitForReadyFromMethodConfig(Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_WAIT_FOR_READY_KEY)) { return null; } @@ -277,7 +278,7 @@ public final class ServiceConfigUtil { } @Nullable - static Integer getMaxRequestMessageBytesFromMethodConfig(Map methodConfig) { + static Integer getMaxRequestMessageBytesFromMethodConfig(Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES_KEY)) { return null; } @@ -285,7 +286,7 @@ public final class ServiceConfigUtil { } @Nullable - static Integer getMaxResponseMessageBytesFromMethodConfig(Map methodConfig) { + static Integer getMaxResponseMessageBytesFromMethodConfig(Map methodConfig) { if (!methodConfig.containsKey(METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES_KEY)) { return null; } @@ -293,8 +294,8 @@ public final class ServiceConfigUtil { } @Nullable - static List> getMethodConfigFromServiceConfig( - Map serviceConfig) { + static List> getMethodConfigFromServiceConfig( + Map serviceConfig) { if (!serviceConfig.containsKey(SERVICE_CONFIG_METHOD_CONFIG_KEY)) { return null; } @@ -306,8 +307,8 @@ public final class ServiceConfigUtil { */ @SuppressWarnings("unchecked") @VisibleForTesting - public static List> getLoadBalancingConfigsFromServiceConfig( - Map serviceConfig) { + public static List> getLoadBalancingConfigsFromServiceConfig( + Map serviceConfig) { /* schema as follows { "loadBalancingConfig": { @@ -325,11 +326,11 @@ public final class ServiceConfigUtil { "loadBalancingPolicy": "ROUND_ROBIN" // The deprecated policy key } */ - List> lbConfigs = new ArrayList<>(); + List> lbConfigs = new ArrayList<>(); if (serviceConfig.containsKey(SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY)) { - List configs = getList(serviceConfig, SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY); + List configs = getList(serviceConfig, SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY); for (Object config : configs) { - lbConfigs.add((Map) config); + lbConfigs.add((Map) config); } } if (lbConfigs.isEmpty()) { @@ -338,7 +339,7 @@ public final class ServiceConfigUtil { String policy = getString(serviceConfig, SERVICE_CONFIG_LOAD_BALANCING_POLICY_KEY); // Convert the policy to a config, so that the caller can handle them in the same way. policy = policy.toLowerCase(Locale.ROOT); - Map fakeConfig = + Map fakeConfig = Collections.singletonMap(policy, (Object) Collections.emptyMap()); lbConfigs.add(fakeConfig); } @@ -353,9 +354,9 @@ public final class ServiceConfigUtil { */ @SuppressWarnings("unchecked") public static LbConfig unwrapLoadBalancingConfig(Object lbConfig) { - Map map; + Map map; try { - map = (Map) lbConfig; + map = (Map) lbConfig; } catch (ClassCastException e) { ClassCastException ex = new ClassCastException("Invalid type. Config=" + lbConfig); ex.initCause(e); @@ -366,10 +367,10 @@ public final class ServiceConfigUtil { "There are " + map.size() + " fields in a LoadBalancingConfig object. Exactly one" + " is expected. Config=" + lbConfig); } - Map.Entry entry = map.entrySet().iterator().next(); - Map configValue; + Map.Entry entry = map.entrySet().iterator().next(); + Map configValue; try { - configValue = (Map) entry.getValue(); + configValue = (Map) entry.getValue(); } catch (ClassCastException e) { ClassCastException ex = new ClassCastException("Invalid value type. value=" + entry.getValue()); @@ -403,7 +404,7 @@ public final class ServiceConfigUtil { * Extracts the loadbalancer name from xds loadbalancer config. */ public static String getBalancerNameFromXdsConfig(LbConfig xdsConfig) { - Map map = xdsConfig.getRawConfigValue(); + Map map = xdsConfig.getRawConfigValue(); return getString(map, XDS_CONFIG_BALANCER_NAME_KEY); } @@ -412,7 +413,7 @@ public final class ServiceConfigUtil { */ @Nullable public static List getChildPolicyFromXdsConfig(LbConfig xdsConfig) { - Map map = xdsConfig.getRawConfigValue(); + Map map = xdsConfig.getRawConfigValue(); Object rawChildPolicies = map.get(XDS_CONFIG_CHILD_POLICY_KEY); if (rawChildPolicies != null) { return unwrapLoadBalancingConfigList(rawChildPolicies); @@ -425,7 +426,7 @@ public final class ServiceConfigUtil { */ @Nullable public static List getFallbackPolicyFromXdsConfig(LbConfig xdsConfig) { - Map map = xdsConfig.getRawConfigValue(); + Map map = xdsConfig.getRawConfigValue(); Object rawFallbackPolicies = map.get(XDS_CONFIG_FALLBACK_POLICY_KEY); if (rawFallbackPolicies != null) { return unwrapLoadBalancingConfigList(rawFallbackPolicies); @@ -438,7 +439,7 @@ public final class ServiceConfigUtil { */ @Nullable public static String getStickinessMetadataKeyFromServiceConfig( - Map serviceConfig) { + Map serviceConfig) { if (!serviceConfig.containsKey(SERVICE_CONFIG_STICKINESS_METADATA_KEY)) { return null; } @@ -449,11 +450,11 @@ public final class ServiceConfigUtil { * Gets a list from an object for the given key. */ @SuppressWarnings("unchecked") - static List getList(Map obj, String key) { + static List getList(Map obj, String key) { assert obj.containsKey(key); Object value = checkNotNull(obj.get(key), "no such key %s", key); if (value instanceof List) { - return (List) value; + return (List) value; } throw new ClassCastException( String.format("value %s for key %s in %s is not List", value, key, obj)); @@ -463,11 +464,11 @@ public final class ServiceConfigUtil { * Gets an object from an object for the given key. */ @SuppressWarnings("unchecked") - static Map getObject(Map obj, String key) { + static Map getObject(Map obj, String key) { assert obj.containsKey(key); Object value = checkNotNull(obj.get(key), "no such key %s", key); if (value instanceof Map) { - return (Map) value; + return (Map) value; } throw new ClassCastException( String.format("value %s for key %s in %s is not object", value, key, obj)); @@ -477,7 +478,7 @@ public final class ServiceConfigUtil { * Gets a double from an object for the given key. */ @SuppressWarnings("unchecked") - static Double getDouble(Map obj, String key) { + static Double getDouble(Map obj, String key) { assert obj.containsKey(key); Object value = checkNotNull(obj.get(key), "no such key %s", key); if (value instanceof Double) { @@ -491,7 +492,7 @@ public final class ServiceConfigUtil { * Gets a string from an object for the given key. */ @SuppressWarnings("unchecked") - static String getString(Map obj, String key) { + static String getString(Map obj, String key) { assert obj.containsKey(key); Object value = checkNotNull(obj.get(key), "no such key %s", key); if (value instanceof String) { @@ -505,7 +506,7 @@ public final class ServiceConfigUtil { * Gets a string from an object for the given index. */ @SuppressWarnings("unchecked") - static String getString(List list, int i) { + static String getString(List list, int i) { assert i >= 0 && i < list.size(); Object value = checkNotNull(list.get(i), "idx %s in %s is null", i, list); if (value instanceof String) { @@ -518,7 +519,7 @@ public final class ServiceConfigUtil { /** * Gets a boolean from an object for the given key. */ - static Boolean getBoolean(Map obj, String key) { + static Boolean getBoolean(Map obj, String key) { assert obj.containsKey(key); Object value = checkNotNull(obj.get(key), "no such key %s", key); if (value instanceof Boolean) { @@ -529,25 +530,25 @@ public final class ServiceConfigUtil { } @SuppressWarnings("unchecked") - private static List> checkObjectList(List rawList) { + private static List> checkObjectList(List rawList) { for (int i = 0; i < rawList.size(); i++) { if (!(rawList.get(i) instanceof Map)) { throw new ClassCastException( String.format("value %s for idx %d in %s is not object", rawList.get(i), i, rawList)); } } - return (List>) (List) rawList; + return (List>) rawList; } @SuppressWarnings("unchecked") - static List checkStringList(List rawList) { + static List checkStringList(List rawList) { for (int i = 0; i < rawList.size(); i++) { if (!(rawList.get(i) instanceof String)) { throw new ClassCastException( String.format("value %s for idx %d in %s is not string", rawList.get(i), i, rawList)); } } - return (List) (List) rawList; + return (List) rawList; } /** @@ -687,9 +688,9 @@ public final class ServiceConfigUtil { */ public static final class LbConfig { private final String policyName; - private final Map rawConfigValue; + private final Map rawConfigValue; - public LbConfig(String policyName, Map rawConfigValue) { + public LbConfig(String policyName, Map rawConfigValue) { this.policyName = checkNotNull(policyName, "policyName"); this.rawConfigValue = checkNotNull(rawConfigValue, "rawConfigValue"); } @@ -698,7 +699,7 @@ public final class ServiceConfigUtil { return policyName; } - public Map getRawConfigValue() { + public Map getRawConfigValue() { return rawConfigValue; } diff --git a/core/src/main/java/io/grpc/util/RoundRobinLoadBalancer.java b/core/src/main/java/io/grpc/util/RoundRobinLoadBalancer.java index e08065656d..ceb26d2838 100644 --- a/core/src/main/java/io/grpc/util/RoundRobinLoadBalancer.java +++ b/core/src/main/java/io/grpc/util/RoundRobinLoadBalancer.java @@ -94,8 +94,7 @@ final class RoundRobinLoadBalancer extends LoadBalancer { Set addedAddrs = setsDifference(latestAddrs, currentAddrs); Set removedAddrs = setsDifference(currentAddrs, latestAddrs); - Map serviceConfig = - attributes.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); + Map serviceConfig = attributes.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); if (serviceConfig != null) { String stickinessMetadataKey = ServiceConfigUtil.getStickinessMetadataKeyFromServiceConfig(serviceConfig); diff --git a/core/src/test/java/io/grpc/internal/AutoConfiguredLoadBalancerFactoryTest.java b/core/src/test/java/io/grpc/internal/AutoConfiguredLoadBalancerFactoryTest.java index da5e0e2154..b77c87559d 100644 --- a/core/src/test/java/io/grpc/internal/AutoConfiguredLoadBalancerFactoryTest.java +++ b/core/src/test/java/io/grpc/internal/AutoConfiguredLoadBalancerFactoryTest.java @@ -191,7 +191,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { @Test public void handleResolvedAddressGroups_shutsDownOldBalancer() { - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("loadBalancingPolicy", "round_robin"); Attributes serviceConfigAttrs = Attributes.newBuilder() @@ -237,7 +237,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { @Test public void handleResolvedAddressGroups_propagateLbConfigToDelegate() throws Exception { - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { \"setting1\": \"high\" } } ] }"); Attributes serviceConfigAttrs = Attributes.newBuilder() @@ -310,7 +310,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(helper); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { \"setting1\": \"high\" } } ] }"); lb.handleResolvedAddressGroups( Collections.emptyList(), @@ -333,7 +333,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(helper); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb2\": { \"setting1\": \"high\" } } ] }"); lb.handleResolvedAddressGroups( Collections.emptyList(), @@ -345,7 +345,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(null); verify(testLbBalancer2).handleResolvedAddressGroups( eq(Collections.emptyList()), attrsCaptor.capture()); - Map lbConfig = + Map lbConfig = attrsCaptor.getValue().get(LoadBalancer.ATTR_LOAD_BALANCING_CONFIG); assertThat(lbConfig).isEqualTo(Collections.singletonMap("setting1", "high")); assertThat(attrsCaptor.getValue().get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG)) @@ -357,7 +357,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = null; + Map serviceConfig = null; List servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){})); PolicySelection selection = lb.decideLoadBalancerProvider(servers, serviceConfig); @@ -374,7 +374,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) new AutoConfiguredLoadBalancerFactory("test_lb") .newLoadBalancer(new TestHelper()); - Map serviceConfig = null; + Map serviceConfig = null; List servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){})); PolicySelection selection = lb.decideLoadBalancerProvider(servers, serviceConfig); @@ -389,7 +389,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_oneBalancer_noServiceConfig_grpclb() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = null; + Map serviceConfig = null; List servers = Collections.singletonList( new EquivalentAddressGroup( @@ -407,7 +407,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbPolicy() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("loadBalancingPolicy", "round_robin"); List servers = Arrays.asList( @@ -431,7 +431,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbConfig() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"round_robin\": {} } ] }"); List servers = Arrays.asList( @@ -454,7 +454,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_grpclbConfigPropagated() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig( "{\"loadBalancingConfig\": [" + "{\"grpclb\": {\"childPolicy\": [ {\"pick_first\": {} } ] } }" @@ -477,7 +477,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_policyUnavailButGrpclbAddressPresent() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig( "{\"loadBalancingConfig\": [" + "{\"unavail\": {} }" @@ -506,7 +506,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) new AutoConfiguredLoadBalancerFactory( registry, GrpcUtil.DEFAULT_LB_POLICY).newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"grpclb\": {} } ] }"); List servers = Arrays.asList( @@ -541,7 +541,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) new AutoConfiguredLoadBalancerFactory( registry, GrpcUtil.DEFAULT_LB_POLICY).newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"grpclb\": {} } ] }"); List servers = Collections.singletonList( @@ -562,7 +562,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbPolicyOverridesDefault() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("loadBalancingPolicy", "round_robin"); List servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){})); @@ -578,7 +578,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbConfigOverridesDefault() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"round_robin\": {\"setting1\": \"high\"} } ] }"); List servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){})); @@ -595,7 +595,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbPolicyFailsOnUnknown() { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("loadBalancingPolicy", "MAGIC_BALANCER"); List servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){})); @@ -612,7 +612,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbConfigFailsOnUnknown() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"magic_balancer\": {} } ] }"); List servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){})); @@ -629,7 +629,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { public void decideLoadBalancerProvider_serviceConfigLbConfigSkipUnknown() throws Exception { AutoConfiguredLoadBalancer lb = (AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper()); - Map serviceConfig = + Map serviceConfig = parseConfig( "{\"loadBalancingConfig\": [ {\"magic_balancer\": {} }, {\"round_robin\": {} } ] }"); List servers = @@ -705,7 +705,7 @@ public class AutoConfiguredLoadBalancerFactoryTest { verifyNoMoreInteractions(channelLogger); - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("loadBalancingPolicy", "round_robin"); lb.handleResolvedAddressGroups(servers, Attributes.newBuilder() @@ -778,8 +778,8 @@ public class AutoConfiguredLoadBalancerFactoryTest { } @SuppressWarnings("unchecked") - private static Map parseConfig(String json) throws Exception { - return (Map) JsonParser.parse(json); + private static Map parseConfig(String json) throws Exception { + return (Map) JsonParser.parse(json); } private static class TestLoadBalancer extends ForwardingLoadBalancer { diff --git a/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java b/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java index 49caed04e7..1ee7784058 100644 --- a/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java +++ b/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java @@ -93,7 +93,7 @@ public class DnsNameResolverTest { @Rule public final MockitoRule mocks = MockitoJUnit.rule(); @Rule public final ExpectedException thrown = ExpectedException.none(); - private final Map serviceConfig = new LinkedHashMap<>(); + private final Map serviceConfig = new LinkedHashMap<>(); private static final int DEFAULT_PORT = 887; private final SynchronizationContext syncContext = new SynchronizationContext( @@ -656,7 +656,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_clientLanguageMatchesJava() { Map choice = new LinkedHashMap<>(); - List langs = new ArrayList<>(); + List langs = new ArrayList<>(); langs.add("java"); choice.put("clientLanguage", langs); choice.put("serviceConfig", serviceConfig); @@ -667,7 +667,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_clientLanguageDoesntMatchGo() { Map choice = new LinkedHashMap<>(); - List langs = new ArrayList<>(); + List langs = new ArrayList<>(); langs.add("go"); choice.put("clientLanguage", langs); choice.put("serviceConfig", serviceConfig); @@ -678,7 +678,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_clientLanguageCaseInsensitive() { Map choice = new LinkedHashMap<>(); - List langs = new ArrayList<>(); + List langs = new ArrayList<>(); langs.add("JAVA"); choice.put("clientLanguage", langs); choice.put("serviceConfig", serviceConfig); @@ -689,7 +689,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_clientLanguageMatchesEmtpy() { Map choice = new LinkedHashMap<>(); - List langs = new ArrayList<>(); + List langs = new ArrayList<>(); choice.put("clientLanguage", langs); choice.put("serviceConfig", serviceConfig); @@ -699,7 +699,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_clientLanguageMatchesMulti() { Map choice = new LinkedHashMap<>(); - List langs = new ArrayList<>(); + List langs = new ArrayList<>(); langs.add("go"); langs.add("java"); choice.put("clientLanguage", langs); @@ -825,7 +825,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_hostnameMatches() { Map choice = new LinkedHashMap<>(); - List hosts = new ArrayList<>(); + List hosts = new ArrayList<>(); hosts.add("localhost"); choice.put("clientHostname", hosts); choice.put("serviceConfig", serviceConfig); @@ -836,7 +836,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_hostnameDoesntMatch() { Map choice = new LinkedHashMap<>(); - List hosts = new ArrayList<>(); + List hosts = new ArrayList<>(); hosts.add("localhorse"); choice.put("clientHostname", hosts); choice.put("serviceConfig", serviceConfig); @@ -847,7 +847,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_clientLanguageCaseSensitive() { Map choice = new LinkedHashMap<>(); - List hosts = new ArrayList<>(); + List hosts = new ArrayList<>(); hosts.add("LOCALHOST"); choice.put("clientHostname", hosts); choice.put("serviceConfig", serviceConfig); @@ -858,7 +858,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_hostnameMatchesEmtpy() { Map choice = new LinkedHashMap<>(); - List hosts = new ArrayList<>(); + List hosts = new ArrayList<>(); choice.put("clientHostname", hosts); choice.put("serviceConfig", serviceConfig); @@ -868,7 +868,7 @@ public class DnsNameResolverTest { @Test public void maybeChooseServiceConfig_hostnameMatchesMulti() { Map choice = new LinkedHashMap<>(); - List hosts = new ArrayList<>(); + List hosts = new ArrayList<>(); hosts.add("localhorse"); hosts.add("localhost"); choice.put("clientHostname", hosts); @@ -883,7 +883,7 @@ public class DnsNameResolverTest { txtRecords.add("some_record"); txtRecords.add("_grpc_config=[]"); - List> results = DnsNameResolver.parseTxtResults(txtRecords); + List> results = DnsNameResolver.parseTxtResults(txtRecords); assertThat(results).isEmpty(); } @@ -898,7 +898,7 @@ public class DnsNameResolverTest { txtRecords.add("some_record"); txtRecords.add("grpc_config={}"); - List> results = DnsNameResolver.parseTxtResults(txtRecords); + List> results = DnsNameResolver.parseTxtResults(txtRecords); assertThat(results).isEmpty(); } finally { @@ -916,7 +916,7 @@ public class DnsNameResolverTest { txtRecords.add("some_record"); txtRecords.add("grpc_config=[\"bogus\"]"); - List> results = DnsNameResolver.parseTxtResults(txtRecords); + List> results = DnsNameResolver.parseTxtResults(txtRecords); assertThat(results).isEmpty(); } finally { @@ -936,7 +936,7 @@ public class DnsNameResolverTest { txtRecords.add("grpc_config=[{}, {}]"); // 2 records txtRecords.add("grpc_config=[{\"\":{}}]"); // 1 record - List> results = DnsNameResolver.parseTxtResults(txtRecords); + List> results = DnsNameResolver.parseTxtResults(txtRecords); assertThat(results).hasSize(2 + 1); } finally { diff --git a/core/src/test/java/io/grpc/internal/HedgingPolicyTest.java b/core/src/test/java/io/grpc/internal/HedgingPolicyTest.java index 37e82af46b..a0c50d5b5c 100644 --- a/core/src/test/java/io/grpc/internal/HedgingPolicyTest.java +++ b/core/src/test/java/io/grpc/internal/HedgingPolicyTest.java @@ -57,7 +57,7 @@ public class HedgingPolicyTest { assertTrue(serviceConfigObj instanceof Map); @SuppressWarnings("unchecked") - Map serviceConfig = (Map) serviceConfigObj; + Map serviceConfig = (Map) serviceConfigObj; ServiceConfigInterceptor serviceConfigInterceptor = new ServiceConfigInterceptor( /* retryEnabled = */ true, /* maxRetryAttemptsLimit = */ 3, @@ -129,7 +129,7 @@ public class HedgingPolicyTest { assertTrue(serviceConfigObj instanceof Map); @SuppressWarnings("unchecked") - Map serviceConfig = (Map) serviceConfigObj; + Map serviceConfig = (Map) serviceConfigObj; ServiceConfigInterceptor serviceConfigInterceptor = new ServiceConfigInterceptor( /* retryEnabled = */ false, /* maxRetryAttemptsLimit = */ 3, diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java index e31d2e3735..4dae2f1d07 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java @@ -889,9 +889,9 @@ public class ManagedChannelImplTest { ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(null); verify(mockLoadBalancer).handleResolvedAddressGroups( eq(ImmutableList.of()), attrsCaptor.capture()); - Map lbConfig = + Map lbConfig = attrsCaptor.getValue().get(LoadBalancer.ATTR_LOAD_BALANCING_CONFIG); - assertEquals(ImmutableMap.of("setting1", "high"), lbConfig); + assertEquals(ImmutableMap.of("setting1", "high"), lbConfig); assertSame( serviceConfig, attrsCaptor.getValue().get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG)); } diff --git a/core/src/test/java/io/grpc/internal/RetryPolicyTest.java b/core/src/test/java/io/grpc/internal/RetryPolicyTest.java index e9296b96b9..aeb21b03ae 100644 --- a/core/src/test/java/io/grpc/internal/RetryPolicyTest.java +++ b/core/src/test/java/io/grpc/internal/RetryPolicyTest.java @@ -60,7 +60,7 @@ public class RetryPolicyTest { assertTrue(serviceConfigObj instanceof Map); @SuppressWarnings("unchecked") - Map serviceConfig = (Map) serviceConfigObj; + Map serviceConfig = (Map) serviceConfigObj; ServiceConfigInterceptor serviceConfigInterceptor = new ServiceConfigInterceptor( /* retryEnabled = */ true, /* maxRetryAttemptsLimit = */ 4, @@ -138,7 +138,7 @@ public class RetryPolicyTest { assertTrue(serviceConfigObj instanceof Map); @SuppressWarnings("unchecked") - Map serviceConfig = (Map) serviceConfigObj; + Map serviceConfig = (Map) serviceConfigObj; ServiceConfigInterceptor serviceConfigInterceptor = new ServiceConfigInterceptor( /* retryEnabled = */ false, /* maxRetryAttemptsLimit = */ 4, @@ -175,7 +175,7 @@ public class RetryPolicyTest { assertTrue(serviceConfigObj instanceof Map); @SuppressWarnings("unchecked") - Map serviceConfig = (Map) serviceConfigObj; + Map serviceConfig = (Map) serviceConfigObj; Throttle throttle = ServiceConfigUtil.getThrottlePolicy(serviceConfig); assertEquals(new Throttle(10f, 0.1f), throttle); diff --git a/core/src/test/java/io/grpc/util/RoundRobinLoadBalancerTest.java b/core/src/test/java/io/grpc/util/RoundRobinLoadBalancerTest.java index 7f4b39d7bc..44087d6d67 100644 --- a/core/src/test/java/io/grpc/util/RoundRobinLoadBalancerTest.java +++ b/core/src/test/java/io/grpc/util/RoundRobinLoadBalancerTest.java @@ -470,7 +470,7 @@ public class RoundRobinLoadBalancerTest { @Test public void stickinessEnabled_withStickyHeader() { - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("stickinessMetadataKey", "my-sticky-key"); Attributes attributes = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig).build(); @@ -500,7 +500,7 @@ public class RoundRobinLoadBalancerTest { @Test public void stickinessEnabled_withDifferentStickyHeaders() { - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("stickinessMetadataKey", "my-sticky-key"); Attributes attributes = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig).build(); @@ -545,7 +545,7 @@ public class RoundRobinLoadBalancerTest { @Test public void stickiness_goToTransientFailure_pick_backToReady() { - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("stickinessMetadataKey", "my-sticky-key"); Attributes attributes = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig).build(); @@ -593,7 +593,7 @@ public class RoundRobinLoadBalancerTest { @Test public void stickiness_goToTransientFailure_backToReady_pick() { - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("stickinessMetadataKey", "my-sticky-key"); Attributes attributes = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig).build(); @@ -647,7 +647,7 @@ public class RoundRobinLoadBalancerTest { @Test public void stickiness_oneSubchannelShutdown() { - Map serviceConfig = new HashMap<>(); + Map serviceConfig = new HashMap<>(); serviceConfig.put("stickinessMetadataKey", "my-sticky-key"); Attributes attributes = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig).build(); @@ -703,14 +703,14 @@ public class RoundRobinLoadBalancerTest { @Test public void stickiness_resolveTwice_metadataKeyChanged() { - Map serviceConfig1 = new HashMap<>(); + Map serviceConfig1 = new HashMap<>(); serviceConfig1.put("stickinessMetadataKey", "my-sticky-key1"); Attributes attributes1 = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig1).build(); loadBalancer.handleResolvedAddressGroups(servers, attributes1); Map stickinessMap1 = loadBalancer.getStickinessMapForTest(); - Map serviceConfig2 = new HashMap<>(); + Map serviceConfig2 = new HashMap<>(); serviceConfig2.put("stickinessMetadataKey", "my-sticky-key2"); Attributes attributes2 = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig2).build(); @@ -722,7 +722,7 @@ public class RoundRobinLoadBalancerTest { @Test public void stickiness_resolveTwice_metadataKeyUnChanged() { - Map serviceConfig1 = new HashMap<>(); + Map serviceConfig1 = new HashMap<>(); serviceConfig1.put("stickinessMetadataKey", "my-sticky-key1"); Attributes attributes1 = Attributes.newBuilder() .set(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG, serviceConfig1).build(); diff --git a/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java b/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java index 181d05657a..7ad6d020ea 100644 --- a/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java +++ b/grpclb/src/main/java/io/grpc/grpclb/GrpclbLoadBalancer.java @@ -100,7 +100,7 @@ class GrpclbLoadBalancer extends LoadBalancer { newLbAddressGroups = Collections.unmodifiableList(newLbAddressGroups); newBackendServers = Collections.unmodifiableList(newBackendServers); - Map rawLbConfigValue = attributes.get(ATTR_LOAD_BALANCING_CONFIG); + Map rawLbConfigValue = attributes.get(ATTR_LOAD_BALANCING_CONFIG); Mode newMode = retrieveModeFromLbConfig(rawLbConfigValue, helper.getChannelLogger()); if (!mode.equals(newMode)) { mode = newMode; @@ -112,7 +112,7 @@ class GrpclbLoadBalancer extends LoadBalancer { @VisibleForTesting static Mode retrieveModeFromLbConfig( - @Nullable Map rawLbConfigValue, ChannelLogger channelLogger) { + @Nullable Map rawLbConfigValue, ChannelLogger channelLogger) { try { if (rawLbConfigValue == null) { return DEFAULT_MODE; diff --git a/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java b/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java index 1232c7d44d..1f066193dd 100644 --- a/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java +++ b/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java @@ -2167,8 +2167,8 @@ public class GrpclbLoadBalancerTest { } @SuppressWarnings("unchecked") - private static Map parseJsonObject(String json) throws Exception { - return (Map) JsonParser.parse(json); + private static Map parseJsonObject(String json) throws Exception { + return (Map) JsonParser.parse(json); } private static class ServerEntry { diff --git a/services/src/main/java/io/grpc/services/HealthCheckingLoadBalancerFactory.java b/services/src/main/java/io/grpc/services/HealthCheckingLoadBalancerFactory.java index c3f9445c6a..ecf9c3432c 100644 --- a/services/src/main/java/io/grpc/services/HealthCheckingLoadBalancerFactory.java +++ b/services/src/main/java/io/grpc/services/HealthCheckingLoadBalancerFactory.java @@ -169,7 +169,7 @@ final class HealthCheckingLoadBalancerFactory extends Factory { @Override public void handleResolvedAddressGroups( List servers, Attributes attributes) { - Map serviceConfig = + Map serviceConfig = attributes.get(GrpcAttributes.NAME_RESOLVER_SERVICE_CONFIG); String serviceName = ServiceConfigUtil.getHealthCheckedServiceName(serviceConfig); helper.setHealthCheckedService(serviceName); diff --git a/services/src/test/java/io/grpc/services/HealthCheckingLoadBalancerFactoryTest.java b/services/src/test/java/io/grpc/services/HealthCheckingLoadBalancerFactoryTest.java index bcae163c50..c5d5d2c0e4 100644 --- a/services/src/test/java/io/grpc/services/HealthCheckingLoadBalancerFactoryTest.java +++ b/services/src/test/java/io/grpc/services/HealthCheckingLoadBalancerFactoryTest.java @@ -935,8 +935,7 @@ public class HealthCheckingLoadBalancerFactoryTest { @Test public void getHealthCheckedServiceName_noHealthCheckConfig() { - assertThat(ServiceConfigUtil.getHealthCheckedServiceName(new HashMap())) - .isNull(); + assertThat(ServiceConfigUtil.getHealthCheckedServiceName(new HashMap())).isNull(); } @Test diff --git a/xds/src/main/java/io/grpc/xds/XdsLoadBalancer.java b/xds/src/main/java/io/grpc/xds/XdsLoadBalancer.java index 9a8e648a91..ddaace3819 100644 --- a/xds/src/main/java/io/grpc/xds/XdsLoadBalancer.java +++ b/xds/src/main/java/io/grpc/xds/XdsLoadBalancer.java @@ -52,7 +52,7 @@ final class XdsLoadBalancer extends LoadBalancer { Attributes.Key.create("io.grpc.xds.XdsLoadBalancer.stateInfo"); private static final LbConfig DEFAULT_FALLBACK_POLICY = - new LbConfig("round_robin", ImmutableMap.of()); + new LbConfig("round_robin", ImmutableMap.of()); private final SubchannelStore subchannelStore; private final Helper helper; @@ -89,7 +89,7 @@ final class XdsLoadBalancer extends LoadBalancer { @Override public void handleResolvedAddressGroups( List servers, Attributes attributes) { - Map newRawLbConfig = checkNotNull( + Map newRawLbConfig = checkNotNull( attributes.get(ATTR_LOAD_BALANCING_CONFIG), "ATTR_LOAD_BALANCING_CONFIG not available"); LbConfig newLbConfig = ServiceConfigUtil.unwrapLoadBalancingConfig(newRawLbConfig); fallbackPolicy = selectFallbackPolicy(newLbConfig, lbRegistry); diff --git a/xds/src/test/java/io/grpc/xds/FallbackManagerTest.java b/xds/src/test/java/io/grpc/xds/FallbackManagerTest.java index f0456b509e..56e04c41f8 100644 --- a/xds/src/test/java/io/grpc/xds/FallbackManagerTest.java +++ b/xds/src/test/java/io/grpc/xds/FallbackManagerTest.java @@ -106,7 +106,7 @@ public class FallbackManagerTest { doReturn(fakeClock.getScheduledExecutorService()).when(helper).getScheduledExecutorService(); doReturn(channelLogger).when(helper).getChannelLogger(); fallbackManager = new FallbackManager(helper, new SubchannelStoreImpl(), lbRegistry); - fallbackPolicy = new LbConfig("test_policy", new HashMap()); + fallbackPolicy = new LbConfig("test_policy", new HashMap()); lbRegistry.register(fakeLbProvider); } diff --git a/xds/src/test/java/io/grpc/xds/XdsLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/XdsLoadBalancerTest.java index 756ea8dd4f..690205ecc4 100644 --- a/xds/src/test/java/io/grpc/xds/XdsLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsLoadBalancerTest.java @@ -311,7 +311,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -328,7 +328,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -352,7 +352,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -366,7 +366,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -388,7 +388,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -404,7 +404,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -426,7 +426,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -442,7 +442,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -463,7 +463,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -477,7 +477,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig2 = (Map) JsonParser.parse(lbConfigRaw); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs); @@ -588,7 +588,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"supported_1\" : { \"supported_1_option\" : \"yes\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); return Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); } @@ -600,7 +600,7 @@ public class XdsLoadBalancerTest { + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}]" + "}}"; @SuppressWarnings("unchecked") - Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); + Map lbConfig = (Map) JsonParser.parse(lbConfigRaw); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); lb.handleResolvedAddressGroups(Collections.emptyList(), attrs);