Search in sources :

Example 1 with RecordingTaskHandler

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

the class BrokerRestartTest 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 2 with RecordingTaskHandler

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

the class BrokerRestartTest method shouldCompleteStandaloneTaskAfterRestart.

@Test
public void shouldCompleteStandaloneTaskAfterRestart() {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").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")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 3 with RecordingTaskHandler

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

the class BrokerRestartTest method shouldReceiveLockExpiredTasksAfterRestart.

@Test
public void shouldReceiveLockExpiredTasksAfterRestart() {
    // given
    clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
    final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
    final TaskSubscription subscription = clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofSeconds(5)).lockOwner("test").handler(recordingTaskHandler).open();
    waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
    subscription.close();
    // when
    restartBroker();
    doRepeatedly(() -> {
        // retriggers lock expiration check in broker
        brokerRule.getClock().addTime(Duration.ofSeconds(60));
        return null;
    }).until(t -> eventRecorder.hasTaskEvent(taskEvent("LOCK_EXPIRED")));
    recordingTaskHandler.clear();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofMinutes(10L)).lockOwner("test").handler(recordingTaskHandler).open();
    // then
    waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
    final TaskEvent task = recordingTaskHandler.getHandledTasks().get(0);
    clientRule.tasks().complete(task).execute();
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskSubscription(io.zeebe.client.task.TaskSubscription) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 4 with RecordingTaskHandler

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

the class TaskSubscriptionTest method shouldCompleteTask.

@Test
public void shouldCompleteTask() throws InterruptedException {
    // given
    eventRecorder.startRecordingEvents();
    final TaskEvent task = clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").payload("{ \"a\" : 1 }").addCustomHeader("b", "2").execute();
    final RecordingTaskHandler taskHandler = new RecordingTaskHandler();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).handler(taskHandler).taskType("foo").lockTime(Duration.ofMinutes(5)).lockOwner("test").open();
    waitUntil(() -> !taskHandler.getHandledTasks().isEmpty());
    final TaskEvent lockedTask = taskHandler.getHandledTasks().get(0);
    // when
    final TaskEvent result = clientRule.tasks().complete(lockedTask).payload("{ \"a\" : 2 }").execute();
    // then
    assertThat(result.getMetadata().getKey()).isEqualTo(task.getMetadata().getKey());
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
    TaskEvent taskEvent = eventRecorder.getTaskEvents(taskEvent("CREATE")).get(0);
    assertThat(taskEvent.getLockExpirationTime()).isNull();
    assertThat(taskEvent.getLockOwner()).isNull();
    taskEvent = eventRecorder.getTaskEvents(taskEvent("CREATED")).get(0);
    assertThat(taskEvent.getLockExpirationTime()).isNull();
    taskEvent = eventRecorder.getTaskEvents(taskEvent("LOCKED")).get(0);
    assertThat(taskEvent.getLockExpirationTime()).isNotNull();
    assertThat(taskEvent.getLockOwner()).isEqualTo("test");
}
Also used : RecordingTaskHandler(io.zeebe.broker.it.util.RecordingTaskHandler) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 5 with RecordingTaskHandler

use of io.zeebe.broker.it.util.RecordingTaskHandler 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)

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