Search in sources :

Example 16 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class YamlWorkflowTest method shouldCompleteTaskWithPayload.

@Test
public void shouldCompleteTaskWithPayload() {
    // given
    workflowClient.deploy(clientRule.getDefaultTopic()).addResourceFromClasspath("workflows/workflow-with-mappings.yaml").execute();
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow-mappings").payload("{\"foo\":1}").execute();
    // when
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler((c, task) -> c.complete(task).payload("{\"result\":3}").execute());
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("owner").lockTime(Duration.ofMinutes(5)).handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> recordingTaskHandler.getHandledTasks().size() >= 1);
    final TaskEvent taskLockedEvent = recordingTaskHandler.getHandledTasks().get(0);
    assertThat(taskLockedEvent.getPayload()).isEqualTo("{\"bar\":1}");
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED")));
    final WorkflowInstanceEvent workflowEvent = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("ACTIVITY_COMPLETED"));
    assertThat(workflowEvent.getPayload()).isEqualTo("{\"result\":3}");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent)

Example 17 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldNotReceiveLockedTasksAfterRestart.

@Test
public void shouldNotReceiveLockedTasksAfterRestart() {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofSeconds(5)).lockOwner("test").handler(taskHandler).open();
    waitUntil(() -> !taskHandler.getHandledTasks().isEmpty());
    // when
    restartBroker();
    taskHandler.clear();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofMinutes(10L)).lockOwner("test").handler(taskHandler).open();
    // then
    TestUtil.doRepeatedly(() -> null).whileConditionHolds((o) -> taskHandler.getHandledTasks().isEmpty());
    assertThat(taskHandler.getHandledTasks()).isEmpty();
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) Test(org.junit.Test)

Example 18 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldCloseSubscription.

@Test
public void shouldCloseSubscription() throws InterruptedException {
    // given
    eventRecorder.startRecordingEvents();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    final TaskSubscription subscription = clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    // when
    subscription.close();
    // then
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("CREATED")));
    assertThat(taskHandler.getHandledTasks()).isEmpty();
    assertThat(eventRecorder.hasTaskEvent(taskEvent("LOCK"))).isFalse();
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskSubscription(io.zeebe.client.task.TaskSubscription) Test(org.junit.Test)

Example 19 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldUpdateTaskRetries.

@Test
public void shouldUpdateTaskRetries() {
    // given
    eventRecorder.startRecordingEvents();
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").retries(1).execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> {
        throw new RuntimeException("expected failure");
    }, (c, t) -> c.complete(t).withoutPayload().execute());
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    waitUntil(() -> taskHandler.getHandledTasks().size() == 1);
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("FAILED").and(taskRetries(0))));
    // when
    final TaskEvent updatedTask = clientRule.tasks().updateRetries(task).retries(2).execute();
    // then
    assertThat(updatedTask.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
    waitUntil(() -> taskHandler.getHandledTasks().size() == 2);
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 20 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldCompletionTaskInHandler.

@Test
public void shouldCompletionTaskInHandler() throws InterruptedException {
    // given
    eventRecorder.startRecordingEvents();
    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).payload("{\"a\":3}").execute());
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    // then
    waitUntil(() -> !taskHandler.getHandledTasks().isEmpty());
    assertThat(taskHandler.getHandledTasks()).hasSize(1);
    final TaskEvent subscribedTask = taskHandler.getHandledTasks().get(0);
    assertThat(subscribedTask.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
    assertThat(subscribedTask.getType()).isEqualTo("foo");
    assertThat(subscribedTask.getLockExpirationTime()).isAfter(Instant.now());
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
    final TaskEvent taskEvent = eventRecorder.getTaskEvents(taskEvent("COMPLETED")).get(0);
    assertThat(taskEvent.getPayload()).isEqualTo("{\"a\":3}");
    assertThat(task.getCustomHeaders()).containsEntry("b", "2");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Aggregations

RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)27 Test (org.junit.Test)23 TaskEvent (io.zeebe.client.event.TaskEvent)19 PollableTaskSubscription (io.zeebe.client.task.PollableTaskSubscription)3 TaskSubscription (io.zeebe.client.task.TaskSubscription)3 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)2 ClientRule (io.zeebe.broker.it.ClientRule)1 EmbeddedBrokerRule (io.zeebe.broker.it.EmbeddedBrokerRule)1 TopicEventRecorder (io.zeebe.broker.it.util.TopicEventRecorder)1 TopicEventRecorder.taskEvent (io.zeebe.broker.it.util.TopicEventRecorder.taskEvent)1 TopicEventRecorder.taskRetries (io.zeebe.broker.it.util.TopicEventRecorder.taskRetries)1 ZeebeClient (io.zeebe.client.ZeebeClient)1 CreateTaskCommandImpl (io.zeebe.client.task.impl.CreateTaskCommandImpl)1 Topic (io.zeebe.client.topic.Topic)1 Topics (io.zeebe.client.topic.Topics)1 TestUtil (io.zeebe.test.util.TestUtil)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1