Search in sources :

Example 1 with BrokerPartitionState

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

the class TopologyRequestTest method shouldUpdateClientTopologyOnAsyncTopologyRequest.

@Test
public void shouldUpdateClientTopologyOnAsyncTopologyRequest() {
    // given
    final SocketAddress oldLeader = BROKER_1_CLIENT_ADDRESS;
    // when
    final List<Integer> partitions = clusteringRule.getBrokersLeadingPartitions(oldLeader);
    clusteringRule.brokers.remove(oldLeader).close();
    doRepeatedly(this::requestTopologyAsync).until(topologyBrokers -> topologyBrokers != null && topologyBrokers.stream().filter(broker -> !broker.getSocketAddress().equals(oldLeader)).flatMap(broker -> broker.getPartitions().stream()).filter(BrokerPartitionState::isLeader).map(BrokerPartitionState::getPartitionId).collect(Collectors.toSet()).containsAll(partitions));
    // then
    zeebeClient.topics().create("foo", 1).execute();
}
Also used : TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) Test(org.junit.Test) Collectors(java.util.stream.Collectors) BROKER_1_CLIENT_ADDRESS(io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) ZeebeClient(io.zeebe.client.ZeebeClient) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.broker.it.ClientRule) List(java.util.List) Future(java.util.concurrent.Future) SocketAddress(io.zeebe.transport.SocketAddress) Rule(org.junit.Rule) Timeout(org.junit.rules.Timeout) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) Before(org.junit.Before) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 2 with BrokerPartitionState

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

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

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

BrokerPartitionState (io.zeebe.client.clustering.impl.BrokerPartitionState)4 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)4 TopologyResponse (io.zeebe.client.clustering.impl.TopologyResponse)4 ZeebeClient (io.zeebe.client.ZeebeClient)3 Test (org.junit.Test)3 ClientRule (io.zeebe.broker.it.ClientRule)1 BROKER_1_CLIENT_ADDRESS (io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS)1 AutoCloseableRule (io.zeebe.test.util.AutoCloseableRule)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 SocketAddress (io.zeebe.transport.SocketAddress)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 RuleChain (org.junit.rules.RuleChain)1 Timeout (org.junit.rules.Timeout)1