Specify Locale to toLowerCase and lint fixes

This commit is contained in:
Eric Anderson 2018-12-06 15:35:01 -08:00
parent 4631c0c7e8
commit de9bc0bcf1
5 changed files with 15 additions and 11 deletions

View File

@ -23,6 +23,7 @@ import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@ -204,7 +205,7 @@ public abstract class AbstractConfigurationBuilder<T extends Configuration>
}
private static String commandLineFlag(Param param) {
String name = param.getName().toLowerCase();
String name = param.getName().toLowerCase(Locale.ROOT);
String type = (!param.getType().isEmpty() ? '=' + param.getType() : "");
return "--" + name + type;
}

View File

@ -189,7 +189,7 @@ public final class AutoConfiguredLoadBalancerFactory extends LoadBalancer.Factor
throws PolicyException {
// Check for balancer addresses
boolean haveBalancerAddress = false;
List<EquivalentAddressGroup> backendAddrs = new ArrayList<EquivalentAddressGroup>();
List<EquivalentAddressGroup> backendAddrs = new ArrayList<>();
for (EquivalentAddressGroup s : servers) {
if (s.getAttributes().get(GrpcAttributes.ATTR_LB_ADDR_AUTHORITY) != null) {
haveBalancerAddress = true;

View File

@ -26,6 +26,7 @@ import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
@ -320,7 +321,7 @@ public final class ServiceConfigUtil {
"loadBalancingPolicy": "ROUND_ROBIN" // The deprecated policy key
}
*/
List<Map<String, Object>> lbConfigs = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> lbConfigs = new ArrayList<>();
if (serviceConfig.containsKey(SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY)) {
List<Object> configs = getList(serviceConfig, SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY);
for (Object config : configs) {
@ -332,7 +333,7 @@ public final class ServiceConfigUtil {
if (serviceConfig.containsKey(SERVICE_CONFIG_LOAD_BALANCING_POLICY_KEY)) {
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();
policy = policy.toLowerCase(Locale.ROOT);
Map<String, Object> fakeConfig =
Collections.singletonMap(policy, (Object) Collections.emptyMap());
lbConfigs.add(fakeConfig);

View File

@ -399,7 +399,7 @@ public class AutoConfiguredLoadBalancerFactoryTest {
assertThat(selection.provider).isInstanceOf(FakeRoundRobinLoadBalancerProvider.class);
// Balancer addresses are filtered out in the server list passed to round_robin
assertThat(selection.serverList).isEqualTo(Collections.singletonList(servers.get(1)));
assertThat(selection.serverList).containsExactly(servers.get(1));
assertThat(selection.config).isNull();
verifyNoMoreInteractions(channelLogger);
}
@ -424,7 +424,8 @@ public class AutoConfiguredLoadBalancerFactoryTest {
lb.decideLoadBalancerProvider(servers, serviceConfig);
fail("Should throw");
} catch (PolicyException e) {
assertThat(e.getMessage())
assertThat(e)
.hasMessageThat()
.isEqualTo("Received ONLY balancer addresses but grpclb runtime is missing");
}
}
@ -433,7 +434,7 @@ public class AutoConfiguredLoadBalancerFactoryTest {
public void decideLoadBalancerProvider_serviceConfigLbPolicyOverridesDefault() throws Exception {
AutoConfiguredLoadBalancer lb =
(AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper());
Map<String, Object> serviceConfig = new HashMap<String, Object>();
Map<String, Object> serviceConfig = new HashMap<>();
serviceConfig.put("loadBalancingPolicy", "round_robin");
List<EquivalentAddressGroup> servers =
Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){}));
@ -466,7 +467,7 @@ public class AutoConfiguredLoadBalancerFactoryTest {
public void decideLoadBalancerProvider_serviceConfigLbPolicyFailsOnUnknown() {
AutoConfiguredLoadBalancer lb =
(AutoConfiguredLoadBalancer) lbf.newLoadBalancer(new TestHelper());
Map<String, Object> serviceConfig = new HashMap<String, Object>();
Map<String, Object> serviceConfig = new HashMap<>();
serviceConfig.put("loadBalancingPolicy", "MAGIC_BALANCER");
List<EquivalentAddressGroup> servers =
Collections.singletonList(new EquivalentAddressGroup(new SocketAddress(){}));
@ -474,7 +475,7 @@ public class AutoConfiguredLoadBalancerFactoryTest {
lb.decideLoadBalancerProvider(servers, serviceConfig);
fail();
} catch (PolicyException e) {
assertThat(e.getMessage()).isEqualTo(
assertThat(e).hasMessageThat().isEqualTo(
"None of [magic_balancer] specified by Service Config are available.");
}
}
@ -491,7 +492,7 @@ public class AutoConfiguredLoadBalancerFactoryTest {
lb.decideLoadBalancerProvider(servers, serviceConfig);
fail();
} catch (PolicyException e) {
assertThat(e.getMessage()).isEqualTo(
assertThat(e).hasMessageThat().isEqualTo(
"None of [magic_balancer] specified by Service Config are available.");
}
}

View File

@ -37,6 +37,7 @@ import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@ -368,7 +369,7 @@ public final class Http2Client {
private static String validTestCasesHelpText() {
StringBuilder builder = new StringBuilder();
for (Http2TestCases testCase : Http2TestCases.values()) {
String strTestcase = testCase.name().toLowerCase();
String strTestcase = testCase.name().toLowerCase(Locale.ROOT);
builder.append("\n ")
.append(strTestcase)
.append(": ")