use of io.atomix.raft.RaftServer.Role in project zeebe by camunda.
the class RaftTest method shouldFailOverOnLeaderDisconnect.
@Test
public void shouldFailOverOnLeaderDisconnect() throws Throwable {
final List<RaftServer> servers = createServers(3);
final RaftServer leader = getLeader(servers).orElseThrow();
final MemberId leaderId = leader.getContext().getCluster().getLocalMember().memberId();
final CountDownLatch newLeaderElected = new CountDownLatch(1);
final AtomicReference<MemberId> newLeaderId = new AtomicReference<>();
servers.forEach(s -> s.addRoleChangeListener((role, term) -> {
if (role == Role.LEADER && !s.equals(leader)) {
newLeaderId.set(s.getContext().getCluster().getLocalMember().memberId());
newLeaderElected.countDown();
}
}));
// when
protocolFactory.partition(leaderId);
// then
assertThat(newLeaderElected.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(leaderId).isNotEqualTo(newLeaderId.get());
}
use of io.atomix.raft.RaftServer.Role in project zeebe by camunda.
the class RaftRolesTest method testStepDownInRoleChangedListener.
@Test
public void testStepDownInRoleChangedListener() throws Exception {
// given
final CompletableFuture<Void> roleChanged = new CompletableFuture<>();
final CountDownLatch followerLatch = new CountDownLatch(2);
final List<Role> roles = new ArrayList<>();
startSingleNodeSinglePartitionWithPartitionConsumer(partition -> {
final RaftPartition raftPartition = (RaftPartition) partition;
raftPartition.addRoleChangeListener((role, term) -> {
roles.add(role);
if (!roleChanged.isDone() && role == Role.LEADER) {
roleChanged.complete(null);
// when
raftPartition.stepDown();
} else if (role == Role.FOLLOWER) {
followerLatch.countDown();
}
});
}).join();
// then
roleChanged.get(60, TimeUnit.SECONDS);
followerLatch.await(10, TimeUnit.SECONDS);
// single node becomes directly leader again
assertThat(roles).containsSequence(Role.INACTIVE, Role.LEADER, Role.LEADER);
}
use of io.atomix.raft.RaftServer.Role in project zeebe by zeebe-io.
the class RaftTest method testRoleChangeNotificationAfterInitialEntryOnLeader.
@Test
public void testRoleChangeNotificationAfterInitialEntryOnLeader() throws Throwable {
// given
final List<RaftServer> servers = createServers(3);
final RaftServer previousLeader = getLeader(servers).get();
final long previousLeaderTerm = previousLeader.getTerm();
final CountDownLatch transitionCompleted = new CountDownLatch(1);
servers.forEach(server -> server.addRoleChangeListener((role, term) -> {
if (term > previousLeaderTerm) {
assertLastReadInitialEntry(role, term, server, transitionCompleted);
}
}));
// when
previousLeader.stepDown();
// then
assertThat(transitionCompleted.await(1000, TimeUnit.SECONDS)).isTrue();
}
use of io.atomix.raft.RaftServer.Role in project zeebe by camunda-cloud.
the class RaftTest method testRoleChangeNotificationAfterInitialEntryOnLeader.
@Test
public void testRoleChangeNotificationAfterInitialEntryOnLeader() throws Throwable {
// given
final List<RaftServer> servers = createServers(3);
final RaftServer previousLeader = getLeader(servers).get();
final long previousLeaderTerm = previousLeader.getTerm();
final CountDownLatch transitionCompleted = new CountDownLatch(1);
servers.forEach(server -> server.addRoleChangeListener((role, term) -> {
if (term > previousLeaderTerm) {
assertLastReadInitialEntry(role, term, server, transitionCompleted);
}
}));
// when
previousLeader.stepDown();
// then
assertThat(transitionCompleted.await(1000, TimeUnit.SECONDS)).isTrue();
}
use of io.atomix.raft.RaftServer.Role in project zeebe by camunda-cloud.
the class RaftServerDisconnectTest method shouldFailOverOnLeaderDisconnect.
@Test
public void shouldFailOverOnLeaderDisconnect() throws Throwable {
final RaftServer leader = raftRule.getLeader().orElseThrow();
final MemberId leaderId = leader.getContext().getCluster().getLocalMember().memberId();
final CountDownLatch newLeaderElected = new CountDownLatch(1);
final AtomicReference<MemberId> newLeaderId = new AtomicReference<>();
raftRule.getServers().forEach(s -> s.addRoleChangeListener((role, term) -> {
if (role == Role.LEADER && !s.equals(leader)) {
newLeaderId.set(s.getContext().getCluster().getLocalMember().memberId());
newLeaderElected.countDown();
}
}));
// when
raftRule.partition(leader);
// then
assertThat(newLeaderElected.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(leaderId).isNotEqualTo(newLeaderId.get());
}
Aggregations