Search in sources :

Example 6 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldOpenSubscription.

@Test
public void shouldOpenSubscription() throws InterruptedException {
    // given
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    // when
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    // then
    waitUntil(() -> !taskHandler.getHandledTasks().isEmpty());
    final List<TaskEvent> tasks = taskHandler.getHandledTasks();
    assertThat(tasks).hasSize(1);
    assertThat(tasks.get(0).getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 7 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldMarkTaskAsFailedAndRetryIfHandlerThrowsException.

@Test
public void shouldMarkTaskAsFailedAndRetryIfHandlerThrowsException() {
    // given
    eventRecorder.startRecordingEvents();
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> {
        throw new RuntimeException("expected failure");
    }, (c, t) -> c.complete(t).withoutPayload().execute());
    // when
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    // then the subscription is not broken and other tasks are still handled
    waitUntil(() -> taskHandler.getHandledTasks().size() == 2);
    final long taskKey = task.getMetadata().getKey();
    assertThat(taskHandler.getHandledTasks()).extracting("metadata.key").containsExactly(taskKey, taskKey);
    assertThat(eventRecorder.hasTaskEvent(taskEvent("FAILED"))).isTrue();
    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 8 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldNotLockTaskIfRetriesAreExhausted.

@Test
public void shouldNotLockTaskIfRetriesAreExhausted() {
    // given
    eventRecorder.startRecordingEvents();
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").retries(1).execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler((c, t) -> {
        throw new RuntimeException("expected failure");
    });
    // when
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("FAILED").and(taskRetries(0))));
    assertThat(taskHandler.getHandledTasks()).hasSize(1);
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) Test(org.junit.Test)

Example 9 with RecordingTaskHandler

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

the class BrokerRecoveryTest method shouldContinueWorkflowInstanceWithLockedTaskAfterRestart.

@Test
public void shouldContinueWorkflowInstanceWithLockedTaskAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("test").lockTime(Duration.ofSeconds(5)).handler(recordingTaskHandler).open();
    waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
    // when
    restartBroker();
    final TaskEvent task = recordingTaskHandler.getHandledTasks().get(0);
    clientRule.tasks().complete(task).execute();
    // then
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 10 with RecordingTaskHandler

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

the class MultipleClientTest method shouldOpenTaskSubscriptionsForDifferentTypes.

@Test
public void shouldOpenTaskSubscriptionsForDifferentTypes() {
    // given
    final RecordingTaskHandler handler1 = new RecordingTaskHandler();
    final RecordingTaskHandler handler2 = new RecordingTaskHandler();
    client1.tasks().newTaskSubscription(client1.getDefaultTopic()).handler(handler1).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("client1").open();
    client2.tasks().newTaskSubscription(client2.getDefaultTopic()).handler(handler2).taskType("bar").lockTime(Duration.ofMinutes(5)).lockOwner("client2").open();
    // when
    final TaskEvent task1 = client1.tasks().create(client1.getDefaultTopic(), "foo").execute();
    final TaskEvent task2 = client1.tasks().create(client1.getDefaultTopic(), "bar").execute();
    // then
    waitUntil(() -> handler1.getHandledTasks().size() + handler2.getHandledTasks().size() >= 2);
    assertThat(handler1.getHandledTasks()).hasSize(1);
    assertThat(handler1.getHandledTasks().get(0).getMetadata().getKey()).isEqualTo(task1.getMetadata().getKey());
    assertThat(handler2.getHandledTasks()).hasSize(1);
    assertThat(handler2.getHandledTasks().get(0).getMetadata().getKey()).isEqualTo(task2.getMetadata().getKey());
}
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