@Test public void maybeChooseServiceConfig_clientLanguageCaseSensitive() { Map<String, Object> choice = new LinkedHashMap<String, Object>(); List<Object> hosts = new ArrayList<>(); hosts.add("LOCALHOST"); choice.put("clientHostname", hosts); choice.put("serviceConfig", serviceConfig); assertNull(DnsNameResolver.maybeChooseServiceConfig(choice, new Random(), "localhost")); }
@Nullable @SuppressWarnings("BetaApi") @VisibleForTesting static Map<String, Object> maybeChooseServiceConfig( Map<String, Object> choice, Random random, String hostname) { for (Entry<String, ?> entry : choice.entrySet()) { Verify.verify(SERVICE_CONFIG_CHOICE_KEYS.contains(entry.getKey()), "Bad key: %s", entry); } List<String> clientLanguages = getClientLanguagesFromChoice(choice); if (clientLanguages != null && !clientLanguages.isEmpty()) { boolean javaPresent = false; for (String lang : clientLanguages) { if ("java".equalsIgnoreCase(lang)) { javaPresent = true; break; } } if (!javaPresent) { return null; } } Double percentage = getPercentageFromChoice(choice); if (percentage != null) { int pct = percentage.intValue(); Verify.verify(pct >= 0 && pct <= 100, "Bad percentage: %s", percentage); if (random.nextInt(100) >= pct) { return null; } } List<String> clientHostnames = getHostnamesFromChoice(choice); if (clientHostnames != null && !clientHostnames.isEmpty()) { boolean hostnamePresent = false; for (String clientHostname : clientHostnames) { if (clientHostname.equals(hostname)) { hostnamePresent = true; break; } } if (!hostnamePresent) { return null; } } return ServiceConfigUtil.getObject(choice, SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY); }
DnsNameResolver extends NameResolver { @Nullable @SuppressWarnings("BetaApi") @VisibleForTesting static Map<String, Object> maybeChooseServiceConfig( Map<String, Object> choice, Random random, String hostname) { for (Entry<String, ?> entry : choice.entrySet()) { Verify.verify(SERVICE_CONFIG_CHOICE_KEYS.contains(entry.getKey()), "Bad key: %s", entry); } List<String> clientLanguages = getClientLanguagesFromChoice(choice); if (clientLanguages != null && !clientLanguages.isEmpty()) { boolean javaPresent = false; for (String lang : clientLanguages) { if ("java".equalsIgnoreCase(lang)) { javaPresent = true; break; } } if (!javaPresent) { return null; } } Double percentage = getPercentageFromChoice(choice); if (percentage != null) { int pct = percentage.intValue(); Verify.verify(pct >= 0 && pct <= 100, "Bad percentage: %s", percentage); if (random.nextInt(100) >= pct) { return null; } } List<String> clientHostnames = getHostnamesFromChoice(choice); if (clientHostnames != null && !clientHostnames.isEmpty()) { boolean hostnamePresent = false; for (String clientHostname : clientHostnames) { if (clientHostname.equals(hostname)) { hostnamePresent = true; break; } } if (!hostnamePresent) { return null; } } return ServiceConfigUtil.getObject(choice, SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY); } }
DnsNameResolver extends NameResolver { @Nullable @SuppressWarnings("BetaApi") @VisibleForTesting static Map<String, Object> maybeChooseServiceConfig( Map<String, Object> choice, Random random, String hostname) { for (Entry<String, ?> entry : choice.entrySet()) { Verify.verify(SERVICE_CONFIG_CHOICE_KEYS.contains(entry.getKey()), "Bad key: %s", entry); } List<String> clientLanguages = getClientLanguagesFromChoice(choice); if (clientLanguages != null && !clientLanguages.isEmpty()) { boolean javaPresent = false; for (String lang : clientLanguages) { if ("java".equalsIgnoreCase(lang)) { javaPresent = true; break; } } if (!javaPresent) { return null; } } Double percentage = getPercentageFromChoice(choice); if (percentage != null) { int pct = percentage.intValue(); Verify.verify(pct >= 0 && pct <= 100, "Bad percentage: %s", percentage); if (random.nextInt(100) >= pct) { return null; } } List<String> clientHostnames = getHostnamesFromChoice(choice); if (clientHostnames != null && !clientHostnames.isEmpty()) { boolean hostnamePresent = false; for (String clientHostname : clientHostnames) { if (clientHostname.equals(hostname)) { hostnamePresent = true; break; } } if (!hostnamePresent) { return null; } } return ServiceConfigUtil.getObject(choice, SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY); } DnsNameResolver(@Nullable String nsAuthority, String name, Attributes params,
      Resource<Executor> executorResource, ProxyDetector proxyDetector,
      Stopwatch stopwatch, boolean isAndroid); }
