use of io.atomix.raft.partition.RaftPartition in project zeebe by zeebe-io.
the class ClusteringRule method stepDown.
public void stepDown(final Broker broker, final int partitionId) {
final var atomix = broker.getBrokerContext().getClusterServices();
final MemberId nodeId = atomix.getMembershipService().getLocalMember().id();
final var raftPartition = broker.getBrokerContext().getPartitionManager().getPartitionGroup().getPartitions().stream().filter(partition -> partition.members().contains(nodeId)).filter(partition -> partition.id().id() == partitionId).map(RaftPartition.class::cast).findFirst().orElseThrow();
raftPartition.getServer().stepDown().join();
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by zeebe-io.
the class HealthMonitoringTest method shouldReportUnhealthyWhenRaftInactive.
@Test
public void shouldReportUnhealthyWhenRaftInactive() {
// given
final Broker leader = embeddedBrokerRule.getBroker();
/* timeouts are selected generously as at the time of this implementation there is a
* 1 minute cycle to update the state
*/
await("Broker is healthy").atMost(Duration.ofMinutes(2)).until(() -> {
embeddedBrokerRule.getClock().addTime(Duration.ofMinutes(1));
return isBrokerHealthy();
});
// when
final var raftPartition = (RaftPartition) leader.getBrokerContext().getPartitionManager().getPartitionGroup().getPartition(PartitionId.from(PartitionManagerImpl.GROUP_NAME, START_PARTITION_ID));
raftPartition.getServer().stop();
// then
/* timeouts are selected generously as at the time of this implementation there is a
* 1 minute cycle to update the state
*/
waitAtMost(Duration.ofMinutes(2)).until(() -> {
embeddedBrokerRule.getClock().addTime(Duration.ofMinutes(1));
return !isBrokerHealthy();
});
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by zeebe-io.
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.partition.RaftPartition in project zeebe by zeebe-io.
the class RaftRolesTest method testRoleChangedListener.
@Test
public void testRoleChangedListener() throws Exception {
// given
final CompletableFuture<Void> roleChanged = new CompletableFuture<>();
// when
final CompletableFuture<Void> joinFuture = startSingleNodeSinglePartitionWithPartitionConsumer(partition -> {
final RaftPartition raftPartition = (RaftPartition) partition;
raftPartition.addRoleChangeListener((role, term) -> roleChanged.complete(null));
});
// then
joinFuture.join();
roleChanged.get();
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by zeebe-io.
the class BrokerSnapshotTest method setup.
@Before
public void setup() {
final RaftPartition raftPartition = (RaftPartition) brokerRule.getBroker().getBrokerContext().getPartitionManager().getPartitionGroup().getPartition(PartitionId.from(PartitionManagerImpl.GROUP_NAME, PARTITION_ID));
journalReader = raftPartition.getServer().openReader();
brokerAdminService = brokerRule.getBroker().getBrokerContext().getBrokerAdminService();
final String contactPoint = NetUtil.toSocketAddressString(brokerRule.getGatewayAddress());
final ZeebeClientBuilder zeebeClientBuilder = ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(contactPoint);
client = zeebeClientBuilder.build();
}
Aggregations