Search in sources :

Example 11 with Task

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
    }
}
Also used : TestTask(org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 12 with Task

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();
}
Also used : TestTask(org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 13 with Task

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();
}
Also used : TestTask(org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 14 with Task

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;
}
Also used : TaskRest(org.bf2.srs.fleetmanager.rest.privateapi.beans.TaskRest)

Example 15 with Task

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();
    }
}
Also used : Command(org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask.Command) TestTask(org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask)

Aggregations

TestTask (org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask)10 Test (org.junit.jupiter.api.Test)9 QuarkusTest (io.quarkus.test.junit.QuarkusTest)8 Transactional (javax.transaction.Transactional)8 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)7 RegistryDeploymentData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData)4 List (java.util.List)3 ProvisionRegistryTenantTask (org.bf2.srs.fleetmanager.execution.impl.tasks.ProvisionRegistryTenantTask)3 Duration (java.time.Duration)2 Instant (java.time.Instant)2 Collectors.toList (java.util.stream.Collectors.toList)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 DeprovisionRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask)2 Task (org.bf2.srs.fleetmanager.execution.manager.Task)2 WorkerContext (org.bf2.srs.fleetmanager.execution.manager.WorkerContext)2 TenantNotFoundServiceException (org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException)2 TenantManagerConfig (org.bf2.srs.fleetmanager.spi.tenants.model.TenantManagerConfig)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2