Search in sources :

Example 6 with HealthIndicator

use of org.springframework.boot.actuate.health.HealthIndicator in project spring-cloud-stream by spring-cloud.

the class HealthIndicatorsConfigurationTests method healthIndicatorsCheck.

@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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) CompositeHealthIndicator(org.springframework.boot.actuate.health.CompositeHealthIndicator) CompositeHealthIndicator(org.springframework.boot.actuate.health.CompositeHealthIndicator) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Map(java.util.Map) Test(org.junit.Test)

Example 7 with HealthIndicator

use of org.springframework.boot.actuate.health.HealthIndicator in project sofa-boot by alipay.

the class HealthCheckManager method getHealthIndicator.

public static List<HealthIndicator> getHealthIndicator() {
    List<HealthIndicator> healthIndicators = new ArrayList<HealthIndicator>();
    Map<String, HealthIndicator> stringToHealthIndicator = applicationContext.getBeansOfType(HealthIndicator.class);
    if (!CollectionUtils.isEmpty(stringToHealthIndicator)) {
        for (HealthIndicator healthIndicator : stringToHealthIndicator.values()) {
            if (!(healthIndicator instanceof SofaBootComponentHealthCheckInfo) && !(healthIndicator instanceof SpringContextHealthCheckInfo)) {
                // 排除掉SofaBootComponentHealthCheckInfo 和 SpringContextHealthCheckInfo
                healthIndicators.add(healthIndicator);
            }
        }
    }
    return healthIndicators;
}
Also used : HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) SpringContextHealthCheckInfo(com.alipay.sofa.healthcheck.service.SpringContextHealthCheckInfo) ArrayList(java.util.ArrayList) SofaBootComponentHealthCheckInfo(com.alipay.sofa.healthcheck.service.SofaBootComponentHealthCheckInfo)

Aggregations

HealthIndicator (org.springframework.boot.actuate.health.HealthIndicator)7 Test (org.junit.Test)3 CompositeHealthIndicator (org.springframework.boot.actuate.health.CompositeHealthIndicator)3 ApplicationHealthIndicator (org.springframework.boot.actuate.health.ApplicationHealthIndicator)2 CassandraHealthIndicator (org.springframework.boot.actuate.health.CassandraHealthIndicator)2 CouchbaseHealthIndicator (org.springframework.boot.actuate.health.CouchbaseHealthIndicator)2 DataSourceHealthIndicator (org.springframework.boot.actuate.health.DataSourceHealthIndicator)2 DiskSpaceHealthIndicator (org.springframework.boot.actuate.health.DiskSpaceHealthIndicator)2 ElasticsearchHealthIndicator (org.springframework.boot.actuate.health.ElasticsearchHealthIndicator)2 ElasticsearchJestHealthIndicator (org.springframework.boot.actuate.health.ElasticsearchJestHealthIndicator)2 JmsHealthIndicator (org.springframework.boot.actuate.health.JmsHealthIndicator)2 LdapHealthIndicator (org.springframework.boot.actuate.health.LdapHealthIndicator)2 MailHealthIndicator (org.springframework.boot.actuate.health.MailHealthIndicator)2 MongoHealthIndicator (org.springframework.boot.actuate.health.MongoHealthIndicator)2 RabbitHealthIndicator (org.springframework.boot.actuate.health.RabbitHealthIndicator)2 RedisHealthIndicator (org.springframework.boot.actuate.health.RedisHealthIndicator)2 SolrHealthIndicator (org.springframework.boot.actuate.health.SolrHealthIndicator)2 HealthChecker (com.alipay.sofa.healthcheck.core.HealthChecker)1 SofaBootComponentHealthCheckInfo (com.alipay.sofa.healthcheck.service.SofaBootComponentHealthCheckInfo)1 SpringContextHealthCheckInfo (com.alipay.sofa.healthcheck.service.SpringContextHealthCheckInfo)1