Search in sources :

Example 1 with TopologyResponse

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

the class BrokerRestartTest 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 2 with TopologyResponse

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

the class TopologyViewer method main.

public static void main(final String[] args) {
    final String[] brokers = new String[] { "localhost:51015", "localhost:41015", "localhost:31015" };
    for (final String broker : brokers) {
        final Properties clientProperties = new Properties();
        clientProperties.put(ClientProperties.BROKER_CONTACTPOINT, broker);
        try (ZeebeClient zeebeClient = ZeebeClient.create(clientProperties)) {
            final TopologyResponse topology = zeebeClient.requestTopology().execute();
            System.out.println("Requesting topology with initial contact point " + broker);
            System.out.println("  Topology:");
            topology.getBrokers().forEach(b -> {
                System.out.println("    " + b.getSocketAddress());
                b.getPartitions().forEach(p -> System.out.println("      " + p.getTopicName() + "." + p.getPartitionId() + " - " + p.getState()));
            });
        } catch (final Exception e) {
            System.out.println("Broker " + broker + " not available");
        }
    }
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties)

Example 3 with TopologyResponse

use of io.zeebe.client.clustering.impl.TopologyResponse 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 4 with TopologyResponse

use of io.zeebe.client.clustering.impl.TopologyResponse 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

TopologyResponse (io.zeebe.client.clustering.impl.TopologyResponse)4 ZeebeClient (io.zeebe.client.ZeebeClient)3 BrokerPartitionState (io.zeebe.client.clustering.impl.BrokerPartitionState)3 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)3 Test (org.junit.Test)2 ClientProperties (io.zeebe.client.ClientProperties)1 Properties (java.util.Properties)1