use of io.zeebe.broker.it.util.RecordingTaskHandler in project zeebe by zeebe-io.
the class BrokerRecoveryTest 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 BrokerRecoveryTest method shouldReceiveLockExpiredTasksAfterRestart.
@Test
public void shouldReceiveLockExpiredTasksAfterRestart() {
// given
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofSeconds(5)).lockOwner("test").handler(recordingTaskHandler).open();
waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
// when
restartBroker();
// wait until stream processor and scheduler process the lock task event which is not re-processed on recovery
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")));
}
Aggregations