use of io.zeebe.test.broker.protocol.brokerapi.data.BrokerPartitionState in project zeebe by zeebe-io.
the class StubBrokerRule method stubTopologyRequest.
public void stubTopologyRequest() {
onTopologyRequest().respondWith().data().put("brokers", r -> currentTopology.get().getBrokers()).done().register();
// assuming that topology and partitions request are consistent
onControlMessageRequest(r -> r.messageType() == ControlMessageType.REQUEST_PARTITIONS && r.partitionId() == Protocol.SYSTEM_PARTITION).respondWith().data().put("partitions", r -> {
final Topology topology = currentTopology.get();
final List<Map<String, Object>> partitions = new ArrayList<>();
for (TopologyBroker broker : topology.getBrokers()) {
final List<BrokerPartitionState> brokerPartitionStates = broker.getPartitions();
for (BrokerPartitionState brokerPartitionState : brokerPartitionStates) {
final Map<String, Object> partition = new HashMap<>();
partition.put("topic", brokerPartitionState.getTopicName());
partition.put("id", brokerPartitionState.getPartitionId());
partitions.add(partition);
}
}
return partitions;
}).done().register();
}
Aggregations