Search in sources :

Example 1 with DbOpsStatusCondition

use of io.stackgres.common.crd.sgdbops.DbOpsStatusCondition in project stackgres by ongres.

the class DbOpLauncherImplTest method givenAValidDbOpsRetry_shouldSetRunningConditionsBeforeExecutingTheJob.

@Test
void givenAValidDbOpsRetry_shouldSetRunningConditionsBeforeExecutingTheJob() {
    ArgumentCaptor<StackGresDbOps> captor = ArgumentCaptor.forClass(StackGresDbOps.class);
    when(securityUpgradeJob.runJob(captor.capture(), any())).thenAnswer(invocation -> getClusterRestartStateUni());
    Instant previousOpStarted = Instant.now();
    dbOps.setStatus(new StackGresDbOpsStatus());
    dbOps.getStatus().setOpStarted(previousOpStarted.toString());
    dbOps.getStatus().setOpRetries(0);
    dbOps.getStatus().setConditions(Seq.of(DbOpsStatusCondition.DB_OPS_FALSE_RUNNING, DbOpsStatusCondition.DB_OPS_FALSE_COMPLETED, DbOpsStatusCondition.DB_OPS_FAILED).map(DbOpsStatusCondition::getCondition).peek(condition -> condition.setLastTransitionTime(previousOpStarted.toString())).toList());
    mockKubeDb.addOrReplaceDbOps(dbOps);
    dbOpLauncher.launchDbOp(randomDbOpsName, namespace);
    StackGresDbOps captured = captor.getValue();
    assertNotNull(captured.getStatus().getOpStarted());
    assertTrue(Instant.parse(captured.getStatus().getOpStarted()).isBefore(Instant.now()));
    assertEquals(1, captured.getStatus().getOpRetries());
    var conditions = captured.getStatus().getConditions();
    assertNotNull(conditions);
    assertEquals(3, conditions.size());
    assertTrue(() -> conditions.stream().anyMatch(DbOpsStatusCondition.DB_OPS_RUNNING::isCondition));
    assertTrue(() -> conditions.stream().anyMatch(DbOpsStatusCondition.DB_OPS_FALSE_COMPLETED::isCondition));
    assertTrue(() -> conditions.stream().anyMatch(DbOpsStatusCondition.DB_OPS_FALSE_FAILED::isCondition));
}
Also used : StackGresDbOpsStatus(io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus) Instant(java.time.Instant) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) DbOpsStatusCondition(io.stackgres.common.crd.sgdbops.DbOpsStatusCondition) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 DbOpsStatusCondition (io.stackgres.common.crd.sgdbops.DbOpsStatusCondition)1 StackGresDbOps (io.stackgres.common.crd.sgdbops.StackGresDbOps)1 StackGresDbOpsStatus (io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus)1 Instant (java.time.Instant)1 Test (org.junit.jupiter.api.Test)1