Search in sources :

Example 1 with LoadedFilterManager

use of gov.cms.bfd.server.war.commons.LoadedFilterManager in project beneficiary-fhir-data by CMSgov.

the class LoadedFilterManagerIT method emptyFilters.

@Test
public void emptyFilters() {
    PipelineTestUtils.get().doTestWithDb((dataSource, entityManager) -> {
        final LoadedFilterManager filterManager = new LoadedFilterManager();
        filterManager.setEntityManager(entityManager);
        filterManager.init();
        // After init manager should have an empty filter list but a valid transaction time
        assertTrue(filterManager.getTransactionTime().isBefore(Instant.now()), "Expect transactionTime be before now");
        final List<LoadedFileFilter> beforeFilters = filterManager.getFilters();
        assertEquals(0, beforeFilters.size());
        final DateRangeParam testBound = new DateRangeParam().setLowerBoundExclusive(Date.from(Instant.now().plusSeconds(1)));
        assertFalse(filterManager.isInBounds(testBound));
        assertFalse(filterManager.isResultSetEmpty(INVALID_BENE, testBound));
        // Refresh the filter list
        filterManager.refreshFilters();
        // Should have zero filters
        assertTrue(filterManager.getTransactionTime().isBefore(Instant.now()), "Expect transactionTime be before now");
        final List<LoadedFileFilter> afterFilters = filterManager.getFilters();
        assertEquals(0, afterFilters.size());
        assertFalse(filterManager.isInBounds(testBound));
        assertFalse(filterManager.isResultSetEmpty(INVALID_BENE, testBound));
    });
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) LoadedFileFilter(gov.cms.bfd.server.war.commons.LoadedFileFilter) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) Test(org.junit.jupiter.api.Test)

Example 2 with LoadedFilterManager

use of gov.cms.bfd.server.war.commons.LoadedFilterManager in project beneficiary-fhir-data by CMSgov.

the class LoadedFilterManagerIT method isResultSetEmpty.

/**
 * Test isResultSetEmpty with one filter
 */
