use of org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testAutomaticRetrySlow.
@Test
@Tag(TestTags.SLOW)
void testAutomaticRetrySlow() {
TestTask task = null;
// Test automatic retries with default limit (+ backoff timing)
task = TestTask.builder().schedule(TaskSchedule.builder().priority(TaskSchedule.PRIORITY_HIGH).build()).build();
for (int i = 0; i < TaskSchedule.MIN_RETRIES_DEFAULT; i++) {
task.andThen(BasicCommand.builder().throwNPE(true).build());
}
task.andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
Instant start = now();
tasks.submit(task);
data.awaitFinished();
Duration duration = Duration.between(start, now());
assertThat(data.getExecutions(), equalTo(TaskSchedule.MIN_RETRIES_DEFAULT + 1));
assertThat(data.getCounter(), equalTo(1));
// Assume that the duration grows more than linearly (2sec * N)
assertThat(duration.getSeconds(), greaterThan(valueOf(TaskSchedule.MIN_RETRIES_DEFAULT * 2)));
data.reset();
}
use of org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testManualRetry.
@Test
void testManualRetry() {
TestTask task = null;
// Test simple manual retry
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(1));
data.reset();
// Test simple manual retry, over limit
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(RetryCommand.builder().build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(2));
assertThat(data.getCounter(), equalTo(0));
data.reset();
// Test manual retry, with schedule
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).interval(ofSeconds(2)).build()).build().andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build()).andThen(RetryCommand.builder().build()).andThen(BasicCommand.builder().increment(true).build()).andThen(RetryCommand.builder().build()).andThen(RetryCommand.builder().build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(6));
assertThat(data.getCounter(), equalTo(3));
data.reset();
}
use of org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testForceRetry.
@Test
void testForceRetry() {
TestTask task = null;
// Test simple force retry
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Request one more over limit (1st)
RetryCommand.builder().force(true).build()).andThen(// OK (2nd)
BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(3));
assertThat(data.getCounter(), equalTo(1));
data.reset();
// Test force retry, over limit
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Request at least two retries (1st)
RetryCommand.builder().minRetries(2).build()).andThen(// This should fail, but is force
RetryCommand.builder().force(true).build()).andThen(// Force again
RetryCommand.builder().force(true).build()).andThen(// Works
BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(5));
assertThat(data.getCounter(), equalTo(1));
data.reset();
}
use of org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TaskManagerTest method testAutomaticRetry.
@Test
void testAutomaticRetry() {
TestTask task = null;
// Test simple automatic retry, with default minRetries
// Test that there are no repeats after success
task = TestTask.builder().schedule(TaskSchedule.builder().build()).build().andThen(BasicCommand.builder().throwNPE(true).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(1));
data.reset();
// Test simple automatic retry with too little minRetries
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().throwNPE(true).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(0));
data.reset();
// Test automatic retry with periodic tasks
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).interval(ofSeconds(2)).build()).build().andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(4));
assertThat(data.getCounter(), equalTo(3));
data.reset();
// Test automatic retry with periodic tasks
// Even if the interval is very small
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(3).interval(ofMillis(200)).build()).build().andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(6));
assertThat(data.getCounter(), equalTo(3));
data.reset();
// Even for periodic tasks, passing retry limit stops it
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).interval(ofMillis(200)).build()).build().andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().throwNPE(true).build()).andThen(BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(4));
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 testLimitRetry.
@Test
void testLimitRetry() {
TestTask task = null;
// Test simple retry
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Request at least two retries (1st)
RetryCommand.builder().minRetries(2).build()).andThen(// OK (2nd)
BasicCommand.builder().increment(true).build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(3));
assertThat(data.getCounter(), equalTo(1));
data.reset();
// Test simple retry, over limit
task = TestTask.builder().schedule(TaskSchedule.builder().minRetries(1).build()).build().andThen(RetryCommand.builder().build()).andThen(// Request at least two retries (1st)
RetryCommand.builder().minRetries(2).build()).andThen(// But here is the second
RetryCommand.builder().build()).andThen(BasicCommand.builder().increment(true).build());
tasks.submit(task);
data.awaitFinished();
assertThat(data.getExecutions(), equalTo(3));
assertThat(data.getCounter(), equalTo(0));
data.reset();
}
Aggregations