@Test public void getClusterMembers_k8s_incorrectCount() throws Exception { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Current Pod ID 2 indicates a cluster size greater than the expected 2."); K8S_INSTANCE.getClusterMembers(2); }
public List<String> getClusterMembers(int expectedClusterSize) { Matcher podTemplateMatcher = getHostnameComponents(); int ourPodId = Integer.parseInt(podTemplateMatcher.group("podId")); Preconditions.checkArgument(ourPodId < expectedClusterSize, "Current Pod ID %s indicates a cluster size greater than the expected %s.", ourPodId, expectedClusterSize); String serviceName = podTemplateMatcher.group("service"); String namespace = podTemplateMatcher.group("namespace"); return IntStream.range(0, expectedClusterSize) .mapToObj(podId -> getPodHostname(serviceName, podId, namespace)) .collect(Collectors.toList()); }
KubernetesHostnames { public List<String> getClusterMembers(int expectedClusterSize) { Matcher podTemplateMatcher = getHostnameComponents(); int ourPodId = Integer.parseInt(podTemplateMatcher.group("podId")); Preconditions.checkArgument(ourPodId < expectedClusterSize, "Current Pod ID %s indicates a cluster size greater than the expected %s.", ourPodId, expectedClusterSize); String serviceName = podTemplateMatcher.group("service"); String namespace = podTemplateMatcher.group("namespace"); return IntStream.range(0, expectedClusterSize) .mapToObj(podId -> getPodHostname(serviceName, podId, namespace)) .collect(Collectors.toList()); } }
KubernetesHostnames { public List<String> getClusterMembers(int expectedClusterSize) { Matcher podTemplateMatcher = getHostnameComponents(); int ourPodId = Integer.parseInt(podTemplateMatcher.group("podId")); Preconditions.checkArgument(ourPodId < expectedClusterSize, "Current Pod ID %s indicates a cluster size greater than the expected %s.", ourPodId, expectedClusterSize); String serviceName = podTemplateMatcher.group("service"); String namespace = podTemplateMatcher.group("namespace"); return IntStream.range(0, expectedClusterSize) .mapToObj(podId -> getPodHostname(serviceName, podId, namespace)) .collect(Collectors.toList()); } @VisibleForTesting  KubernetesHostnames(Supplier<String> currentHostnameSupplier); }
KubernetesHostnames { public List<String> getClusterMembers(int expectedClusterSize) { Matcher podTemplateMatcher = getHostnameComponents(); int ourPodId = Integer.parseInt(podTemplateMatcher.group("podId")); Preconditions.checkArgument(ourPodId < expectedClusterSize, "Current Pod ID %s indicates a cluster size greater than the expected %s.", ourPodId, expectedClusterSize); String serviceName = podTemplateMatcher.group("service"); String namespace = podTemplateMatcher.group("namespace"); return IntStream.range(0, expectedClusterSize) .mapToObj(podId -> getPodHostname(serviceName, podId, namespace)) .collect(Collectors.toList()); } @VisibleForTesting  KubernetesHostnames(Supplier<String> currentHostnameSupplier); String getCurrentHostname(); List<String> getClusterMembers(int expectedClusterSize); }
KubernetesHostnames { public List<String> getClusterMembers(int expectedClusterSize) { Matcher podTemplateMatcher = getHostnameComponents(); int ourPodId = Integer.parseInt(podTemplateMatcher.group("podId")); Preconditions.checkArgument(ourPodId < expectedClusterSize, "Current Pod ID %s indicates a cluster size greater than the expected %s.", ourPodId, expectedClusterSize); String serviceName = podTemplateMatcher.group("service"); String namespace = podTemplateMatcher.group("namespace"); return IntStream.range(0, expectedClusterSize) .mapToObj(podId -> getPodHostname(serviceName, podId, namespace)) .collect(Collectors.toList()); } @VisibleForTesting  KubernetesHostnames(Supplier<String> currentHostnameSupplier); String getCurrentHostname(); List<String> getClusterMembers(int expectedClusterSize); static final KubernetesHostnames INSTANCE; }