Java 类org.springframework.boot.actuate.health.Status 实例源码

项目:extended-actuator-health-endpoints    文件:ExtendedHealthMvcEndpointUnitTest.java   
@Test
public void downWithExceptionHandling() throws Exception {

    HealthAggregator healthAggregator = mock(HealthAggregator.class);
    ApplicationAliveIndicator healthIndicator = mock(ApplicationAliveIndicator.class);
    when(healthIndicator.health()).thenThrow(new RuntimeException("fooException"));
    Map<String, ApplicationAliveIndicator> healthIndicators = new LinkedHashMap<>();
    healthIndicators.put("foo", healthIndicator);

    when(applicationContext.getBeansOfType(ApplicationAliveIndicator.class)).thenReturn(healthIndicators);


    extendedHealthEndpoint = new AliveHealthEndpoint("healthIndicatorfoo", healthAggregator);
    extendedHealthEndpoint.setApplicationContext(applicationContext);

    this.extendedHealthMvcEndpoint = new ExtendedHealthMvcEndpoint(this.extendedHealthEndpoint);

    ResponseEntity<Health> result = (ResponseEntity<Health>) this.extendedHealthMvcEndpoint.invoke(null);

    Map<String, Object> expectedHealthDetails = new LinkedHashMap<>();
    expectedHealthDetails.put("error", "java.lang.RuntimeException: fooException");
    assertThat(result.getBody().getDetails(), is(expectedHealthDetails));
    assertThat(result.getStatusCode(), is(HttpStatus.SERVICE_UNAVAILABLE));
    assertThat(result.getBody().getStatus(), is(Status.DOWN));
}
项目:keti    文件:AcsHealthAggregator.java   
private Status aggregateStatus(final List<Status> candidates) {
    // Only sort those status instances that we know about
    List<Status> filteredCandidates = new ArrayList<>();
    for (Status candidate : candidates) {
        if (this.statusOrder.contains(candidate.getCode())) {
            filteredCandidates.add(candidate);
        }
    }
    // If no status is given return UNKNOWN
    if (filteredCandidates.isEmpty()) {
        return Status.UNKNOWN;
    }
    // Sort given Status instances by configured order
    filteredCandidates.sort(new StatusComparator(this.statusOrder));
    return filteredCandidates.get(0);
}
项目:keti    文件:GraphDbHealthIndicatorTest.java   
@Test(dataProvider = "statuses")
public void testHealth(final GraphResourceRepository graphResourceRepository, final Status status,
        final AcsMonitoringUtilities.HealthCode healthCode, final boolean cassandraEnabled) throws Exception {
    GraphDbHealthIndicator graphDbHealthIndicator = new GraphDbHealthIndicator(graphResourceRepository);
    ReflectionTestUtils.setField(graphDbHealthIndicator, "cassandraEnabled", cassandraEnabled);
    Assert.assertEquals(status, graphDbHealthIndicator.health().getStatus());
    Assert.assertEquals(GraphDbHealthIndicator.DESCRIPTION,
            graphDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.DESCRIPTION_KEY));
    if (healthCode == AcsMonitoringUtilities.HealthCode.AVAILABLE) {
        Assert.assertFalse(
                graphDbHealthIndicator.health().getDetails().containsKey(AcsMonitoringUtilities.CODE_KEY));
    } else {
        Assert.assertEquals(healthCode,
                graphDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.CODE_KEY));
    }
}
项目:keti    文件:GraphDbHealthIndicatorTest.java   
@DataProvider
public Object[][] statuses() {
    return new Object[][] {
            new Object[] { mockGraphDbWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.IN_MEMORY, false },

            { mockGraphDbWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.AVAILABLE, true },

            { mockGraphDbWithExceptionWhileCheckingVersion(new QueryException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.INVALID_QUERY, true },

            { mockGraphDbWithExceptionWhileCheckingVersion(new ResourceUnavailableException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNAVAILABLE, true },

            { mockGraphDbWithExceptionWhileCheckingVersion(new TitanConfigurationException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.MISCONFIGURATION, true },

            { mockGraphDbWithExceptionWhileCheckingVersion(new IDPoolExhaustedException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.ERROR, true }, };

}
项目:keti    文件:AcsDbHealthIndicatorTest.java   
@Test(dataProvider = "statuses")
public void testHealth(final AcsMonitoringRepository acsMonitoringRepository, final Status status,
        final AcsMonitoringUtilities.HealthCode healthCode, final TitanMigrationManager titanMigrationManager)
        throws Exception {
    AcsDbHealthIndicator acsDbHealthIndicator = new AcsDbHealthIndicator(acsMonitoringRepository);
    acsDbHealthIndicator.setMigrationManager(titanMigrationManager);
    Assert.assertEquals(status, acsDbHealthIndicator.health().getStatus());
    Assert.assertEquals(AcsDbHealthIndicator.DESCRIPTION,
            acsDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.DESCRIPTION_KEY));
    if (healthCode == AcsMonitoringUtilities.HealthCode.AVAILABLE) {
        Assert.assertFalse(acsDbHealthIndicator.health().getDetails().containsKey(AcsMonitoringUtilities.CODE_KEY));
    } else {
        Assert.assertEquals(healthCode,
                acsDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.CODE_KEY));
    }
}
项目:springboot-graceful-shutdown    文件:GracefulShutdownHookTest.java   
@Test
public void testShutdown() throws Exception {
    // Prepare
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    GracefulShutdownHook testee = new GracefulShutdownHook(appContext);
    healthCheck.setReady(true);

    // Modify
    testee.run();

    // Test
    asyncSpringContextShutdownDelayedAssert();
    assertEquals(Status.DOWN, healthCheck.health().getStatus());
    verify(appContext, times(1)).close();
    stopWatch.stop();
    assertTrue(stopWatch.getTotalTimeSeconds() >= SHUTDOWN_WAIT_S);
}
项目:smarti    文件:RequiredProvidersHealthCheck.java   
private void appendProviderDetails(Health.Builder builder, String name, Processor processor) {
    final Health.Builder sub = new Health.Builder(Status.UP);
    if (processor != null) {
        sub
                .withDetail("key", processor.getKey())
                .withDetail("name", processor.getName())
                .withDetail("class", processor.getClass().getName())
                ;
    } else {
        sub.outOfService();
        if (requiredProvidersHealthCheckProperties.isFailOnMissing() &&
                requiredProvidersHealthCheckProperties.getFailIfMissing().getOrDefault(name, true)) {
            builder.down();
        }
    }
    builder.withDetail(name, sub.build());
}
项目:spring-cloud-stream-binder-redis    文件:RedisBinderModuleTests.java   
@Test
public void testParentConnectionFactoryInheritedByDefault() {
    context = SpringApplication.run(SimpleProcessor.class, "--server.port=0");
    BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
    Binder binder = binderFactory.getBinder(null);
    assertThat(binder, instanceOf(RedisMessageChannelBinder.class));
    DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
    RedisConnectionFactory binderConnectionFactory =
            (RedisConnectionFactory) binderFieldAccessor.getPropertyValue("connectionFactory");
    assertThat(binderConnectionFactory, instanceOf(RedisConnectionFactory.class));
    RedisConnectionFactory connectionFactory = context.getBean(RedisConnectionFactory.class);
    assertThat(binderConnectionFactory, is(connectionFactory));
    CompositeHealthIndicator bindersHealthIndicator =
            context.getBean("bindersHealthIndicator", CompositeHealthIndicator.class);
    assertNotNull(bindersHealthIndicator);
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    @SuppressWarnings("unchecked")
    Map<String,HealthIndicator> healthIndicators =
            (Map<String, HealthIndicator>) directFieldAccessor.getPropertyValue("indicators");
    assertThat(healthIndicators, hasKey("redis"));
    assertThat(healthIndicators.get("redis").health().getStatus(), equalTo(Status.UP));
}
项目:spring-cloud-stream-binder-redis    文件:RedisBinderModuleTests.java   
@Test
public void testParentConnectionFactoryInheritedIfOverridden() {
    context = new SpringApplication(SimpleProcessor.class, ConnectionFactoryConfiguration.class).run("--server.port=0");
    BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
    Binder binder = binderFactory.getBinder(null);
    assertThat(binder, instanceOf(RedisMessageChannelBinder.class));
    DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
    RedisConnectionFactory binderConnectionFactory =
            (RedisConnectionFactory) binderFieldAccessor.getPropertyValue("connectionFactory");
    assertThat(binderConnectionFactory, is(MOCK_CONNECTION_FACTORY));
    RedisConnectionFactory connectionFactory = context.getBean(RedisConnectionFactory.class);
    assertThat(binderConnectionFactory, is(connectionFactory));
    CompositeHealthIndicator bindersHealthIndicator =
            context.getBean("bindersHealthIndicator", CompositeHealthIndicator.class);
    assertNotNull(bindersHealthIndicator);
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    @SuppressWarnings("unchecked")
    Map<String,HealthIndicator> healthIndicators =
            (Map<String, HealthIndicator>) directFieldAccessor.getPropertyValue("indicators");
    assertThat(healthIndicators, hasKey("redis"));
    assertThat(healthIndicators.get("redis").health().getStatus(), equalTo(Status.UP));
}
项目:spring-cloud-stream-binder-kafka    文件:KafkaBinderHealthIndicatorTest.java   
@Test(timeout = 5000)
public void kafkaBinderDoesNotAnswer() {
    final List<PartitionInfo> partitions = partitions(new Node(-1, null, 0));
    topicsInUse.put(TEST_TOPIC, new KafkaMessageChannelBinder.TopicInformation("group", partitions));
    org.mockito.BDDMockito.given(consumer.partitionsFor(TEST_TOPIC)).willAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final int fiveMinutes = 1000 * 60 * 5;
            Thread.sleep(fiveMinutes);
            return partitions;
        }

    });
    this.indicator.setTimeout(1);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
}
项目:spring-rabbitmq-actuator    文件:RabbitQueueCheckHealthIndicatorTest.java   
@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"));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HealthMvcEndpointTests.java   
@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
    given(this.endpoint.getTimeToLive()).willReturn(50L);
    given(this.endpoint.isSensitive()).willReturn(false);
    given(this.endpoint.invoke())
            .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(null);
    assertThat(result instanceof Health).isTrue();
    assertThat(((Health) result).getStatus() == Status.UP).isTrue();
    Thread.sleep(100);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(null);
    @SuppressWarnings("unchecked")
    Health health = ((ResponseEntity<Health>) result).getBody();
    assertThat(health.getStatus() == Status.DOWN).isTrue();
}
项目:spring-cloud-stream-binder-rabbit    文件:RabbitBinderModuleTests.java   
@Test
public void testParentConnectionFactoryInheritedIfOverridden() {
    context = new SpringApplicationBuilder(SimpleProcessor.class, ConnectionFactoryConfiguration.class)
            .web(WebApplicationType.NONE)
            .run("--server.port=0");
    BinderFactory binderFactory = context.getBean(BinderFactory.class);
    Binder<?, ?, ?> binder = binderFactory.getBinder(null, MessageChannel.class);
    assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
    DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
    ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
            .getPropertyValue("connectionFactory");
    assertThat(binderConnectionFactory).isSameAs(MOCK_CONNECTION_FACTORY);
    ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
    assertThat(binderConnectionFactory).isSameAs(connectionFactory);
    CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
            CompositeHealthIndicator.class);
    assertThat(bindersHealthIndicator).isNotNull();
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    @SuppressWarnings("unchecked")
    Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
            .getPropertyValue("indicators");
    assertThat(healthIndicators).containsKey("rabbit");
    // mock connection factory behaves as if down
    assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo(Status.DOWN);
}
项目:spring-boot-concourse    文件:HealthMvcEndpointTests.java   
@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
    given(this.endpoint.getTimeToLive()).willReturn(50L);
    given(this.endpoint.isSensitive()).willReturn(false);
    given(this.endpoint.invoke())
            .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(null);
    assertThat(result instanceof Health).isTrue();
    assertThat(((Health) result).getStatus() == Status.UP).isTrue();
    Thread.sleep(100);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(null);
    @SuppressWarnings("unchecked")
    Health health = ((ResponseEntity<Health>) result).getBody();
    assertThat(health.getStatus() == Status.DOWN).isTrue();
}
项目:contestparser    文件:HealthMvcEndpointTests.java   
@Test
public void healthIsCached() {
    given(this.endpoint.getTimeToLive()).willReturn(10000L);
    given(this.endpoint.isSensitive()).willReturn(true);
    given(this.endpoint.invoke())
            .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(this.admin);
    assertTrue(result instanceof Health);
    Health health = (Health) result;
    assertTrue(health.getStatus() == Status.UP);
    assertThat(health.getDetails().size(), is(equalTo(1)));
    assertThat(health.getDetails().get("foo"), is(equalTo((Object) "bar")));
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(null); // insecure now
    assertTrue(result instanceof Health);
    health = (Health) result;
    // so the result is cached
    assertTrue(health.getStatus() == Status.UP);
    // but the details are hidden
    assertThat(health.getDetails().size(), is(equalTo(0)));
}
项目:contestparser    文件:HealthMvcEndpointTests.java   
@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
    given(this.endpoint.getTimeToLive()).willReturn(50L);
    given(this.endpoint.isSensitive()).willReturn(false);
    given(this.endpoint.invoke())
            .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(null);
    assertTrue(result instanceof Health);
    assertTrue(((Health) result).getStatus() == Status.UP);
    Thread.sleep(100);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(null);
    @SuppressWarnings("unchecked")
    Health health = ((ResponseEntity<Health>) result).getBody();
    assertTrue(health.getStatus() == Status.DOWN);
}
项目:resilience4j    文件:RateLimiterHealthIndicator.java   
@Override
public Health health() {
    RateLimiter.Metrics metrics = rateLimiter.getMetrics();
    int availablePermissions = metrics.getAvailablePermissions();
    int numberOfWaitingThreads = metrics.getNumberOfWaitingThreads();
    if (availablePermissions > 0 || numberOfWaitingThreads == 0) {
        return rateLimiterHealth(Status.UP, availablePermissions, numberOfWaitingThreads);
    }
    if (rateLimiter instanceof AtomicRateLimiter) {
        AtomicRateLimiter atomicRateLimiter = (AtomicRateLimiter) this.rateLimiter;
        AtomicRateLimiter.AtomicRateLimiterMetrics detailedMetrics = atomicRateLimiter.getDetailedMetrics();
        if (detailedMetrics.getNanosToWait() > timeoutInNanos) {
            return rateLimiterHealth(Status.DOWN, availablePermissions, numberOfWaitingThreads);
        }
    }
    return rateLimiterHealth(Status.UNKNOWN, availablePermissions, numberOfWaitingThreads);
}
项目:spring-cloud-stream    文件:HealthIndicatorsConfigurationTests.java   
@SuppressWarnings("rawtypes")
@Test
public void healthIndicatorsCheck() throws Exception {
    ConfigurableApplicationContext context = createBinderTestContext(new String[] { "binder1", "binder2" },
            "spring.cloud.stream.defaultBinder:binder2");
    Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1", MessageChannel.class);
    assertThat(binder1).isInstanceOf(StubBinder1.class);
    Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2", MessageChannel.class);
    assertThat(binder2).isInstanceOf(StubBinder2.class);
    CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
            CompositeHealthIndicator.class);
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    assertThat(bindersHealthIndicator).isNotNull();
    assertThat(context.getBean("testHealthIndicator1", CompositeHealthIndicator.class)).isNotNull();
    assertThat(context.getBean("testHealthIndicator2", CompositeHealthIndicator.class)).isNotNull();
    @SuppressWarnings("unchecked")
    Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
            .getPropertyValue("indicators");
    assertThat(healthIndicators).containsKey("binder1");
    assertThat(healthIndicators.get("binder1").health().getStatus()).isEqualTo(Status.UP);
    assertThat(healthIndicators).containsKey("binder2");
    assertThat(healthIndicators.get("binder2").health().getStatus()).isEqualTo(Status.UNKNOWN);
    context.close();
}
项目:zuul-route-health-spring-cloud-starter    文件:ZuulRouteHealthIndicatorTest.java   
@Test
public void shouldReportDownState() {

    // given
    final ZuulProperties.ZuulRoute route = new ZuulProperties.ZuulRoute("/zuul", "proxied-service");
    zuulProperties.getRoutes().put(route.getId(), route);

    // when
    final Health health = zuulRouteHealthIndicator.health();

    // then
    assertNotNull(health);
    assertEquals(Status.DOWN, health.getStatus());
    assertNull(health.getDetails().get("available"));
    assertFalse(((Collection) health.getDetails().get("unavailable")).isEmpty());
}
项目:zuul-route-health-spring-cloud-starter    文件:ZuulRouteHealthIndicatorTest.java   
@Test
public void shouldReportUpState() {

    // given
    final ZuulProperties.ZuulRoute route = new ZuulProperties.ZuulRoute("/zuul", "proxied-service");
    zuulProperties.getRoutes().put(route.getId(), route);

    final List<ServiceInstance> services = new ArrayList<>();
    services.add(mock(ServiceInstance.class));
    when(discoveryClient.getInstances("proxied-service")).thenReturn(services);

    // when
    final Health health = zuulRouteHealthIndicator.health();

    // then
    assertNotNull(health);
    assertEquals(Status.UP, health.getStatus());
    assertFalse(((Collection) health.getDetails().get("available")).isEmpty());
    assertNull(health.getDetails().get("unavailable"));
}
项目:spring-cloud-commons    文件:DiscoveryClientHealthIndicator.java   
@Override
public Health health() {
    Health.Builder builder = new Health.Builder();

    if (this.discoveryInitialized.get()) {
        try {
            List<String> services = this.discoveryClient.getServices();
            String description = (this.properties.isIncludeDescription()) ? this.discoveryClient.description() : "";
            builder.status(new Status("UP", description))
                    .withDetail("services", services);
        }
        catch (Exception e) {
            log.error("Error", e);
            builder.down(e);
        }
    }
    else {
        builder.status(new Status(Status.UNKNOWN.getCode(),
                "Discovery Client not initialized"));
    }
    return builder.build();
}
项目:spring-boot-readiness    文件:HealthClient.java   
private HealthResponseBuilder doGetHealth(URI uri) {
    try {
        log.debug("Checking health at '{}'", uri);
        // TODO let Jackson directly deserialize into HealthResponseBuilder
        return restTemplate.getForObject(uri, HealthResponse.class).toBuilder();
    } catch (RestClientException e) {
        Status status = new Status(DOWN.getCode(), getRootCause(e).getMessage());
        return HealthResponse.builder().status(status);
    }
}
项目:spring-boot-readiness    文件:StatusComparator.java   
@Override
public int compare(Status first, Status second) {
    int firstIndex = this.statusOrder.indexOf(first);
    int secondIndex = this.statusOrder.indexOf(second);
    return (firstIndex < secondIndex ? -1 :
            (firstIndex == secondIndex ? first.getCode().compareTo(second.getCode()) : 1));
}
项目:spring-boot-readiness    文件:ReadinessResponse.java   
@Override
public Status getStatus() {
    Map<String, Health> healths = children.stream()
            .collect(toMap(
                    HealthResponse::getService,
                    healthResponse -> new Health.Builder().status(healthResponse.getStatus()).build()
            ));

    return healthAggregator.aggregate(healths).getStatus();
}
项目:spring-boot-readiness    文件:MockRestTemplateAnswer.java   
@Override
public HealthResponse answer(InvocationOnMock invocation) {
    URI uri = invocation.getArgumentAt(0, URI.class);
    List<String> pathSegments = UriComponentsBuilder.fromUri(uri).build().getPathSegments();
    String status = Iterables.getLast(pathSegments);
    if ("EXCEPTION".equals(status)) {
        throw new RestClientException("simulated exception");
    }
    return HealthResponse.builder().status(new Status(status)).build();
}
项目:keti    文件:AcsMonitoringUtilities.java   
static Health health(final Status status, final HealthCode healthCode, final String description) {
    Health.Builder healthBuilder = Health.status(status);
    if (healthCode != HealthCode.AVAILABLE) {
        healthBuilder.withDetail(CODE_KEY, healthCode);
    }
    healthBuilder.withDetail(DESCRIPTION_KEY, description);
    return healthBuilder.build();
}
项目:keti    文件:AcsMonitoringUtilities.java   
static Health health(final Supplier<HealthCode> check, final String description) {
    try {
        HealthCode healthCode = check.get();
        if (healthCode == HealthCode.AVAILABLE) {
            return health(Status.UP, healthCode, description);
        }
        return health(Status.DOWN, healthCode, description);
    } catch (Exception e) {
        return health(Status.DOWN,
                AcsMonitoringUtilities.logError(HealthCode.ERROR, LOGGER, ERROR_MESSAGE_FORMAT, e), description);
    }
}
项目:keti    文件:AcsHealthAggregator.java   
void setStatusOrder(final Status... statusOrder) {
    String[] order = new String[statusOrder.length];
    for (int i = 0; i < statusOrder.length; ++i) {
        order[i] = statusOrder[i].getCode();
    }
    this.setStatusOrder(Arrays.asList(order));
}
项目:keti    文件:AcsHealthAggregator.java   
@Override
public int compare(final Status s1, final Status s2) {
    int i1 = this.statusOrder.indexOf(s1.getCode());
    int i2 = this.statusOrder.indexOf(s2.getCode());
    if (i1 < i2) {
        return -1;
    } else if (i1 == i2) {
        return s1.getCode().compareTo(s2.getCode());
    } else {
        return 1;
    }
}
项目:keti    文件:AbstractCacheHealthIndicator.java   
@Override
public Health health() {
    if (!this.healthCheckEnabled) {
        return AcsMonitoringUtilities
                .health(Status.UNKNOWN, AcsMonitoringUtilities.HealthCode.HEALTH_CHECK_DISABLED, DESCRIPTION);
    }
    if (!this.cachingEnabled) {
        return AcsMonitoringUtilities
                .health(Status.UNKNOWN, AcsMonitoringUtilities.HealthCode.DISABLED, DESCRIPTION);
    }
    return cacheHealth(redisConnectionFactory, this.cacheType, DESCRIPTION, this::getRedisConnection);
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@Test
public void defaultOrder() {
    Map<String, Health> healths = new HashMap<>();
    healths.put("h1", new Health.Builder().status(Status.DOWN).build());
    healths.put("h2", new Health.Builder().status(Status.UP).build());
    healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
    healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
    Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.DOWN);
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@Test
public void customOrder() {
    this.healthAggregator.setStatusOrder(Status.UNKNOWN, Status.UP, Status.OUT_OF_SERVICE, Status.DOWN);
    Map<String, Health> healths = new HashMap<>();
    healths.put("h1", new Health.Builder().status(Status.DOWN).build());
    healths.put("h2", new Health.Builder().status(Status.UP).build());
    healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
    healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
    Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.UNKNOWN);
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@Test
public void defaultOrderWithCustomStatus() {
    Map<String, Health> healths = new HashMap<>();
    healths.put("h1", new Health.Builder().status(Status.DOWN).build());
    healths.put("h2", new Health.Builder().status(Status.UP).build());
    healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
    healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
    healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build());
    Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.DOWN);
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@Test(dataProvider = "statuses")
public void defaultOrderWithDegradedStatus(final Status expectedStatus, final List<Status> actualStatuses) {
    Map<String, Health> healths = new HashMap<>();
    healths.put("h1", new Health.Builder().status(actualStatuses.get(0)).build());
    healths.put("h2", new Health.Builder().status(actualStatuses.get(1)).build());
    healths.put("h3", new Health.Builder().status(actualStatuses.get(2)).build());
    Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), expectedStatus);
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@DataProvider
public Object[][] statuses() {
    return new Object[][] { new Object[] { AcsHealthAggregator.DEGRADED_STATUS,
            Arrays.asList(Status.UP, AcsHealthAggregator.DEGRADED_STATUS, Status.UP) },

            { Status.UP, Arrays.asList(Status.UP, Status.UNKNOWN, Status.UP) },

            { Status.DOWN, Arrays.asList(Status.UP, AcsHealthAggregator.DEGRADED_STATUS, Status.DOWN) }, };
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@Test
public void customOrderWithCustomStatus() {
    this.healthAggregator.setStatusOrder(Arrays.asList("DOWN", "OUT_OF_SERVICE", "UP", "UNKNOWN", "CUSTOM"));
    Map<String, Health> healths = new HashMap<>();
    healths.put("h1", new Health.Builder().status(Status.DOWN).build());
    healths.put("h2", new Health.Builder().status(Status.UP).build());
    healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
    healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
    healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build());
    Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.DOWN);
}
项目:keti    文件:AcsHealthAggregatorTest.java   
@DataProvider
public Object[][] singleStatuses() {
    return new Object[][] {
            new Object[] { "h1", new Health.Builder().status(new Status("CUSTOM")).build(), Status.UNKNOWN },

            { "cache", new Health.Builder().status(Status.DOWN).build(), AcsHealthAggregator.DEGRADED_STATUS },

            { "cache", new Health.Builder().status(Status.UNKNOWN).build(), Status.UP }, };
}
项目:keti    文件:AcsDbHealthIndicatorTest.java   
@DataProvider
public Object[][] statuses() {
    TitanMigrationManager happyMigrationManager = new TitanMigrationManager();
    TitanMigrationManager sadMigrationManager = new TitanMigrationManager();
    Whitebox.setInternalState(happyMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, true);
    Whitebox.setInternalState(sadMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, false);

    return new Object[][] { new Object[] { mockDbWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.AVAILABLE,
            happyMigrationManager },

            { mockDbWithException(new TransientDataAccessResourceException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager },

            { mockDbWithException(new QueryTimeoutException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager },

            { mockDbWithException(new DataSourceLookupFailureException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNREACHABLE, happyMigrationManager },

            { mockDbWithException(new PermissionDeniedDataAccessException("", null)), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.MISCONFIGURATION, happyMigrationManager },

            { mockDbWithException(new ConcurrencyFailureException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.ERROR, happyMigrationManager },

            { mockDbWithUp(), Status.DOWN, AcsMonitoringUtilities.HealthCode.MIGRATION_INCOMPLETE,
                    sadMigrationManager }, };
}
项目:keti    文件:UaaHealthIndicatorTest.java   
@Test(dataProvider = "statuses")
public void testHealth(final RestTemplate restTemplate, final Status status,
        final AcsMonitoringUtilities.HealthCode healthCode) throws Exception {
    UaaHealthIndicator uaaHealthIndicator = new UaaHealthIndicator(restTemplate);
    Assert.assertEquals(status, uaaHealthIndicator.health().getStatus());
    Assert.assertEquals(uaaHealthIndicator.getDescription(),
            uaaHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.DESCRIPTION_KEY));
    if (healthCode == AcsMonitoringUtilities.HealthCode.AVAILABLE) {
        Assert.assertFalse(uaaHealthIndicator.health().getDetails().containsKey(AcsMonitoringUtilities.CODE_KEY));
    } else {
        Assert.assertEquals(healthCode,
                uaaHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.CODE_KEY));
    }
}
项目:keti    文件:UaaHealthIndicatorTest.java   
@DataProvider
public Object[][] statuses() {
    return new Object[][] {
            new Object[] { mockRestWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.AVAILABLE },

            { mockRestWithException(new RestClientException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNREACHABLE },

            { mockRestWithException(new RuntimeException()), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.ERROR }, };
}