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