Search in sources :

Example 1 with Topology

use of io.zeebe.test.broker.protocol.brokerapi.data.Topology in project zeebe by zeebe-io.

the class StubBrokerRule method addTopic.

public void addTopic(String topic, int partition) {
    final Topology newTopology = new Topology(currentTopology.get());
    newTopology.addLeader(host, port, topic, partition);
    currentTopology.set(newTopology);
}
Also used : Topology(io.zeebe.test.broker.protocol.brokerapi.data.Topology)

Example 2 with Topology

use of io.zeebe.test.broker.protocol.brokerapi.data.Topology in project zeebe by zeebe-io.

the class PartitionedTopicSubscriptionTest method setUp.

@Before
public void setUp() {
    final Topology topology = new Topology().addLeader(broker1, Protocol.SYSTEM_TOPIC, Protocol.SYSTEM_PARTITION).addLeader(broker1, TOPIC, PARTITION_1).addLeader(broker2, TOPIC, PARTITION_2);
    broker1.setCurrentTopology(topology);
    broker2.setCurrentTopology(topology);
    client = clientRule.getClient();
}
Also used : Topology(io.zeebe.test.broker.protocol.brokerapi.data.Topology) Before(org.junit.Before)

Example 3 with Topology

use of io.zeebe.test.broker.protocol.brokerapi.data.Topology in project zeebe by zeebe-io.

the class PartitionedTaskSubscriptionTest method setUp.

@Before
public void setUp() {
    final Topology topology = new Topology().addLeader(broker1, Protocol.SYSTEM_TOPIC, Protocol.SYSTEM_PARTITION).addLeader(broker1, TOPIC, PARTITION_1).addLeader(broker2, TOPIC, PARTITION_2);
    broker1.setCurrentTopology(topology);
    broker2.setCurrentTopology(topology);
    client = clientRule.getClient();
}
Also used : Topology(io.zeebe.test.broker.protocol.brokerapi.data.Topology) Before(org.junit.Before)

Example 4 with Topology

use of io.zeebe.test.broker.protocol.brokerapi.data.Topology in project zeebe by zeebe-io.

the class StubBrokerRule method before.

@Override
protected void before() throws Throwable {
    msgPackHelper = new MsgPackHelper();
    final int numThreads = 2;
    scheduler = ActorScheduler.newActorScheduler().setCpuBoundActorThreadCount(numThreads).setActorClock(clock).build();
    scheduler.start();
    sendBuffer = Dispatchers.create("send-buffer").actorScheduler(scheduler).bufferSize(1024 * 1024).build();
    channelHandler = new StubResponseChannelHandler(msgPackHelper);
    bindAddr = new InetSocketAddress(host, port);
    currentTopology.set(new Topology().addLeader(host, port, TEST_TOPIC_NAME, TEST_PARTITION_ID).addLeader(host, port, Protocol.SYSTEM_TOPIC, Protocol.SYSTEM_PARTITION));
    stubTopologyRequest();
    bindTransport();
}
Also used : MsgPackHelper(io.zeebe.test.broker.protocol.MsgPackHelper) InetSocketAddress(java.net.InetSocketAddress) Topology(io.zeebe.test.broker.protocol.brokerapi.data.Topology)

Example 5 with Topology

use of io.zeebe.test.broker.protocol.brokerapi.data.Topology 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

Topology (io.zeebe.test.broker.protocol.brokerapi.data.Topology)5 MsgPackHelper (io.zeebe.test.broker.protocol.MsgPackHelper)2 InetSocketAddress (java.net.InetSocketAddress)2 Before (org.junit.Before)2 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 BrokerPartitionState (io.zeebe.test.broker.protocol.brokerapi.data.BrokerPartitionState)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 ArrayList (java.util.ArrayList)1