Search in sources :

Example 1 with PollableTaskSubscription

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

the class TaskSubscriptionTest method shouldPollTasks.

@Test
public void shouldPollTasks() {
    // given
    eventRecorder.startRecordingEvents();
    final PollableTaskSubscription subscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").payload("{\"a\":1}").addCustomHeader("b", "2").execute();
    // when
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> c.complete(t).withoutPayload().execute());
    doRepeatedly(() -> subscription.poll(taskHandler)).until((workCount) -> workCount == 1);
    assertThat(taskHandler.getHandledTasks()).hasSize(1);
    final TaskEvent subscribedTasks = taskHandler.getHandledTasks().get(0);
    assertThat(subscribedTasks.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
    assertThat(subscribedTasks.getType()).isEqualTo("foo");
    assertThat(subscribedTasks.getLockExpirationTime()).isAfter(Instant.now());
    assertThat(subscribedTasks.getPayload()).isEqualTo("{\"a\":1}");
    assertThat(subscribedTasks.getCustomHeaders()).containsEntry("b", "2");
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 2 with PollableTaskSubscription

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

the class CancelWorkflowInstanceTest method shouldFailToLockTaskAfterCancel.

@Test
public void shouldFailToLockTaskAfterCancel() {
    // given
    final WorkflowInstanceEvent workflowInstance = clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("CREATED")));
    clientRule.workflows().cancel(workflowInstance).execute();
    final PollableTaskSubscription taskSubscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopic()).taskType("test").lockOwner("owner").lockTime(Duration.ofMinutes(1)).open();
    // when
    final int completedTasks = taskSubscription.poll((c, t) -> c.complete(t).withoutPayload().execute());
    // then
    assertThat(completedTasks).isEqualTo(0);
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("LOCK_REJECTED")));
    assertThat(eventRecorder.hasTaskEvent(taskEvent("CANCELED")));
    assertThat(eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_CANCELED")));
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription)

Example 3 with PollableTaskSubscription

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

the class CancelWorkflowInstanceTest method shouldFailToCompleteTaskAfterCancel.

@Test
public void shouldFailToCompleteTaskAfterCancel() {
    // given
    final WorkflowInstanceEvent workflowInstance = clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    final PollableTaskSubscription taskSubscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopic()).taskType("test").lockOwner("owner").lockTime(Duration.ofMinutes(1)).open();
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("LOCKED")));
    clientRule.workflows().cancel(workflowInstance).execute();
    // when
    taskSubscription.poll((c, t) -> c.complete(t).withoutPayload().execute());
    // then
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETE_REJECTED")));
    assertThat(eventRecorder.hasTaskEvent(taskEvent("CANCELED")));
    assertThat(eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_CANCELED")));
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription)

Example 4 with PollableTaskSubscription

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

the class TaskSubscriptionTest method shouldInvokeTaskHandlerForPollableSubscription.

@Test
public void shouldInvokeTaskHandlerForPollableSubscription() {
    // given
    broker.stubTaskSubscriptionApi(123L);
    stubTaskCompleteRequest();
    final RecordingTaskHandler handler = new RecordingTaskHandler();
    final PollableTaskSubscription subscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopicName()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
    final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
    broker.pushLockedTask(clientAddress, 123L, 4L, 5L, "foo", "type");
    // when
    final Integer handledTasks = TestUtil.doRepeatedly(() -> subscription.poll(handler)).until(numTasks -> numTasks > 0);
    // then
    assertThat(handledTasks).isEqualTo(1);
    assertThat(handler.getHandledTasks()).hasSize(1);
    final TaskEvent task = handler.getHandledTasks().get(0);
    assertThat(task.getMetadata().getKey()).isEqualTo(4L);
    assertThat(task.getType()).isEqualTo("type");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemoteAddress(io.zeebe.transport.RemoteAddress) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 5 with PollableTaskSubscription

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

the class TaskSubscriptionTest method shouldOpenPollableSubscription.

@Test
public void shouldOpenPollableSubscription() {
    // given
    broker.stubTaskSubscriptionApi(123L);
    // when
    final PollableTaskSubscription subscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopicName()).lockOwner("foo").lockTime(10000L).taskType("bar").taskFetchSize(456).open();
    // then
    assertThat(subscription.isOpen()).isTrue();
    final ControlMessageRequest subscriptionRequest = getSubscribeRequests().findFirst().get();
    assertThat(subscriptionRequest.messageType()).isEqualByComparingTo(ControlMessageType.ADD_TASK_SUBSCRIPTION);
    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) 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