MultiNodeClusterMemberResolver implements ClusterMemberResolver { @Override public Flux<ClusterMembershipSnapshot> resolve() { return snapshotEventObservable; } MultiNodeClusterMemberResolver(String serviceName,
                                          ClusterMembershipResolverConfiguration configuration,
                                          Supplier<Set<ClusterMemberAddress>> seedAddressesProvider,
                                          Function<ClusterMemberAddress, DirectClusterMemberResolver> directResolverFactory,
                                          Function<ClusterMember, ClusterMemberAddress> addressSelector,
                                          TitusRuntime titusRuntime); @Override void close(); @Override ClusterMembershipSnapshot getSnapshot(); @Override Flux<ClusterMembershipSnapshot> resolve();  }
@Test(timeout = 30_000) public void testMemberUpdate() { Iterator<ClusterMembershipSnapshot> eventIterator = resolver.resolve().toIterable().iterator(); eventIterator.next(); long initialRevision = MEMBER_1.getRevision(); long nextRevision = initialRevision + 1; memberResolver1.addMembers(MEMBER_1.toBuilder().withRevision(nextRevision).build()); ClusterMembershipSnapshot nextEvent = eventIterator.next(); assertThat(nextEvent.getMemberRevisions().get(MEMBER_1.getCurrent().getMemberId()).getRevision()).isEqualTo(nextRevision); }
@Test(timeout = 30_000) public void testMemberRemoval() { Iterator<ClusterMembershipSnapshot> eventIterator = resolver.resolve().toIterable().iterator(); eventIterator.next(); memberResolver1.removeMembers(MEMBER_2.getCurrent().getMemberId()); memberResolver2.changeHealth(false); ClusterMembershipSnapshot nextEvent = eventIterator.next(); assertThat(nextEvent.getMemberRevisions()).hasSize(1); }
@Test(timeout = 30_000) public void testLeaderElection() { Iterator<ClusterMembershipSnapshot> eventIterator = resolver.resolve().toIterable().iterator(); eventIterator.next(); memberResolver1.setAsLeader(MEMBER_1); Optional<ClusterMembershipRevision<ClusterMemberLeadership>> firstLeader = eventIterator.next().getLeaderRevision(); assertThat(firstLeader).isPresent(); assertThat(firstLeader.get().getCurrent().getMemberId()).isEqualTo(MEMBER_1.getCurrent().getMemberId()); memberResolver1.setAsLeader(MEMBER_2); Optional<ClusterMembershipRevision<ClusterMemberLeadership>> secondLeader = eventIterator.next().getLeaderRevision(); assertThat(secondLeader).isPresent(); assertThat(secondLeader.get().getCurrent().getMemberId()).isEqualTo(MEMBER_2.getCurrent().getMemberId()); }