Search in sources :

Example 1 with PurgeTask

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());
}
Also used : LocalDateTime(java.time.LocalDateTime) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) OffsetDateTime(java.time.OffsetDateTime) PurgeTask(com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask) Ignore(org.junit.Ignore) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with PurgeTask

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);
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) SchedulingDescriptorKey(com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) SchedulingDescriptorKey(com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) PurgeTask(com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask) Test(org.junit.jupiter.api.Test)

Aggregations

PurgeTask (com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask)2 Test (org.junit.jupiter.api.Test)2 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)1 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 SchedulingDescriptorKey (com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)1 LocalDateTime (java.time.LocalDateTime)1 OffsetDateTime (java.time.OffsetDateTime)1 Ignore (org.junit.Ignore)1 Disabled (org.junit.jupiter.api.Disabled)1