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);
}
Aggregations