use of io.zeebe.client.event.TaskEvent 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.client.event.TaskEvent 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.client.event.TaskEvent 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.client.event.TaskEvent in project zeebe by zeebe-io.
the class TaskTopicSubscriptionTest method shouldReceiveTaskPOJOEvents.
@Test
public void shouldReceiveTaskPOJOEvents() {
// given
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").addCustomHeader("key", "value").payload("{}").retries(2).execute();
final RecordingTaskPOJOEventHandler handler = new RecordingTaskPOJOEventHandler();
// when
clientRule.topics().newSubscription(clientRule.getDefaultTopic()).startAtHeadOfTopic().taskEventHandler(handler).name("sub-1").open();
// then
TestUtil.waitUntil(() -> handler.numRecordedEvents() == 2);
final TaskEvent event1 = handler.getEvent(0);
assertThat(event1.getState()).isEqualTo("CREATE");
assertThat(event1.getHeaders()).isEmpty();
assertThat(event1.getCustomHeaders()).containsExactly(entry("key", "value"));
assertThat(event1.getLockExpirationTime()).isNull();
assertThat(event1.getLockOwner()).isNull();
assertThat(event1.getRetries()).isEqualTo(2);
assertThat(event1.getType()).isEqualTo("foo");
assertThat(event1.getPayload()).isEqualTo("{}");
final TaskEvent event2 = handler.getEvent(1);
assertThat(event2.getState()).isEqualTo("CREATED");
}
use of io.zeebe.client.event.TaskEvent 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");
}
Aggregations