Search in sources :

Example 6 with PollableTaskSubscription

use of io.zeebe.client.task.PollableTaskSubscription in project zeebe by zeebe-io.

the class PartitionedTaskSubscriptionTest method shouldSumWorkCountOfPollableSubscription.

@Test
public void shouldSumWorkCountOfPollableSubscription() {
    // given
    final int subscriberKey1 = 456;
    broker1.stubTaskSubscriptionApi(subscriberKey1);
    final int subscriberKey2 = 789;
    broker2.stubTaskSubscriptionApi(subscriberKey2);
    final RecordingTaskHandler eventHandler = new RecordingTaskHandler();
    final PollableTaskSubscription subscription = client.tasks().newPollableTaskSubscription(TOPIC).taskType(TASK_TYPE).lockOwner("bumbum").lockTime(Duration.ofSeconds(6)).open();
    final RemoteAddress clientAddressFromBroker1 = broker1.getReceivedControlMessageRequests().get(0).getSource();
    final RemoteAddress clientAddressFromBroker2 = broker2.getReceivedControlMessageRequests().get(0).getSource();
    final long key1 = 3;
    broker1.newSubscribedEvent().eventType(EventType.TASK_EVENT).partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(key1).subscriptionType(SubscriptionType.TASK_SUBSCRIPTION).event().done().push(clientAddressFromBroker1);
    final long key2 = 4;
    broker2.newSubscribedEvent().eventType(EventType.TASK_EVENT).partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(key2).subscriptionType(SubscriptionType.TASK_SUBSCRIPTION).event().done().push(clientAddressFromBroker2);
    waitUntil(() -> ((SubscriberGroup<?>) subscription).size() == 2);
    // when
    final int polledEvents = subscription.poll(eventHandler);
    // then
    assertThat(polledEvents).isEqualTo(2);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) SubscriberGroup(io.zeebe.client.task.impl.subscription.SubscriberGroup) Test(org.junit.Test)

Aggregations

PollableTaskSubscription (io.zeebe.client.task.PollableTaskSubscription)6 Test (org.junit.Test)4 TaskEvent (io.zeebe.client.event.TaskEvent)2 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)2 RemoteAddress (io.zeebe.transport.RemoteAddress)2 RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)1 SubscriberGroup (io.zeebe.client.task.impl.subscription.SubscriberGroup)1 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1