Search in sources :

Example 1 with CoverageJobStatus

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

the class CoverageDriverTest method normalExecution.

@DisplayName("Normal workflow functions")
@Test
void normalExecution() {
    org.hl7.fhir.dstu3.model.Bundle bundle1 = buildBundle(0, 10);
    bundle1.setLink(singletonList(new org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent().setRelation(org.hl7.fhir.dstu3.model.Bundle.LINK_NEXT)));
    org.hl7.fhir.dstu3.model.Bundle bundle2 = buildBundle(10, 20);
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt(), anyInt())).thenReturn(bundle1);
    when(bfdClient.requestNextBundleFromServer(eq(STU3), any(org.hl7.fhir.dstu3.model.Bundle.class))).thenReturn(bundle2);
    processor.queueCoveragePeriod(january, false);
    CoverageJobStatus status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    driver.loadMappingJob();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    sleep(1000);
    processor.monitorMappingJobs();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    processor.insertJobResults();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUCCESSFUL, status);
}
Also used : CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with CoverageJobStatus

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

the class CoverageUpdateAndProcessorTest method mappingRetried.

@DisplayName("Mapping failure leads to retry but still can succeed on retry")
@Test
void mappingRetried() {
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt())).thenThrow(new RuntimeException("oops"));
    processor.queueCoveragePeriod(january, false);
    CoverageJobStatus status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    driver.loadMappingJob();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    sleep(1000);
    processor.monitorMappingJobs();
    assertTrue(coverageSearchEventRepo.findAll().stream().anyMatch(event -> event.getNewStatus() == CoverageJobStatus.FAILED));
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    reset(bfdClient);
    org.hl7.fhir.dstu3.model.Bundle bundle1 = buildBundle(0, 10);
    bundle1.setLink(Collections.singletonList(new org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent().setRelation(org.hl7.fhir.dstu3.model.Bundle.LINK_NEXT)));
    org.hl7.fhir.dstu3.model.Bundle bundle2 = buildBundle(10, 20);
    Mockito.clearInvocations();
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt(), anyInt())).thenReturn(bundle1);
    when(bfdClient.requestNextBundleFromServer(eq(STU3), any(org.hl7.fhir.dstu3.model.Bundle.class))).thenReturn(bundle2);
    driver.loadMappingJob();
    sleep(1000);
    processor.monitorMappingJobs();
    sleep(1000);
    processor.insertJobResults();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUCCESSFUL, status);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) WorkerDataSetup(gov.cms.ab2d.worker.util.WorkerDataSetup) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Autowired(org.springframework.beans.factory.annotation.Autowired) STU3(gov.cms.ab2d.fhir.FhirVersion.STU3) Constants(gov.cms.ab2d.common.util.Constants) ContractRepository(gov.cms.ab2d.common.repository.ContractRepository) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) DateUtil(gov.cms.ab2d.common.util.DateUtil) Contract(gov.cms.ab2d.common.model.Contract) CoverageSearchRepository(gov.cms.ab2d.coverage.repository.CoverageSearchRepository) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) CoverageService(gov.cms.ab2d.coverage.service.CoverageService) Test(org.junit.jupiter.api.Test) AB2D_EPOCH(gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CoveragePeriodRepository(gov.cms.ab2d.coverage.repository.CoveragePeriodRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) PdpClientService(gov.cms.ab2d.common.service.PdpClientService) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) TemporalAdjusters(java.time.temporal.TemporalAdjusters) CoverageDataSetup(gov.cms.ab2d.coverage.util.CoverageDataSetup) BFDClient(gov.cms.ab2d.bfd.client.BFDClient) Mockito.mock(org.mockito.Mockito.mock) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AB2DPostgresqlContainer(gov.cms.ab2d.common.util.AB2DPostgresqlContainer) PostgreSQLContainer(org.testcontainers.containers.PostgreSQLContainer) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Nullable(javax.annotation.Nullable) Container(org.testcontainers.junit.jupiter.Container) ContractWorkerClient(gov.cms.ab2d.worker.service.ContractWorkerClient) SPONSOR_ROLE(gov.cms.ab2d.common.model.Role.SPONSOR_ROLE) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) Job(gov.cms.ab2d.common.model.Job) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.when(org.mockito.Mockito.when) BENEFICIARY_ID(gov.cms.ab2d.fhir.IdentifierUtils.BENEFICIARY_ID) DisplayName(org.junit.jupiter.api.DisplayName) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Collectors.toList(java.util.stream.Collectors.toList) ChronoUnit(java.time.temporal.ChronoUnit) DayOfWeek(java.time.DayOfWeek) Properties(gov.cms.ab2d.common.model.Properties) CoverageSearchEventRepository(gov.cms.ab2d.coverage.repository.CoverageSearchEventRepository) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with CoverageJobStatus

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

