### Question:
AggregationEngineHealthCheck extends HealthCheck { @Override public Result check() { Result result = Result.healthy(); if (!aggregationEngine.isRunning()) { result = Result.unhealthy("Aggregation Engine instance: " + aggregationEngine.getAggregatorID() + " in error state"); } return result; } @Inject  AggregationEngineHealthCheck(AggregationEngine aggregationEngine); @Override Result check();  }### Answer:
@Test public void testHealthyEngine() throws InterruptedException { final var orgID = UUID.randomUUID(); queue.createJob( orgID, TEST_PROVIDER_ID, Collections.singletonList("1"), Collections.singletonList(ResourceType.Patient), null, MockBlueButtonClient.BFD_TRANSACTION_TIME ); AggregationEngineHealthCheck healthCheck = new AggregationEngineHealthCheck(engine); Assert.assertTrue(healthCheck.check().isHealthy()); ExecutorService executor = Executors.newCachedThreadPool(); executor.execute(engine); executor.awaitTermination(2, TimeUnit.SECONDS); Assert.assertTrue(healthCheck.check().isHealthy()); }
@Test public void testHealthyEngineWhenJobBatchErrors() throws InterruptedException { Mockito.doThrow(new RuntimeException("Error")).when(bbclient).requestPatientFromServer(Mockito.anyString(), Mockito.any(DateRangeParam.class)); final var orgID = UUID.randomUUID(); queue.createJob( orgID, TEST_PROVIDER_ID, Collections.singletonList("1"), Collections.singletonList(ResourceType.Patient), null, MockBlueButtonClient.BFD_TRANSACTION_TIME ); AggregationEngineHealthCheck healthCheck = new AggregationEngineHealthCheck(engine); Assert.assertTrue(healthCheck.check().isHealthy()); ExecutorService executor = Executors.newCachedThreadPool(); executor.execute(engine); executor.awaitTermination(2, TimeUnit.SECONDS); Assert.assertTrue(healthCheck.check().isHealthy()); }
@Test public void testHealthyEngineWhenClaimBatchErrors() throws InterruptedException { final var orgID = UUID.randomUUID(); queue.createJob( orgID, TEST_PROVIDER_ID, Collections.singletonList("1"), Collections.singletonList(ResourceType.Patient), null, MockBlueButtonClient.BFD_TRANSACTION_TIME ); Mockito.doThrow(new RuntimeException("Error")).when(queue).claimBatch(Mockito.any(UUID.class)); AggregationEngineHealthCheck healthCheck = new AggregationEngineHealthCheck(engine); Assert.assertTrue(healthCheck.check().isHealthy()); ExecutorService executor = Executors.newCachedThreadPool(); executor.execute(engine); executor.awaitTermination(2, TimeUnit.SECONDS); Assert.assertTrue(healthCheck.check().isHealthy()); }
@Test public void testHealthyEngineWhenQueueOperationsError() throws InterruptedException { Mockito.doThrow(new RuntimeException("Error")).when(queue).completePartialBatch(Mockito.any(JobQueueBatch.class), Mockito.any(UUID.class)); final var orgID = UUID.randomUUID(); queue.createJob( orgID, TEST_PROVIDER_ID, Collections.singletonList("1"), Collections.singletonList(ResourceType.Patient), null, MockBlueButtonClient.BFD_TRANSACTION_TIME ); AggregationEngineHealthCheck healthCheck = new AggregationEngineHealthCheck(engine); Assert.assertTrue(healthCheck.check().isHealthy()); ExecutorService executor = Executors.newCachedThreadPool(); executor.execute(engine); executor.awaitTermination(2, TimeUnit.SECONDS); Assert.assertTrue(healthCheck.check().isHealthy()); }