Search in sources :

Example 1 with CoveragePagingRequest

use of gov.cms.ab2d.coverage.model.CoveragePagingRequest in project ab2d by CMSgov.

the class CoverageDriverUnitTest method beginPagingWhenCoveragePeriodsPresent.

@DisplayName("Paging coverage periods")
@Test
void beginPagingWhenCoveragePeriodsPresent() {
    when(coverageService.getCoveragePeriod(any(ContractForCoverageDTO.class), anyInt(), anyInt())).thenAnswer((invocationOnMock) -> {
        CoveragePeriod period = new CoveragePeriod();
        period.setContractNumber((invocationOnMock.getArgument(0).toString()));
        period.setMonth(invocationOnMock.getArgument(1));
        period.setYear(invocationOnMock.getArgument(2));
        return period;
    });
    int pagingSize = (int) ReflectionTestUtils.getField(driver, "PAGING_SIZE");
    when(coverageService.pageCoverage(any(CoveragePagingRequest.class))).thenAnswer((invocationMock) -> {
        CoveragePagingRequest request = invocationMock.getArgument(0);
        Optional<Long> cursor = request.getCursor();
        CoveragePagingRequest nextRequest = null;
        if (cursor.isPresent()) {
            long cursorValue = cursor.get();
            nextRequest = new CoveragePagingRequest(pagingSize, (cursorValue + pagingSize), request.getContract(), request.getJobStartTime());
        } else {
            nextRequest = new CoveragePagingRequest(pagingSize, (long) pagingSize, request.getContract(), request.getJobStartTime());
        }
        return new CoveragePagingResult(List.of(), nextRequest);
    });
    Job job = new Job();
    ContractDTO contract = new ContractDTO("Contract-0", null, AB2D_EPOCH.toOffsetDateTime(), null);
    when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO("Contract-0", contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));
    CoveragePagingResult firstCall = driver.pageCoverage(job, contract);
    assertNotNull(firstCall);
    assertTrue(firstCall.getNextRequest().isPresent());
    CoveragePagingRequest firstNextRequest = firstCall.getNextRequest().get();
    assertTrue(firstNextRequest.getCursor().isPresent());
    assertEquals(pagingSize, firstNextRequest.getCursor().get());
    CoveragePagingResult secondCall = driver.pageCoverage(firstNextRequest);
    assertNotNull(secondCall);
    assertTrue(secondCall.getNextRequest().isPresent());
    CoveragePagingRequest secondNextRequest = secondCall.getNextRequest().get();
    assertTrue(secondNextRequest.getCursor().isPresent());
    assertEquals((2L * pagingSize), secondNextRequest.getCursor().get());
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with CoveragePagingRequest

use of gov.cms.ab2d.coverage.model.CoveragePagingRequest in project ab2d by CMSgov.

the class CoverageDriverUnitTest method failureToPageCausesExceptions.

@DisplayName("When paging coverage fails throw coverage driver exception")
@Test
void failureToPageCausesExceptions() {
    when(coverageService.pageCoverage(any())).thenThrow(RuntimeException.class);
    CoverageDriver driver = new CoverageDriverImpl(null, null, coverageService, null, null, null, null);
    ContractForCoverageDTO contract = new ContractForCoverageDTO();
    contract.setContractNumber("contractNum");
    CoverageDriverException exception = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(new CoveragePagingRequest(1000, null, contract, OffsetDateTime.now())));
    assertTrue(exception.getMessage().contains("coverage driver failing preconditions"));
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with CoveragePagingRequest

use of gov.cms.ab2d.coverage.model.CoveragePagingRequest in project ab2d by CMSgov.

the class CoverageDriverStub method pageCoverage.

@Override
public CoveragePagingResult pageCoverage(CoveragePagingRequest request) {
    CoveragePagingRequest nextRequest = getNextRequest(request, null, request.getContract());
    List<CoverageSummary> results = getSummaries(request);
    return new CoveragePagingResult(results, nextRequest);
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult)

Example 4 with CoveragePagingRequest

use of gov.cms.ab2d.coverage.model.CoveragePagingRequest in project ab2d by CMSgov.

the class ContractProcessorUnitTest method whenBlockingQueueFullPatientsNotSkipped.

@Test
@DisplayName("When round robin blocking queue is full, patients should not be skipped")
void whenBlockingQueueFullPatientsNotSkipped() throws InterruptedException {
    when(coverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 1), new CoveragePagingRequest(1, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 1), null));
    jobChannelService.sendUpdate(jobUuid, JobMeasure.PATIENTS_EXPECTED, 2);
    jobChannelService.sendUpdate(jobUuid, JobMeasure.FAILURE_THRESHHOLD, 1);
    when(requestQueue.size(anyString())).thenReturn(1_0000_000);
    ExecutorService singleThreadedExecutor = Executors.newSingleThreadExecutor();
    Runnable testRunnable = () -> cut.process(job);
    Future<?> future = singleThreadedExecutor.submit(testRunnable);
    Thread.sleep(5000);
    assertFalse(future.isDone());
    future.cancel(true);
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with CoveragePagingRequest

use of gov.cms.ab2d.coverage.model.CoveragePagingRequest in project ab2d by CMSgov.

the class ContractProcessorUnitTest method whenManyPatientIdsAreProcessed_shouldUpdatePercentageCompletedMultipleTimes.

@Test
@DisplayName("When many patientId are present, 'PercentageCompleted' should be updated many times")
void whenManyPatientIdsAreProcessed_shouldUpdatePercentageCompletedMultipleTimes() {
    when(coverageDriver.numberOfBeneficiariesToProcess(any(Job.class), any(ContractDTO.class))).thenReturn(18);
    when(coverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), new CoveragePagingRequest(2, null, contractForCoverageDTO, OffsetDateTime.now()))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 2), null));
    jobChannelService.sendUpdate(jobUuid, JobMeasure.PATIENTS_EXPECTED, 18);
    jobChannelService.sendUpdate(jobUuid, JobMeasure.FAILURE_THRESHHOLD, 10);
    var jobOutputs = cut.process(job);
    assertEquals(6, jobRepository.getUpdatePercentageCompletedCount());
    verify(patientClaimsProcessor, atLeast(1)).process(any());
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)21 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)19 DisplayName (org.junit.jupiter.api.DisplayName)15 Test (org.junit.jupiter.api.Test)15 CoverageSummary (gov.cms.ab2d.coverage.model.CoverageSummary)13 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)12 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)11 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)10 Identifiers (gov.cms.ab2d.coverage.model.Identifiers)10 LinkedHashSet (java.util.LinkedHashSet)10 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)9 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)9 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)9 FilterOutByDate (gov.cms.ab2d.filter.FilterOutByDate)9 OffsetDateTime (java.time.OffsetDateTime)9 Collections.disjoint (java.util.Collections.disjoint)9 List (java.util.List)9 Map (java.util.Map)9 Optional (java.util.Optional)9 CoverageDelta (gov.cms.ab2d.coverage.model.CoverageDelta)8