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