use of io.zeebe.client.task.TaskSubscription in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldOpenSubscription.
@Test
public void shouldOpenSubscription() {
// given
broker.stubTaskSubscriptionApi(123L);
// when
final TaskSubscription subscription = clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).lockOwner("foo").lockTime(10000L).taskType("bar").taskFetchSize(456).open();
// then
assertThat(subscription.isOpen()).isTrue();
assertThat(subscription.isClosed()).isFalse();
final ControlMessageRequest subscriptionRequest = getSubscribeRequests().findFirst().get();
assertThat(subscriptionRequest.messageType()).isEqualByComparingTo(ControlMessageType.ADD_TASK_SUBSCRIPTION);
assertThat(subscriptionRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
assertThat(subscriptionRequest.getData()).contains(entry("lockOwner", "foo"), entry("lockDuration", 10000), entry("taskType", "bar"), entry("credits", 456));
}
use of io.zeebe.client.task.TaskSubscription in project zeebe by zeebe-io.
the class PartitionedTaskSubscriptionTest method shouldSubscribeToMultiplePartitionsOfATopic.
@Test
public void shouldSubscribeToMultiplePartitionsOfATopic() {
// given
broker1.stubTaskSubscriptionApi(456);
broker2.stubTaskSubscriptionApi(789);
// when
final TaskSubscription subscription = client.tasks().newTaskSubscription(TOPIC).handler(new RecordingTaskHandler()).taskType(TASK_TYPE).lockOwner("bumbum").lockTime(Duration.ofSeconds(6)).open();
// then
assertThat(subscription.isOpen()).isTrue();
final List<ControlMessageRequest> subscribeRequestsBroker1 = getSubscribeRequests(broker1);
assertThat(subscribeRequestsBroker1).hasSize(1);
final ControlMessageRequest request1 = subscribeRequestsBroker1.get(0);
assertThat(request1.partitionId()).isEqualTo(PARTITION_1);
final List<ControlMessageRequest> subscribeRequestsBroker2 = getSubscribeRequests(broker2);
assertThat(subscribeRequestsBroker2).hasSize(1);
final ControlMessageRequest request2 = subscribeRequestsBroker2.get(0);
assertThat(request2.partitionId()).isEqualTo(PARTITION_2);
}
Aggregations