use of com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot in project titus-control-plane by Netflix.
the class SingleClusterMemberResolverTest method testInitialState.
@Test(timeout = 30_000)
public void testInitialState() {
assertThat(resolver.isHealthy()).isTrue();
assertThat(resolver.getAddress()).isEqualTo(ADDRESS);
ClusterMembershipSnapshot snapshotEvent = resolver.resolve().blockFirst(TIMEOUT);
assertThat(snapshotEvent).isNotNull();
assertThat(snapshotEvent.getMemberRevisions()).hasSize(3);
assertThat(snapshotEvent.getLeaderRevision()).isNotEmpty();
}
use of com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot in project titus-control-plane by Netflix.
the class SingleClusterMemberResolverTest method testElectedLeaderSetInSnapshot.
@Test
public void testElectedLeaderSetInSnapshot() {
Iterator<ClusterMembershipSnapshot> eventIt = resolver.resolve().toIterable().iterator();
ClusterMembershipSnapshot leadElectedEvent = eventIt.next();
assertThat(leadElectedEvent.getLeaderRevision()).isNotEmpty();
}
use of com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot in project titus-control-plane by Netflix.
the class SingleClusterMemberResolverTest method testMemberRemoval.
@Test(timeout = 30_000)
public void testMemberRemoval() {
Iterator<ClusterMembershipSnapshot> eventIt = subscribeAndDiscardFirstSnapshot();
serviceStub.removeMember(MEMBER_2);
ClusterMembershipSnapshot update = eventIt.next();
assertThat(update.getMemberRevisions()).hasSize(2);
assertThat(update.getMemberRevisions()).doesNotContainKey(MEMBER_2.getCurrent().getMemberId());
}
use of com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot in project titus-control-plane by Netflix.
the class SingleClusterMemberResolverTest method testReconnectOnStreamOnComplete.
@Test(timeout = 30_000)
public void testReconnectOnStreamOnComplete() {
Iterator<ClusterMembershipSnapshot> eventIt = subscribeAndDiscardFirstSnapshot();
serviceStub.completeEventStream();
ClusterMembershipSnapshot newSnapshot = eventIt.next();
assertThat(newSnapshot).isNotNull();
assertThat(newSnapshot.getMemberRevisions()).hasSize(3);
}
use of com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot in project titus-control-plane by Netflix.
the class MultiNodeClusterMemberResolver method buildSnapshot.
private ClusterMembershipSnapshot buildSnapshot() {
if (memberResolversByIpAddress.isEmpty()) {
return ClusterMembershipSnapshot.empty();
}
List<ClusterMembershipSnapshot> healthySnapshots = findHealthySnapshots();
ClusterMembershipSnapshot.Builder builder = ClusterMembershipSnapshot.newBuilder();
Map<String, List<ClusterMembershipRevision<ClusterMember>>> grouped = healthySnapshots.stream().flatMap(snapshot -> snapshot.getMemberRevisions().values().stream()).collect(Collectors.groupingBy(m -> m.getCurrent().getMemberId()));
List<ClusterMembershipRevision<ClusterMember>> recentRevisions = grouped.values().stream().map(this::findBestMemberRevision).collect(Collectors.toList());
builder.withMemberRevisions(recentRevisions);
// Find leader
Optional<ClusterMembershipRevision<ClusterMemberLeadership>> recentLeader = Optional.empty();
for (ClusterMembershipSnapshot snapshot : healthySnapshots) {
if (snapshot.getLeaderRevision().isPresent()) {
if (recentLeader.isPresent()) {
if (recentLeader.get().getRevision() < snapshot.getLeaderRevision().get().getRevision()) {
recentLeader = snapshot.getLeaderRevision();
}
} else {
recentLeader = snapshot.getLeaderRevision();
}
}
}
recentLeader.ifPresent(builder::withLeaderRevision);
// Choose latest version of each
long minStaleness = healthySnapshots.stream().mapToLong(ClusterMembershipSnapshot::getStalenessMs).min().orElse(0);
builder.withStalenessMs(minStaleness);
return builder.build();
}
Aggregations