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