use of io.zeebe.raft.Raft in project zeebe by zeebe-io.
the class BrokerRecoveryTest method shouldLoadRaftConfiguration.
@Test
public void shouldLoadRaftConfiguration() {
// given
final int testTerm = 8;
final ServiceName<Raft> serviceName = ClusterServiceNames.raftServiceName(clientRule.getDefaultTopic() + "." + clientRule.getDefaultPartition());
Raft raft = brokerRule.getService(serviceName);
waitUntil(raft::isInitialEventCommitted);
raft.setTerm(testTerm);
// when
restartBroker();
raft = brokerRule.getService(serviceName);
waitUntil(raft::isInitialEventCommitted);
// then
assertThat(raft.getState()).isEqualTo(RaftState.LEADER);
assertThat(raft.getTerm()).isEqualTo(testTerm + 1);
assertThat(raft.getMembers()).isEmpty();
assertThat(raft.getVotedFor()).isEqualTo(new SocketAddress("localhost", 51017));
}
use of io.zeebe.raft.Raft in project zeebe by zeebe-io.
the class ServicesLifecycleTest method shouldShutdownStreamProcessingBeforeLogStream.
@Test
public void shouldShutdownStreamProcessingBeforeLogStream() throws Exception {
// given
final Broker broker = brokerRule.getBroker();
final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer();
final String logStreamName = ClientApiRule.DEFAULT_TOPIC_NAME + "." + apiRule.getDefaultPartitionId();
final ServiceName<StreamProcessorController> streamProcessorServiceName = WorkflowQueueServiceNames.workflowInstanceStreamProcessorServiceName(logStreamName);
final ServiceName<Raft> raftServiceName = ClusterServiceNames.raftServiceName(logStreamName);
final StreamProcessorController streamProcessorController = getService(serviceContainer, streamProcessorServiceName);
// when
serviceContainer.removeService(raftServiceName).get();
// then
assertThat(!streamProcessorController.isOpened()).isTrue();
assertThat(streamProcessorController.isFailed()).isFalse();
}
use of io.zeebe.raft.Raft in project zeebe by zeebe-io.
the class BrokerRestartTest method shouldLoadRaftConfiguration.
@Test
public void shouldLoadRaftConfiguration() {
// given
final int testTerm = 8;
final ServiceName<Raft> serviceName = ClusterServiceNames.raftServiceName(clientRule.getDefaultTopic() + "." + clientRule.getDefaultPartition());
Raft raft = brokerRule.getService(serviceName);
waitUntil(raft::isInitialEventCommitted);
raft.setTerm(testTerm);
// when
restartBroker();
raft = brokerRule.getService(serviceName);
waitUntil(raft::isInitialEventCommitted);
// then
assertThat(raft.getState()).isEqualTo(RaftState.LEADER);
assertThat(raft.getTerm()).isEqualTo(testTerm + 1);
assertThat(raft.getMembers()).isEmpty();
assertThat(raft.getVotedFor()).isEqualTo(new SocketAddress("localhost", 51017));
}
use of io.zeebe.raft.Raft in project zeebe by zeebe-io.
the class ClusterManager method removeRaftCallback.
/**
* This method is called, if a RAFT is removed from the service group.
*/
public void removeRaftCallback(final Raft raft) {
final LogStream logStream = raft.getLogStream();
final int partitionId = logStream.getPartitionId();
actor.call(() -> {
for (int i = 0; i < rafts.size(); i++) {
final Raft r = rafts.get(i);
final LogStream stream = r.getLogStream();
if (partitionId == stream.getPartitionId()) {
rafts.remove(i);
break;
}
}
});
}
use of io.zeebe.raft.Raft in project zeebe by zeebe-io.
the class ClusterManager method createRaft.
public void createRaft(final SocketAddress socketAddress, final LogStream logStream, final List<SocketAddress> members, final RaftPersistentStorage persistentStorage) {
final ServiceName<Raft> raftServiceName = raftServiceName(logStream.getLogName());
final RaftService raftService = new RaftService(transportComponentCfg.raft, socketAddress, logStream, members, persistentStorage, clusterMemberListManager, clusterMemberListManager, raftServiceName);
serviceContainer.createService(raftServiceName, raftService).group(RAFT_SERVICE_GROUP).dependency(TransportServiceNames.clientTransport(TransportServiceNames.REPLICATION_API_CLIENT_NAME), raftService.getClientTransportInjector()).install();
}
Aggregations