the class CoverageUpdateAndProcessorTest method iterateFailingJob.

private CoverageJobStatus iterateFailingJob() {
    CoverageJobStatus status;
    driver.loadMappingJob();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    sleep(1000);
    processor.monitorMappingJobs();
    status = coverageService.getSearchStatus(january.getId());
    return status;
}
Also used : CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus)

Example 4 with CoverageJobStatus

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

the class CoverageUpdateAndProcessorTest method mappingFailsAfterXRetries.

@DisplayName("Mapping failure after x retries")
@Test
void mappingFailsAfterXRetries() {
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt())).thenThrow(new RuntimeException("oops"));
    processor.queueCoveragePeriod(january, false);
    CoverageJobStatus status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    // Should retry x times
    for (int i = 0; i < maxRetries; i++) {
        status = iterateFailingJob();
        assertEquals(CoverageJobStatus.SUBMITTED, status);
    }
    status = iterateFailingJob();
    assertEquals(CoverageJobStatus.FAILED, status);
}
Also used : CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with CoverageJobStatus

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

the class CoverageUpdateAndProcessorTest method normalExecution.

@DisplayName("Normal workflow functions")
@Test
void normalExecution() throws CoverageDriverException, InterruptedException {
    org.hl7.fhir.dstu3.model.Bundle bundle1 = buildBundle(0, 10);
    bundle1.setLink(Collections.singletonList(new org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent().setRelation(org.hl7.fhir.dstu3.model.Bundle.LINK_NEXT)));
    org.hl7.fhir.dstu3.model.Bundle bundle2 = buildBundle(10, 20);
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt(), anyInt())).thenReturn(bundle1);
    when(bfdClient.requestNextBundleFromServer(eq(STU3), any(org.hl7.fhir.dstu3.model.Bundle.class))).thenReturn(bundle2);
    processor.queueCoveragePeriod(january, false);
    CoverageJobStatus status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    driver.loadMappingJob();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    sleep(1000);
    processor.monitorMappingJobs();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    processor.insertJobResults();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUCCESSFUL, status);
}
Also used : CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)13 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)7 DisplayName (org.junit.jupiter.api.DisplayName)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)2 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)2 BFDClient (gov.cms.ab2d.bfd.client.BFDClient)1 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)1 PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)1 PropertiesDTO (gov.cms.ab2d.common.dto.PropertiesDTO)1 Contract (gov.cms.ab2d.common.model.Contract)1 Job (gov.cms.ab2d.common.model.Job)1 Properties (gov.cms.ab2d.common.model.Properties)1 SPONSOR_ROLE (gov.cms.ab2d.common.model.Role.SPONSOR_ROLE)1 ContractRepository (gov.cms.ab2d.common.repository.ContractRepository)1 PdpClientService (gov.cms.ab2d.common.service.PdpClientService)1 PropertiesService (gov.cms.ab2d.common.service.PropertiesService)1 AB2DPostgresqlContainer (gov.cms.ab2d.common.util.AB2DPostgresqlContainer)1 Constants (gov.cms.ab2d.common.util.Constants)1