Search in sources :

Example 1 with MAX_POOL_TYPE_SIZE

use of org.hisp.dhis.system.notification.NotificationMap.MAX_POOL_TYPE_SIZE in project dhis2-core by dhis2.

the class NotificationMapTest method testFirstSummaryToBeCreatedIsTheFirstOneToBeRemoved.

@Test
void testFirstSummaryToBeCreatedIsTheFirstOneToBeRemoved() {
    // Fill the map with jobs
    JobConfiguration jobConfiguration = new JobConfiguration(null, DATAVALUE_IMPORT, "userId", false);
    for (int i = 0; i < MAX_POOL_TYPE_SIZE; i++) {
        jobConfiguration.setUid(String.valueOf(i));
        mapToTest.addSummary(jobConfiguration, i);
    }
    // Add one more
    jobConfiguration.setUid(String.valueOf(MAX_POOL_TYPE_SIZE));
    mapToTest.addSummary(jobConfiguration, MAX_POOL_TYPE_SIZE);
    // Check that oldest job is not in the map anymore
    Optional<String> notPresentSummary = mapToTest.getJobSummariesForJobType(DATAVALUE_IMPORT).keySet().stream().filter(object -> object.equals("0")).findAny();
    Assertions.assertFalse(notPresentSummary.isPresent());
    // Add one more
    jobConfiguration.setUid(String.valueOf(MAX_POOL_TYPE_SIZE + 1));
    mapToTest.addSummary(jobConfiguration, MAX_POOL_TYPE_SIZE + 1);
    // Check that oldest job is not in the map anymore
    notPresentSummary = mapToTest.getJobSummariesForJobType(DATAVALUE_IMPORT).keySet().stream().filter(object -> object.equals("1")).findAny();
    Assertions.assertFalse(notPresentSummary.isPresent());
}
Also used : Test(org.junit.jupiter.api.Test) MAX_POOL_TYPE_SIZE(org.hisp.dhis.system.notification.NotificationMap.MAX_POOL_TYPE_SIZE) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) DATAVALUE_IMPORT(org.hisp.dhis.scheduling.JobType.DATAVALUE_IMPORT) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

Optional (java.util.Optional)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 DATAVALUE_IMPORT (org.hisp.dhis.scheduling.JobType.DATAVALUE_IMPORT)1 MAX_POOL_TYPE_SIZE (org.hisp.dhis.system.notification.NotificationMap.MAX_POOL_TYPE_SIZE)1 Assertions (org.junit.jupiter.api.Assertions)1 Test (org.junit.jupiter.api.Test)1