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();
}
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;
}
Aggregations