PropertiesEndpointGroup extends DynamicEndpointGroup { public static PropertiesEndpointGroupBuilder builder(ClassLoader classLoader, String resourceName, String endpointKeyPrefix) { requireNonNull(classLoader, "classLoader"); requireNonNull(resourceName, "resourceName"); requireNonNull(endpointKeyPrefix, "endpointKeyPrefix"); return new PropertiesEndpointGroupBuilder(classLoader, resourceName, endpointKeyPrefix); } PropertiesEndpointGroup(EndpointSelectionStrategy selectionStrategy, List<Endpoint> endpoints);   PropertiesEndpointGroup(EndpointSelectionStrategy selectionStrategy,
                            Path path, String endpointKeyPrefix, int defaultPort); static PropertiesEndpointGroup of(ClassLoader classLoader, String resourceName,
                                             String endpointKeyPrefix); static PropertiesEndpointGroup of(Properties properties, String endpointKeyPrefix); static PropertiesEndpointGroup of(Path path, String endpointKeyPrefix); static PropertiesEndpointGroupBuilder builder(ClassLoader classLoader, String resourceName,
                                                         String endpointKeyPrefix); static PropertiesEndpointGroupBuilder builder(Properties properties, String endpointKeyPrefix); static PropertiesEndpointGroupBuilder builder(Path path, String endpointKeyPrefix);  }
@Test public void propertiesWithDefaultPort() { final PropertiesEndpointGroup endpointGroupA = PropertiesEndpointGroup.builder(PROPS, "serverA.hosts") .defaultPort(80) .build(); final PropertiesEndpointGroup endpointGroupB = PropertiesEndpointGroup.builder(PROPS, "serverB.hosts") .defaultPort(8080) .build(); assertThat(endpointGroupA.endpoints()).containsExactlyInAnyOrder(Endpoint.parse("127.0.0.1:8080"), Endpoint.parse("127.0.0.1:8081"), Endpoint.parse("127.0.0.1:80")); assertThat(endpointGroupB.endpoints()).containsExactlyInAnyOrder(Endpoint.parse("127.0.0.1:8082"), Endpoint.parse("127.0.0.1:8083")); }
@Test public void resourceWithDefaultPort() { final PropertiesEndpointGroup endpointGroupA = PropertiesEndpointGroup.builder(getClass().getClassLoader(), "server-list.properties", "serverA.hosts") .defaultPort(80) .build(); final PropertiesEndpointGroup endpointGroupB = PropertiesEndpointGroup.builder(getClass().getClassLoader(), "server-list.properties", "serverB.hosts") .defaultPort(8080) .build(); assertThat(endpointGroupA.endpoints()).containsExactlyInAnyOrder(Endpoint.parse("127.0.0.1:8080"), Endpoint.parse("127.0.0.1:8081"), Endpoint.parse("127.0.0.1:80")); assertThat(endpointGroupB.endpoints()).containsExactlyInAnyOrder(Endpoint.parse("127.0.0.1:8082"), Endpoint.parse("127.0.0.1:8083")); }
@Test public void pathWithDefaultPort() throws Exception { final URL resourceUrl = getClass().getClassLoader().getResource("server-list.properties"); assert resourceUrl != null; final Path resourcePath = new File(resourceUrl.getFile()).toPath(); final PropertiesEndpointGroup endpointGroupA = PropertiesEndpointGroup.builder( resourcePath, "serverA.hosts").defaultPort(80).build(); assertThat(endpointGroupA.endpoints()).containsExactlyInAnyOrder(Endpoint.parse("127.0.0.1:8080"), Endpoint.parse("127.0.0.1:8081"), Endpoint.parse("127.0.0.1:80")); endpointGroupA.close(); }
@Test public void containsNoHosts() { assertThat(PropertiesEndpointGroup.builder(getClass().getClassLoader(), "server-list.properties", "serverC.hosts") .defaultPort(8080) .build() .endpoints()).isEmpty(); }
@Test public void illegalDefaultPort() { assertThatThrownBy(() -> PropertiesEndpointGroup.builder(getClass().getClassLoader(), "server-list.properties", "serverA.hosts") .defaultPort(0)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("defaultPort"); }