use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase in project stackgres by ongres.
the class DistributedLogsClusterReconciliatorTest method testReconciliationWithRetentionUpdated_isPerformedWithoutUpdatingRetention.
@Test
void testReconciliationWithRetentionUpdated_isPerformedWithoutUpdatingRetention() throws Exception {
when(propertyContext.getString(same(DistributedLogsControllerProperty.DISTRIBUTEDLOGS_CONTROLLER_POD_NAME))).thenReturn("stackgres-0");
StackGresDistributedLogsContext distributedLogsContext = getDistributedLogsContext();
StackGresDistributedLogsStatusDatabase databaseStatus = new StackGresDistributedLogsStatusDatabase();
databaseStatus.setName("stackgres_stackgres");
databaseStatus.setRetention("1 minute");
distributedLogsContext.getDistributedLogs().getStatus().setDatabases(Seq.of(databaseStatus).toList());
Assertions.assertFalse(reconciliator.reconcile(null, distributedLogsContext).result().get());
verify(databaseReconciliator, times(1)).existsDatabase(any(), any());
verify(databaseReconciliator, times(1)).createDatabase(any(), any());
verify(databaseReconciliator, times(0)).updateRetention(any(), any(), any(), any());
verify(databaseReconciliator, times(2)).reconcileRetention(any(), any(), any(), any());
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase in project stackgres by ongres.
the class DistributedLogsClusterReconciliatorTest method testReconciliationWithEmptyDatabaseStatus_isPerformed.
@Test
void testReconciliationWithEmptyDatabaseStatus_isPerformed() throws Exception {
when(propertyContext.getString(same(DistributedLogsControllerProperty.DISTRIBUTEDLOGS_CONTROLLER_POD_NAME))).thenReturn("stackgres-0");
StackGresDistributedLogsContext distributedLogsContext = getDistributedLogsContext();
StackGresDistributedLogsStatusDatabase databaseStatus = new StackGresDistributedLogsStatusDatabase();
databaseStatus.setName("stackgres_stackgres");
distributedLogsContext.getDistributedLogs().getStatus().setDatabases(Seq.of(databaseStatus).toList());
Assertions.assertTrue(reconciliator.reconcile(null, distributedLogsContext).result().get());
verify(databaseReconciliator, times(1)).existsDatabase(any(), any());
verify(databaseReconciliator, times(1)).createDatabase(any(), any());
verify(databaseReconciliator, times(2)).updateRetention(any(), any(), any(), any());
verify(databaseReconciliator, times(2)).reconcileRetention(any(), any(), any(), any());
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatusDatabase in project stackgres by ongres.
the class DistributedLogsClusterReconciliator method updateStatus.
private boolean updateStatus(StackGresDistributedLogs distributedLogs, String database, String retention) {
Optional<StackGresDistributedLogsStatusDatabase> foundDistributedLogsDatabase = distributedLogs.getStatus().getDatabases().stream().filter(databaseStatus -> databaseStatus.getName().equals(database)).findAny();
final StackGresDistributedLogsStatusDatabase distributedLogsDatabase = foundDistributedLogsDatabase.orElseGet(() -> new StackGresDistributedLogsStatusDatabase());
if (!foundDistributedLogsDatabase.isPresent()) {
distributedLogs.getStatus().getDatabases().add(distributedLogsDatabase);
}
if (Objects.isNull(distributedLogsDatabase.getName()) || !Objects.equals(retention, distributedLogsDatabase.getRetention())) {
distributedLogsDatabase.setName(database);
distributedLogsDatabase.setRetention(retention);
return true;
}
return false;
}
Aggregations