Search in sources :

Example 1 with TopologyBroker

use of io.zeebe.test.broker.protocol.brokerapi.data.TopologyBroker 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();
}
Also used : ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) Protocol(io.zeebe.protocol.Protocol) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) RemoteAddress(io.zeebe.transport.RemoteAddress) DEFAULT_TOPIC_NAME(io.zeebe.test.broker.protocol.clientapi.ClientApiRule.DEFAULT_TOPIC_NAME) Topology(io.zeebe.test.broker.protocol.brokerapi.data.Topology) Map(java.util.Map) MapFactoryBuilder(io.zeebe.test.util.collection.MapFactoryBuilder) Transports(io.zeebe.transport.Transports) MsgPackHelper(io.zeebe.test.broker.protocol.MsgPackHelper) TopologyBroker(io.zeebe.test.broker.protocol.brokerapi.data.TopologyBroker) Predicate(java.util.function.Predicate) ServerTransport(io.zeebe.transport.ServerTransport) Dispatcher(io.zeebe.dispatcher.Dispatcher) SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) InetSocketAddress(java.net.InetSocketAddress) Consumer(java.util.function.Consumer) ControlledActorClock(io.zeebe.util.sched.clock.ControlledActorClock) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ActorScheduler(io.zeebe.util.sched.ActorScheduler) ExternalResource(org.junit.rules.ExternalResource) EventType(io.zeebe.protocol.clientapi.EventType) BrokerPartitionState(io.zeebe.test.broker.protocol.brokerapi.data.BrokerPartitionState) Dispatchers(io.zeebe.dispatcher.Dispatchers) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BrokerPartitionState(io.zeebe.test.broker.protocol.brokerapi.data.BrokerPartitionState) Topology(io.zeebe.test.broker.protocol.brokerapi.data.Topology) HashMap(java.util.HashMap) Map(java.util.Map) TopologyBroker(io.zeebe.test.broker.protocol.brokerapi.data.TopologyBroker)

Aggregations

Dispatcher (io.zeebe.dispatcher.Dispatcher)1 Dispatchers (io.zeebe.dispatcher.Dispatchers)1 Protocol (io.zeebe.protocol.Protocol)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 EventType (io.zeebe.protocol.clientapi.EventType)1 SubscriptionType (io.zeebe.protocol.clientapi.SubscriptionType)1 MsgPackHelper (io.zeebe.test.broker.protocol.MsgPackHelper)1 BrokerPartitionState (io.zeebe.test.broker.protocol.brokerapi.data.BrokerPartitionState)1 Topology (io.zeebe.test.broker.protocol.brokerapi.data.Topology)1 TopologyBroker (io.zeebe.test.broker.protocol.brokerapi.data.TopologyBroker)1 DEFAULT_TOPIC_NAME (io.zeebe.test.broker.protocol.clientapi.ClientApiRule.DEFAULT_TOPIC_NAME)1 MapFactoryBuilder (io.zeebe.test.util.collection.MapFactoryBuilder)1 RemoteAddress (io.zeebe.transport.RemoteAddress)1 ServerTransport (io.zeebe.transport.ServerTransport)1 Transports (io.zeebe.transport.Transports)1 ActorScheduler (io.zeebe.util.sched.ActorScheduler)1 ControlledActorClock (io.zeebe.util.sched.clock.ControlledActorClock)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1