Search in sources :

Example 1 with SubscriberGroup

use of io.zeebe.client.task.impl.subscription.SubscriberGroup in project zeebe by zeebe-io.

the class PartitionedTopicSubscriptionTest method shouldSumWorkCountOfPollableSubscription.

@Test
public void shouldSumWorkCountOfPollableSubscription() {
    // given
    final int subscriberKey1 = 456;
    broker1.stubTopicSubscriptionApi(subscriberKey1);
    final int subscriberKey2 = 789;
    broker2.stubTopicSubscriptionApi(subscriberKey2);
    final RecordingEventHandler eventHandler = new RecordingEventHandler();
    final PollableTopicSubscription subscription = client.topics().newPollableSubscription(TOPIC).name("hohoho").open();
    final RemoteAddress clientAddressFromBroker1 = broker1.getReceivedCommandRequests().get(0).getSource();
    final RemoteAddress clientAddressFromBroker2 = broker2.getReceivedCommandRequests().get(0).getSource();
    broker1.pushTopicEvent(clientAddressFromBroker1, b -> b.partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(3));
    broker2.pushTopicEvent(clientAddressFromBroker2, b -> b.partitionId(PARTITION_2).subscriberKey(subscriberKey2).key(4));
    waitUntil(() -> ((SubscriberGroup<?>) subscription).size() == 2);
    // when
    final int polledEvents = subscription.poll(eventHandler);
    // then
    assertThat(polledEvents).isEqualTo(2);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) SubscriberGroup(io.zeebe.client.task.impl.subscription.SubscriberGroup) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) Test(org.junit.Test)

Example 2 with SubscriberGroup

use of io.zeebe.client.task.impl.subscription.SubscriberGroup 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

SubscriberGroup (io.zeebe.client.task.impl.subscription.SubscriberGroup)2 RemoteAddress (io.zeebe.transport.RemoteAddress)2 Test (org.junit.Test)2 TopicSubscriberGroup (io.zeebe.client.event.impl.TopicSubscriberGroup)1 PollableTaskSubscription (io.zeebe.client.task.PollableTaskSubscription)1