DnsNameResolver extends NameResolver { @Nullable @SuppressWarnings("BetaApi") @VisibleForTesting static Map<String, Object> maybeChooseServiceConfig( Map<String, Object> choice, Random random, String hostname) { for (Entry<String, ?> entry : choice.entrySet()) { Verify.verify(SERVICE_CONFIG_CHOICE_KEYS.contains(entry.getKey()), "Bad key: %s", entry); } List<String> clientLanguages = getClientLanguagesFromChoice(choice); if (clientLanguages != null && !clientLanguages.isEmpty()) { boolean javaPresent = false; for (String lang : clientLanguages) { if ("java".equalsIgnoreCase(lang)) { javaPresent = true; break; } } if (!javaPresent) { return null; } } Double percentage = getPercentageFromChoice(choice); if (percentage != null) { int pct = percentage.intValue(); Verify.verify(pct >= 0 && pct <= 100, "Bad percentage: %s", percentage); if (random.nextInt(100) >= pct) { return null; } } List<String> clientHostnames = getHostnamesFromChoice(choice); if (clientHostnames != null && !clientHostnames.isEmpty()) { boolean hostnamePresent = false; for (String clientHostname : clientHostnames) { if (clientHostname.equals(hostname)) { hostnamePresent = true; break; } } if (!hostnamePresent) { return null; } } return ServiceConfigUtil.getObject(choice, SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY); } DnsNameResolver(@Nullable String nsAuthority, String name, Attributes params,
      Resource<Executor> executorResource, ProxyDetector proxyDetector,
      Stopwatch stopwatch, boolean isAndroid); @Override final String getServiceAuthority(); @Override final synchronized void start(Listener listener); @Override final synchronized void refresh(); @Override final synchronized void shutdown(); }
DnsNameResolver extends NameResolver { @Nullable @SuppressWarnings("BetaApi") @VisibleForTesting static Map<String, Object> maybeChooseServiceConfig( Map<String, Object> choice, Random random, String hostname) { for (Entry<String, ?> entry : choice.entrySet()) { Verify.verify(SERVICE_CONFIG_CHOICE_KEYS.contains(entry.getKey()), "Bad key: %s", entry); } List<String> clientLanguages = getClientLanguagesFromChoice(choice); if (clientLanguages != null && !clientLanguages.isEmpty()) { boolean javaPresent = false; for (String lang : clientLanguages) { if ("java".equalsIgnoreCase(lang)) { javaPresent = true; break; } } if (!javaPresent) { return null; } } Double percentage = getPercentageFromChoice(choice); if (percentage != null) { int pct = percentage.intValue(); Verify.verify(pct >= 0 && pct <= 100, "Bad percentage: %s", percentage); if (random.nextInt(100) >= pct) { return null; } } List<String> clientHostnames = getHostnamesFromChoice(choice); if (clientHostnames != null && !clientHostnames.isEmpty()) { boolean hostnamePresent = false; for (String clientHostname : clientHostnames) { if (clientHostname.equals(hostname)) { hostnamePresent = true; break; } } if (!hostnamePresent) { return null; } } return ServiceConfigUtil.getObject(choice, SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY); } DnsNameResolver(@Nullable String nsAuthority, String name, Attributes params,
      Resource<Executor> executorResource, ProxyDetector proxyDetector,
      Stopwatch stopwatch, boolean isAndroid); @Override final String getServiceAuthority(); @Override final synchronized void start(Listener listener); @Override final synchronized void refresh(); @Override final synchronized void shutdown();  }