Search in sources :

Example 1 with Raft

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));
}
Also used : Raft(io.zeebe.raft.Raft) SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 2 with Raft

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();
}
Also used : Broker(io.zeebe.broker.Broker) ServiceContainer(io.zeebe.servicecontainer.ServiceContainer) StreamProcessorController(io.zeebe.logstreams.processor.StreamProcessorController) Raft(io.zeebe.raft.Raft) Test(org.junit.Test)

Example 3 with Raft

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));
}
Also used : Raft(io.zeebe.raft.Raft) SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 4 with Raft

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;
            }
        }
    });
}
Also used : LogStream(io.zeebe.logstreams.log.LogStream) Raft(io.zeebe.raft.Raft)

Example 5 with Raft

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();
}
Also used : RaftService(io.zeebe.broker.clustering.raft.RaftService) Raft(io.zeebe.raft.Raft)

Aggregations

Raft (io.zeebe.raft.Raft)5 Test (org.junit.Test)3 SocketAddress (io.zeebe.transport.SocketAddress)2 Broker (io.zeebe.broker.Broker)1 RaftService (io.zeebe.broker.clustering.raft.RaftService)1 LogStream (io.zeebe.logstreams.log.LogStream)1 StreamProcessorController (io.zeebe.logstreams.processor.StreamProcessorController)1 ServiceContainer (io.zeebe.servicecontainer.ServiceContainer)1