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));
}
Aggregations