Search in sources :

Example 6 with TaskSubscription

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));
}
Also used : ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskSubscription(io.zeebe.client.task.TaskSubscription) Test(org.junit.Test)

Example 7 with TaskSubscription

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);
}
Also used : ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskSubscription(io.zeebe.client.task.TaskSubscription) Test(org.junit.Test)

Aggregations

TaskSubscription (io.zeebe.client.task.TaskSubscription)7 Test (org.junit.Test)6 PollableTaskSubscription (io.zeebe.client.task.PollableTaskSubscription)5 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)4 RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)2 ClientProperties (io.zeebe.client.ClientProperties)2 ZeebeClient (io.zeebe.client.ZeebeClient)2 TaskEvent (io.zeebe.client.event.TaskEvent)2 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)2 Duration (java.time.Duration)2 Properties (java.util.Properties)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TasksClient (io.zeebe.client.TasksClient)1 TasksClientImpl (io.zeebe.client.impl.TasksClientImpl)1 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)1 TaskHandler (io.zeebe.client.task.TaskHandler)1 Subscriber (io.zeebe.client.task.impl.subscription.Subscriber)1 ClientRule (io.zeebe.client.util.ClientRule)1