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());
}
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"));
}
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);
}
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);
}
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());
}
Aggregations