ZooKeeperEndpointGroup extends DynamicEndpointGroup { public static ZooKeeperEndpointGroupBuilder builder( String zkConnectionStr, String znodePath, ZooKeeperDiscoverySpec spec) { return new ZooKeeperEndpointGroupBuilder(zkConnectionStr, znodePath, spec); } ZooKeeperEndpointGroup(EndpointSelectionStrategy selectionStrategy,
                           CuratorFramework client, String znodePath,
                           ZooKeeperDiscoverySpec discoverySpec, boolean internalClient); static ZooKeeperEndpointGroup of(String zkConnectionStr, String znodePath,
                                            ZooKeeperDiscoverySpec spec); static ZooKeeperEndpointGroup of(CuratorFramework client, String znodePath,
                                            ZooKeeperDiscoverySpec spec); static ZooKeeperEndpointGroupBuilder builder(
            String zkConnectionStr, String znodePath, ZooKeeperDiscoverySpec spec); static ZooKeeperEndpointGroupBuilder builder(
            CuratorFramework client, String znodePath, ZooKeeperDiscoverySpec spec);  }
@Test void legacyDiscoverySpec() throws Throwable { final List<Endpoint> sampleEndpoints = ZooKeeperTestUtil.sampleEndpoints(3); setLegacySpecNodeChildren(sampleEndpoints); final ZooKeeperEndpointGroup endpointGroup = endpointGroup(ZooKeeperDiscoverySpec.legacy()); await().untilAsserted(() -> assertThat(endpointGroup.endpoints()).hasSameElementsAs(sampleEndpoints)); final List<Endpoint> extraEndpoints = ZooKeeperTestUtil.sampleEndpoints(2); setLegacySpecNodeChildren(extraEndpoints); final Builder<Endpoint> builder = ImmutableSet.builder(); builder.addAll(sampleEndpoints).addAll(extraEndpoints); try (CloseableZooKeeper zk = zkInstance.connection()) { zk.sync(Z_NODE, (rc, path, ctx) -> {}, null); } final Set<Endpoint> expected = builder.build(); await().untilAsserted(() -> assertThat(endpointGroup.endpoints()).hasSameElementsAs(expected)); disconnectZk(endpointGroup); }
@Test void curatorDiscovery() throws Throwable { final List<Endpoint> sampleEndpoints = ZooKeeperTestUtil.sampleEndpoints(3); setCuratorXNodeChildren(sampleEndpoints, 0); final ZooKeeperDiscoverySpec spec = ZooKeeperDiscoverySpec.builderForCurator(CURATOR_X_SERVICE_NAME) .build(); final ZooKeeperEndpointGroup endpointGroup = endpointGroup(spec); await().untilAsserted(() -> assertThat(endpointGroup.endpoints()).hasSameElementsAs(sampleEndpoints)); final List<Endpoint> extraEndpoints = ZooKeeperTestUtil.sampleEndpoints(2); setCuratorXNodeChildren(extraEndpoints, 3); final Builder<Endpoint> builder = ImmutableSet.builder(); builder.addAll(sampleEndpoints).addAll(extraEndpoints); try (CloseableZooKeeper zk = zkInstance.connection()) { zk.sync(Z_NODE, (rc, path, ctx) -> {}, null); } final Set<Endpoint> expected = builder.build(); await().untilAsserted(() -> assertThat(endpointGroup.endpoints()).hasSameElementsAs(expected)); disconnectZk(endpointGroup); }