Search in sources :

Example 6 with SocketAddress

use of io.zeebe.transport.SocketAddress 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 7 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class GossipDifferentNodeJoinTest method shouldRemoveLeaderFromCluster.

@Test
public void shouldRemoveLeaderFromCluster() {
    // given
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(0);
    final SocketAddress[] otherBrokers = clusteringRule.getOtherBrokers(leaderForPartition.getSocketAddress());
    // when
    clusteringRule.stopBroker(leaderForPartition.getSocketAddress());
    // then
    final List<SocketAddress> topologyBrokers = clusteringRule.getBrokersInCluster();
    assertThat(topologyBrokers).containsExactlyInAnyOrder(otherBrokers);
}
Also used : SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 8 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class GossipDifferentNodeJoinTest method shouldRemoveMemberFromTopology.

@Test
public void shouldRemoveMemberFromTopology() {
    // given
    final SocketAddress brokerAddress = ClusteringRule.BROKER_3_CLIENT_ADDRESS;
    final SocketAddress[] otherBrokers = clusteringRule.getOtherBrokers(brokerAddress);
    // when
    clusteringRule.stopBroker(brokerAddress);
    // then
    final List<SocketAddress> topologyBrokers = clusteringRule.getBrokersInCluster();
    assertThat(topologyBrokers).containsExactlyInAnyOrder(otherBrokers);
}
Also used : SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 9 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class BrokerLeaderChangeTest method shouldChangeLeaderAfterLeaderDies.

@Test
public void shouldChangeLeaderAfterLeaderDies() {
    // given
    clusteringRule.createTopic(clientRule.getDefaultTopic(), 2);
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(1);
    final SocketAddress leaderAddress = leaderForPartition.getSocketAddress();
    final TaskEvent taskEvent = taskClient.create(clientRule.getDefaultTopic(), TASK_TYPE).execute();
    // when
    clusteringRule.stopBroker(leaderAddress);
    final TaskCompleter taskCompleter = new TaskCompleter(taskEvent);
    // then
    taskCompleter.waitForTaskCompletion();
    taskCompleter.close();
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 10 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class TopologyCreator method createTopology.

public Topology createTopology() {
    LOG.trace("Received topology request.");
    final Iterator<MemberRaftComposite> iterator = clusterManagerContext.getMemberListService().iterator();
    final Topology topology = new Topology();
    while (iterator.hasNext()) {
        final MemberRaftComposite next = iterator.next();
        final ValueArray<TopologyBroker> brokers = topology.brokers();
        final SocketAddress clientApi = next.getClientApi();
        if (clientApi != null) {
            final TopologyBroker nextTopologyBroker = brokers.add();
            nextTopologyBroker.setHost(clientApi.getHostBuffer(), 0, clientApi.hostLength()).setPort(clientApi.port());
            final Iterator<RaftStateComposite> raftTupleIt = next.getRaftIterator();
            while (raftTupleIt.hasNext()) {
                final RaftStateComposite nextRaftState = raftTupleIt.next();
                final DirectBuffer topicName = BufferUtil.cloneBuffer(nextRaftState.getTopicName());
                nextTopologyBroker.partitionStates().add().setPartitionId(nextRaftState.getPartition()).setTopicName(topicName, 0, topicName.capacity()).setState(nextRaftState.getRaftState());
            }
        }
    }
    // LOG.debug("Send topology {} as response.", topology);
    return topology;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Topology(io.zeebe.broker.clustering.handler.Topology) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker)

Aggregations

SocketAddress (io.zeebe.transport.SocketAddress)21 Test (org.junit.Test)13 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)6 TaskEvent (io.zeebe.client.event.TaskEvent)3 DirectBuffer (org.agrona.DirectBuffer)3 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)2 TypedBatchWriter (io.zeebe.broker.logstreams.processor.TypedBatchWriter)2 Raft (io.zeebe.raft.Raft)2 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)2 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MutableDirectBuffer (org.agrona.MutableDirectBuffer)2 Before (org.junit.Before)2 Topology (io.zeebe.broker.clustering.handler.Topology)1 Member (io.zeebe.broker.clustering.member.Member)1 ClientRule (io.zeebe.broker.it.ClientRule)1 BROKER_1_CLIENT_ADDRESS (io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS)1 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1