Search in sources :

Example 1 with LoadedFileFilter

use of gov.cms.bfd.server.war.commons.LoadedFileFilter 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 LoadedFileFilter

use of gov.cms.bfd.server.war.commons.LoadedFileFilter 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 3 with LoadedFileFilter

use of gov.cms.bfd.server.war.commons.LoadedFileFilter 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)

Example 4 with LoadedFileFilter

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

the class LoadedFilterManagerTest method buildOneFilter.

@Test
public void buildOneFilter() {
    final MockDb mockDb = new MockDb().insert(1, preDates[0]).insert(preBatches[0]);
    final List<LoadedFileFilter> filters = LoadedFilterManager.buildFilters(mockDb.fetchAllTuples(), mockDb::fetchById);
    assertEquals(1, filters.size());
    // Test the filter
    final DateRangeParam during1 = new DateRangeParam(Date.from(preDates[1]), Date.from(preDates[2]));
    assertTrue(filters.get(0).matchesDateRange(during1));
    assertEquals(1, filters.get(0).getBatchesCount());
    assertTrue(filters.get(0).mightContain(SAMPLE_BENE));
    assertFalse(filters.get(0).mightContain(INVALID_BENE));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) LoadedFileFilter(gov.cms.bfd.server.war.commons.LoadedFileFilter) Test(org.junit.jupiter.api.Test)

Example 5 with LoadedFileFilter

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

the class LoadedFilterTest method testMightContain.

@Test
public void testMightContain() {
    // Very small test on the Guava implementation of BloomFilters. Assume this package works.
    final BloomFilter smallFilter = LoadedFileFilter.createFilter(10);
    smallFilter.putString("1");
    smallFilter.putString("100");
    smallFilter.putString("100");
    final LoadedFileFilter filter1 = new LoadedFileFilter(1, 1, Instant.now().minusSeconds(10), Instant.now().minusSeconds(5), smallFilter);
    assertTrue(filter1.mightContain("1"));
    assertFalse(filter1.mightContain("888"));
    assertFalse(filter1.mightContain("BAD"));
}
Also used : LoadedFileFilter(gov.cms.bfd.server.war.commons.LoadedFileFilter) BloomFilter(org.apache.spark.util.sketch.BloomFilter) Test(org.junit.jupiter.api.Test)

Aggregations

LoadedFileFilter (gov.cms.bfd.server.war.commons.LoadedFileFilter)6 Test (org.junit.jupiter.api.Test)6 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)4 LoadedFilterManager (gov.cms.bfd.server.war.commons.LoadedFilterManager)3 Date (java.util.Date)2 BloomFilter (org.apache.spark.util.sketch.BloomFilter)2 DateParam (ca.uhn.fhir.rest.param.DateParam)1 Instant (java.time.Instant)1