use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testInputs.
@Test
void testInputs() {
TestTask task = null;
// Zero period is OK, but not recommended
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).interval(Duration.ZERO).build()).build().andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(2));
data.reset();
try {
TaskSchedule.builder().minRetries(-1).build();
fail("Illegal argument.");
} catch (IllegalArgumentException ex) {
// OK
}
try {
TaskSchedule.builder().interval(Duration.ofSeconds(-1)).build();
fail("Illegal argument.");
} catch (IllegalArgumentException ex) {
// OK
}
}
use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testDelay.
@Test
void testDelay() {
TestTask task = null;
// Throw an exception after delaying an increment
// It will fails since delay is executed only on success
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Throw but delay
BasicCommand.builder().throwNPE(true).delayIncrement(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(0));
data.reset();
// Increment normally + delayed
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(BasicCommand.builder().increment(true).delayIncrement(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(2));
data.reset();
}
use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testFinallyExecute.
@Test
void testFinallyExecute() {
TestTask task = null;
// Normally fail
// Finally is always executed
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(BasicCommand.builder().throwNPE(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(0));
assertThat(data.getFinallyExecuteAttempts(), equalTo(1));
data.reset();
// Throw an exception finally execute an increment
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Throw
BasicCommand.builder().throwNPE(true).build()).finallyExecute(// But increment in finally
BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(1));
assertThat(data.getFinallyExecuteAttempts(), equalTo(1));
assertThat(data.getFinallyExecuteSuccess(), equalTo(1));
data.reset();
// Throw in finally
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Throw
BasicCommand.builder().throwNPE(true).build()).finallyExecute(// Throw again
BasicCommand.builder().throwNPE(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(0));
assertThat(data.getFinallyExecuteAttempts(), equalTo(1));
assertThat(data.getFinallyExecuteSuccess(), equalTo(0));
data.reset();
}
use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class Convert method convert.
public TaskRest convert(Task data) {
TaskRest res = new TaskRest();
res.setId(data.getId());
res.setData(data.getData());
res.setSchedule(convert(data.getSchedule()));
res.setType(data.getType());
return res;
}
use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class DataCollectingWorker method finallyExecute.
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) {
TestTask task = (TestTask) aTask;
try {
Command command = task.getFinalCommand();
if (command != null)
command.execute(ctl, task);
data.recordFinallyExecuteSuccess();
} finally {
data.recordCounter(task.getCounter());
data.recordFinallyExecuteAttempt();
data.signalFinished();
}
}
Aggregations