use of com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask in project hub-alert by blackducksoftware.
the class NotificationRemovalTest method testDeletion.
@Test
@Ignore
@Disabled
public void testDeletion() throws IntegrationException, InterruptedException {
providerConfig = createBlackDuckConfiguration();
OffsetDateTime testStartTime = OffsetDateTime.now();
OffsetDateTime notificationCreatedAtTime = OffsetDateTime.now();
// create 1000 processed notifications not for removal
createABatchOfNotifications(providerConfig, testStartTime, true);
// create 9000 for removal with varying dates and processed flags
for (int index = 0; index < 9; index++) {
boolean processed = index % 2 == 0 ? true : false;
// update the createdAt time to be 1 month older
notificationCreatedAtTime = notificationCreatedAtTime.minusMonths(1);
createABatchOfNotifications(providerConfig, notificationCreatedAtTime, processed);
}
OffsetDateTime oldestNotificationCreationTime = notificationCreatedAtTime;
purgeTask = new PurgeTask(schedulingDescriptorKey, taskScheduler, notificationAccessor, systemMessageAccessor, taskManager, configurationModelConfigurationAccessor);
LocalDateTime startTime = LocalDateTime.now();
WaitJob<Boolean> waitJob = createWaitJob(startTime, () -> {
List<AlertNotificationModel> notificationsInDatabase = getAllNotificationsInDatabase(oldestNotificationCreationTime, testStartTime);
return notificationsInDatabase.size() == BATCH_SIZE && notificationsInDatabase.stream().allMatch(AlertNotificationModel::getProcessed);
});
purgeTask.runTask();
boolean isComplete = waitJob.waitFor();
logTimeElapsedWithMessage("Purge of notifications duration: %s", startTime, LocalDateTime.now());
List<AlertNotificationModel> remainingNotifications = getAllNotificationsInDatabase(oldestNotificationCreationTime, testStartTime);
assertTrue(isComplete);
assertEquals(BATCH_SIZE, remainingNotifications.size());
}
use of com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask in project hub-alert by blackducksoftware.
the class PurgeTaskTest method cronExpressionNotDefault.
@Test
public void cronExpressionNotDefault() {
final String notDefaultValue = "44";
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, null, null, ConfigContextEnum.GLOBAL);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(SchedulingDescriptor.KEY_PURGE_DATA_FREQUENCY_DAYS);
configurationFieldModel.setFieldValue(notDefaultValue);
configurationModel.put(configurationFieldModel);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
PurgeTask task = new PurgeTask(new SchedulingDescriptorKey(), null, null, null, null, configurationModelConfigurationAccessor);
String cronWithNotDefault = task.scheduleCronExpression();
String expectedCron = String.format(PurgeTask.CRON_FORMAT, notDefaultValue);
assertEquals(expectedCron, cronWithNotDefault);
}
Aggregations