use of org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class DataCollectingWorker method execute.
@Override
public void execute(Task aTask, WorkerContext ctl) {
boolean finished = false;
try {
TestTask task = (TestTask) aTask;
Command command = task.getCommands().peekFirst();
if (command != null && command.done()) {
task.getCommands().removeFirst();
command = task.getCommands().peekFirst();
}
if (command != null) {
command.execute(ctl, task);
} else {
// Do not record stop caused by end of commands
finished = true;
ctl.stop();
}
data.recordSuccess();
} catch (RetryExecutionControlException ex) {
if (ex.isForce())
data.recordForceRetry();
else
data.recordRetry();
throw ex;
} catch (StopExecutionControlException ex) {
if (!finished)
data.recordStop();
throw ex;
} catch (Exception ex) {
data.recordException();
throw ex;
} finally {
if (!finished)
data.recordExecution();
}
}
use of org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask 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.impl.tasks.TestTask 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.impl.tasks.TestTask 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.impl.tasks.TestTask 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