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