Search in sources :

Example 6 with TopologyBroker

use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.

the class CreateTopicClusteredTest method shouldChooseNewLeaderForCreatedTopicAfterLeaderDies.

@Test
public void shouldChooseNewLeaderForCreatedTopicAfterLeaderDies() {
    // given
    final int partitionsCount = 1;
    clusteringRule.createTopic("foo", partitionsCount);
    final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
    final int partitionId = taskEvent.getMetadata().getPartitionId();
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(partitionId);
    final SocketAddress currentLeaderAddress = leaderForPartition.getSocketAddress();
    // when
    clusteringRule.stopBroker(currentLeaderAddress);
    // then
    final TopologyBroker newLeader = clusteringRule.getLeaderForPartition(partitionId);
    assertThat(newLeader.getSocketAddress()).isNotEqualTo(leaderForPartition.getSocketAddress());
}
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 7 with TopologyBroker

use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.

the class GossipClusteringTest 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 TopologyBroker

use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.

the class BrokerRecoveryTest method shouldCreateUniquePartitionIdsAfterRestart.

@Test
public void shouldCreateUniquePartitionIdsAfterRestart() {
    // given
    final ZeebeClient client = clientRule.getClient();
    client.topics().create("foo", 2).execute();
    restartBroker();
    // when
    client.topics().create("bar", 2).execute();
    // then
    final TopologyResponse topology = client.requestTopology().execute();
    final List<TopologyBroker> brokers = topology.getBrokers();
    assertThat(brokers).hasSize(1);
    final TopologyBroker topologyBroker = brokers.get(0);
    final List<BrokerPartitionState> partitions = topologyBroker.getPartitions();
    // default partition + system partition + 4 partitions we create here
    assertThat(partitions).hasSize(6);
    assertThat(partitions).extracting("partitionId").doesNotHaveDuplicates();
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 9 with TopologyBroker

use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.

the class ClientRule method createDefaultTopic.

private void createDefaultTopic() {
    client.topics().create(DEFAULT_TOPIC, 1).execute();
    final TopologyResponse topology = client.requestTopology().execute();
    defaultPartition = -1;
    final List<TopologyBroker> topologyBrokers = topology.getBrokers();
    for (TopologyBroker leader : topologyBrokers) {
        final List<BrokerPartitionState> partitions = leader.getPartitions();
        for (BrokerPartitionState brokerPartitionState : partitions) {
            if (DEFAULT_TOPIC.equals(brokerPartitionState.getTopicName()) && brokerPartitionState.isLeader()) {
                defaultPartition = brokerPartitionState.getPartitionId();
                break;
            }
        }
    }
    if (defaultPartition < 0) {
        throw new RuntimeException("Could not detect leader for default partition");
    }
}
Also used : TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker)

Aggregations

TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)9 Test (org.junit.Test)8 SocketAddress (io.zeebe.transport.SocketAddress)5 TaskEvent (io.zeebe.client.event.TaskEvent)4 ZeebeClient (io.zeebe.client.ZeebeClient)3 BrokerPartitionState (io.zeebe.client.clustering.impl.BrokerPartitionState)3 TopologyResponse (io.zeebe.client.clustering.impl.TopologyResponse)3 Topic (io.zeebe.client.topic.Topic)1 Topics (io.zeebe.client.topic.Topics)1 CompletableFuture (java.util.concurrent.CompletableFuture)1