@SuppressWarnings({"unchecked", "boxing"})
  @Test
  public void testDoHealthCheckSingleQueueCheckConsumerDown() throws Exception {
    Queue queue = generateQueue("test");
    healthIndicator.addQueueCheck(queue, 10000, 2);

    RabbitQueueProperties properties = new RabbitQueueProperties();
    properties.setConsumerCount(1);
    properties.setMessageCount(5883);
    propertiesManager.request(queue);
    PowerMock.expectLastCall().andReturn(properties);

    PowerMock.replayAll();
    Builder builder = new Builder(Status.OUT_OF_SERVICE);
    healthIndicator.doHealthCheck(builder);
    PowerMock.verifyAll();

    Health health = builder.build();
    Assert.assertEquals(Status.DOWN, health.getStatus());
    Assert.assertNotNull(health.getDetails().get("test"));
    Map<String, Object> details = (Map<String, Object>) health.getDetails().get("test");
    Assert.assertEquals(Status.DOWN.getCode(), details.get("status"));
    Assert.assertEquals(5883, details.get("currentMessageCount"));
    Assert.assertEquals(10000, details.get("maxMessageCount"));
    Assert.assertEquals(1, details.get("currentConsumerCount"));
    Assert.assertEquals(2, details.get("minConsumerCount"));
  }
 @Override
 public Health health() {
   try {
     getSongDb();
     return Health.up().build();
   } catch (Exception e) {
     return Health.down(e).build();
   }
 }
 @Override
 protected Health getHealth(BasicGitConfiguration config) {
   try {
     GitRepositoryClient client = repositoryClientFactory.getClient(config.getGitRepository());
     client.sync(logger::debug);
     return Health.up().build();
   } catch (Exception ex) {
     return Health.down(ex).build();
   }
 }
 @Override
 protected Health getHealth(GitLabConfiguration config) {
   try {
     // Gets the client
     OntrackGitLabClient client = gitLabClientFactory.create(config);
     // Gets the list of repositories
     client.getRepositories();
     // OK
     return Health.up().build();
   } catch (Exception ex) {
     return Health.down(ex).build();
   }
 }
 @RequestMapping
 @ResponseBody
 public Object invoke(Principal principal) {
   if (!this.delegate.isEnabled()) {
     // Shouldn't happen because the request mapping should not be registered
     return new ResponseEntity<Map<String, String>>(
         Collections.singletonMap("message", "This endpoint is disabled"), HttpStatus.NOT_FOUND);
   }
   Health health = getHealth(principal);
   HttpStatus status = this.statusMapping.get(health.getStatus().getCode());
   if (status != null) {
     return new ResponseEntity<Health>(health, status);
   }
   return health;
 }
  @Test
  public void testDoHealthCheckSingleQueueCheckMetricException() throws Exception {
    Queue queue = generateQueue("test");
    healthIndicator.addQueueCheck(queue, 10000, 2);

    propertiesManager.request(queue);
    PowerMock.expectLastCall().andThrow(new RuntimeException());

    PowerMock.replayAll();
    Builder builder = new Builder(Status.OUT_OF_SERVICE);
    healthIndicator.doHealthCheck(builder);
    PowerMock.verifyAll();

    Health health = builder.build();
    Assert.assertEquals(Status.DOWN, health.getStatus());
    Assert.assertNull(health.getDetails().get("test"));
  }
 private Health getHealth(Principal principal) {
   long accessTime = System.currentTimeMillis();
   if (isCacheStale(accessTime)) {
     this.lastAccess = accessTime;
     this.cached = this.delegate.invoke();
   }
   if (exposeHealthDetails(principal)) {
     return this.cached;
   }
   return Health.status(this.cached.getStatus()).build();
 }
 @Bean
 HealthIndicator healthIndicator() {
   return () -> Health.status("I <3 RWX & Ft. Lauderdale").build();
 }