@Test
public void isResultSetEmpty() {
    PipelineTestUtils.get().doTestWithDb((dataSource, entityManager) -> {
        final LoadedFilterManager filterManager = new LoadedFilterManager();
        filterManager.setEntityManager(entityManager);
        filterManager.init();
        // Establish a before load time
        final Date beforeLoad = new Date();
        final DateRangeParam beforeLoadUnbounded = new DateRangeParam().setUpperBoundExclusive(beforeLoad);
        PipelineTestUtils.get().pauseMillis(10);
        loadData(dataSource, Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
        // Establish a time after load but before refresh
        PipelineTestUtils.get().pauseMillis(10);
        final Date beforeRefresh = new Date();
        final DateRangeParam beforeRefreshRange = new DateRangeParam(beforeRefresh, Date.from(Instant.now().plusMillis(5)));
        PipelineTestUtils.get().pauseMillis(10);
        filterManager.refreshFilters();
        // Establish a after refresh time
        final Date afterRefresh = Date.from(Instant.now().plusMillis(10));
        final DateRangeParam afterRefreshRange = new DateRangeParam(afterRefresh, Date.from(Instant.now().plusMillis(15)));
        // Assert on isInKnownBounds
        assertTrue(filterManager.isInBounds(beforeRefreshRange), "Known bound should include a time range before refresh");
        assertTrue(filterManager.isInBounds(afterRefreshRange), "Known bound includes time after refresh");
        assertFalse(filterManager.isInBounds(beforeLoadUnbounded), "Unbounded lower range always match null lastUpdated which are not known");
        // Assert on isResultSetEmpty
        assertTrue(filterManager.isResultSetEmpty(SAMPLE_BENE, beforeRefreshRange), "Expected date range to not have a matching filter");
        assertTrue(filterManager.isResultSetEmpty(INVALID_BENE, beforeRefreshRange), "Expected date range to not have a matching filter");
    });
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with LoadedFilterManager

use of gov.cms.bfd.server.war.commons.LoadedFilterManager in project beneficiary-fhir-data by CMSgov.

the class LoadedFilterManagerIT method refreshFilters.

@Test
public void refreshFilters() {
    PipelineTestUtils.get().doTestWithDb((dataSource, entityManager) -> {
        final LoadedFilterManager filterManager = new LoadedFilterManager();
        filterManager.setEntityManager(entityManager);
        filterManager.init();
        final Instant initialTransactionTime = filterManager.getTransactionTime();
        assertTrue(initialTransactionTime.isBefore(Instant.now().plusMillis(1)));
        loadData(dataSource, Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
        Date afterLoad = new Date();
        // Without a refresh, the manager should have an empty filter list
        final List<LoadedFileFilter> beforeFilters = filterManager.getFilters();
        assertEquals(0, beforeFilters.size());
        // Refresh the filter list
        filterManager.refreshFilters();
        Date afterRefresh = new Date();
        // Should have many filters
        final List<LoadedFileFilter> afterFilters = filterManager.getFilters();
        assertTrue(filterManager.getFirstBatchCreated().toEpochMilli() <= afterLoad.getTime());
        assertTrue(filterManager.getLastBatchCreated().toEpochMilli() <= afterRefresh.getTime());
        assertTrue(filterManager.getTransactionTime().toEpochMilli() > initialTransactionTime.toEpochMilli());
        assertTrue(afterFilters.size() > 1);
    });
}
Also used : LoadedFileFilter(gov.cms.bfd.server.war.commons.LoadedFileFilter) Instant(java.time.Instant) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with LoadedFilterManager

use of gov.cms.bfd.server.war.commons.LoadedFilterManager in project beneficiary-fhir-data by CMSgov.

the class LoadedFilterManagerIT method testWithMultipleRefreshes.

/**
 * Test isResultSetEmpty with multiple refreshes
 */
@Test
public void testWithMultipleRefreshes() {
    PipelineTestUtils.get().doTestWithDb((dataSource, entityManager) -> {
        final LoadedFilterManager filterManager = new LoadedFilterManager();
        filterManager.setEntityManager(entityManager);
        filterManager.init();
        loadData(dataSource, Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
        // Establish a couple of times
        PipelineTestUtils.get().pauseMillis(1000);
        final Date afterSampleA = new Date();
        PipelineTestUtils.get().pauseMillis(10);
        final Date afterSampleAPlus = new Date();
        final DateRangeParam afterSampleARange = new DateRangeParam(afterSampleA, afterSampleAPlus);
        // Refresh the filter list
        PipelineTestUtils.get().pauseMillis(10);
        filterManager.refreshFilters();
        // Test after refresh
        int after1Count = filterManager.getFilters().size();
        assertTrue(filterManager.isInBounds(afterSampleARange));
        assertTrue(filterManager.isResultSetEmpty(SAMPLE_BENE, afterSampleARange), "Expected date range to not have a matching filter");
        assertTrue(filterManager.isResultSetEmpty(INVALID_BENE, afterSampleARange), "Expected date range to not have a matching filter");
        // Refresh again (should do nothing)
        filterManager.refreshFilters();
        int after2Count = filterManager.getFilters().size();
        assertEquals(after1Count, after2Count);
        // Load some more data
        loadData(dataSource, Arrays.asList(StaticRifResourceGroup.SAMPLE_U.getResources()));
        PipelineTestUtils.get().pauseMillis(1000);
        final Date afterSampleU = new Date();
        final DateRangeParam aroundSampleU = new DateRangeParam(afterSampleA, afterSampleU);
        filterManager.refreshFilters();
        // Test after refresh
        assertFalse(filterManager.isResultSetEmpty(SAMPLE_BENE, aroundSampleU), "Expected date range to not have a matching filter");
        assertTrue(filterManager.isResultSetEmpty(INVALID_BENE, aroundSampleU), "Expected date range to not have a matching filter");
    });
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with LoadedFilterManager

use of gov.cms.bfd.server.war.commons.LoadedFilterManager in project beneficiary-fhir-data by CMSgov.

the class LoadedFilterManagerTest method testIsResultSetEmpty.

@Test
public void testIsResultSetEmpty() {
    final MockDb mockDb = new MockDb().insert(1, preDates[1]).insert(2, preDates[11]).insert(preBatches[0], preBatches[1], preBatches[2]);
    final List<LoadedFilterManager.LoadedTuple> tuples = mockDb.fetchAllTuples();
    final List<LoadedFileFilter> aFilters = LoadedFilterManager.buildFilters(tuples, mockDb::fetchById);
    assertEquals(2, aFilters.size());
    // Setup the manager and test a few lastUpdated ranges
    final LoadedFilterManager filterManagerA = new LoadedFilterManager();
    filterManagerA.set(aFilters, preDates[1], preBatches[2].getCreated());
    final DateRangeParam beforeRange = new DateRangeParam(Date.from(preDates[0]), Date.from(preDates[1]));
    assertFalse(filterManagerA.isInBounds(beforeRange));
    assertFalse(filterManagerA.isResultSetEmpty(SAMPLE_BENE, beforeRange));
    final DateRangeParam duringRange1 = new DateRangeParam(Date.from(preDates[2]), Date.from(preDates[3]));
    assertTrue(filterManagerA.isInBounds(duringRange1));
    assertFalse(filterManagerA.isResultSetEmpty(SAMPLE_BENE, duringRange1));
    assertTrue(filterManagerA.isResultSetEmpty(INVALID_BENE, duringRange1));
    final DateRangeParam duringRange2 = new DateRangeParam().setLowerBoundExclusive(Date.from(preDates[9])).setUpperBoundExclusive(Date.from(preDates[10]));
    assertTrue(filterManagerA.isInBounds(duringRange2));
    assertTrue(filterManagerA.isResultSetEmpty(SAMPLE_BENE, duringRange2));
    assertTrue(filterManagerA.isResultSetEmpty(INVALID_BENE, duringRange2));
    final DateRangeParam afterRange = new DateRangeParam(Date.from(preDates[20]), Date.from(preDates[21]));
    assertTrue(filterManagerA.isInBounds(afterRange));
    assertTrue(filterManagerA.isResultSetEmpty(SAMPLE_BENE, afterRange));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) LoadedFileFilter(gov.cms.bfd.server.war.commons.LoadedFileFilter) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) Test(org.junit.jupiter.api.Test)

Aggregations

LoadedFilterManager (gov.cms.bfd.server.war.commons.LoadedFilterManager)5 Test (org.junit.jupiter.api.Test)5 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)4 LoadedFileFilter (gov.cms.bfd.server.war.commons.LoadedFileFilter)3 Date (java.util.Date)3 Instant (java.time.Instant)1