本文整理汇总了Java中org.springframework.boot.actuate.health.HealthIndicator类的典型用法代码示例。如果您正苦于以下问题:Java HealthIndicator类的具体用法?Java HealthIndicator怎么用?Java HealthIndicator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HealthIndicator类属于org.springframework.boot.actuate.health包,在下文中一共展示了HealthIndicator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParentConnectionFactoryInheritedByDefault
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@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));
}
示例2: testParentConnectionFactoryInheritedIfOverridden
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@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));
}
示例3: dataSourceHealthIndicatorWithCustomValidationQuery
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void dataSourceHealthIndicatorWithCustomValidationQuery() {
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ManagementServerProperties.class, DataSourceProperties.class,
DataSourceConfig.class,
DataSourcePoolMetadataProvidersConfiguration.class,
HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.test.validation-query:SELECT from FOOBAR",
"management.health.diskspace.enabled:false");
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
HealthIndicator healthIndicator = beans.values().iterator().next();
assertThat(healthIndicator.getClass()).isEqualTo(DataSourceHealthIndicator.class);
DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator) healthIndicator;
assertThat(dataSourceHealthIndicator.getQuery()).isEqualTo("SELECT from FOOBAR");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:HealthIndicatorAutoConfigurationTests.java
示例4: mailHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void mailHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mail.host:smtp.acme.org",
"management.health.diskspace.enabled:false");
this.context.register(MailSenderAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
assertThat(beans.values().iterator().next().getClass())
.isEqualTo(MailHealthIndicator.class);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:HealthIndicatorAutoConfigurationTests.java
示例5: elasticsearchHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void elasticsearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.path.home:target",
"management.health.diskspace.enabled:false");
this.context.register(JestClientConfiguration.class,
JestAutoConfiguration.class, ElasticsearchAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
assertThat(beans.values().iterator().next().getClass())
.isEqualTo(ElasticsearchHealthIndicator.class);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:HealthIndicatorAutoConfigurationTests.java
示例6: notElasticsearchHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void notElasticsearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.elasticsearch.enabled:false",
"spring.data.elasticsearch.properties.path.home:target",
"management.health.diskspace.enabled:false");
this.context.register(JestClientConfiguration.class,
JestAutoConfiguration.class, ElasticsearchAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
assertThat(beans.values().iterator().next().getClass())
.isEqualTo(ApplicationHealthIndicator.class);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:HealthIndicatorAutoConfigurationTests.java
示例7: testParentConnectionFactoryInheritedIfOverridden
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@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);
}
示例8: taskHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Bean
public HealthIndicator taskHealthIndicator() {
return new AbstractHealthIndicator() {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
if (correctNumberOfInstances()) {
builder.up();
} else {
builder.down();
}
builder.withDetail("mesos.resources.count", instanceCount.getCount());
builder.withDetail("instances", stateRepository.allTaskInfos().size());
for (Protos.TaskState taskState : Protos.TaskState.values()) {
Map<String, Protos.TaskStatus> state = getTasksForState(taskState);
builder.withDetail(taskState.name(), state.size());
}
}
};
}
示例9: configure
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Override
public void configure(CommandLine cli) {
CommandLine healthCli = new CommandLine(new HelpAwareContainerPicocliCommand() {});
for (Map.Entry<String, HealthIndicator> entry : healthIndicators.entrySet()) {
Matcher matcher = HEALTH_PATTERN.matcher(entry.getKey());
if (matcher.matches()) {
String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, matcher.group(1));
healthCli.addSubcommand(name, new PrintCommand(entry.getValue().health()));
} else {
logger.warn("Unable to determine a correct name for given indicator: \"{}\", skip it!",
entry.getKey());
}
}
cli.addSubcommand("health", healthCli);
}
开发者ID:kakawait,项目名称:picocli-spring-boot-starter,代码行数:16,代码来源:PicocliSpringBootSampleApplication.java
示例10: jmsHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void jmsHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
this.context.register(ActiveMQAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
assertThat(beans.values().iterator().next().getClass())
.isEqualTo(JmsHealthIndicator.class);
}
示例11: createHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
protected HealthIndicator createHealthIndicator(Map<String, S> beans) {
if (beans.size() == 1) {
return createHealthIndicator(beans.values().iterator().next());
}
CompositeHealthIndicator composite = new CompositeHealthIndicator(
this.healthAggregator);
for (Map.Entry<String, S> entry : beans.entrySet()) {
composite.addHealthIndicator(entry.getKey(),
createHealthIndicator(entry.getValue()));
}
return composite;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:CompositeHealthIndicatorConfiguration.java
示例12: notJmsHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void notJmsHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.jms.enabled:false",
"management.health.diskspace.enabled:false");
this.context.register(ActiveMQAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
assertThat(beans.values().iterator().next().getClass())
.isEqualTo(ApplicationHealthIndicator.class);
}
示例13: notMailHealthIndicator
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Test
public void notMailHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mail.host:smtp.acme.org", "management.health.mail.enabled:false",
"management.health.diskspace.enabled:false");
this.context.register(MailSenderAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
assertThat(beans.values().iterator().next().getClass())
.isEqualTo(ApplicationHealthIndicator.class);
}
示例14: healthEndpoint
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public HealthEndpoint healthEndpoint() {
return new HealthEndpoint(
this.healthAggregator == null ? new OrderedHealthAggregator()
: this.healthAggregator,
this.healthIndicators == null
? Collections.<String, HealthIndicator>emptyMap()
: this.healthIndicators);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:EndpointAutoConfiguration.java
示例15: HealthEndpoint
import org.springframework.boot.actuate.health.HealthIndicator; //导入依赖的package包/类
/**
* Create a new {@link HealthIndicator} instance.
* @param healthAggregator the health aggregator
* @param healthIndicators the health indicators
*/
public HealthEndpoint(HealthAggregator healthAggregator,
Map<String, HealthIndicator> healthIndicators) {
super("health", false);
Assert.notNull(healthAggregator, "HealthAggregator must not be null");
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(
healthAggregator);
for (Map.Entry<String, HealthIndicator> entry : healthIndicators.entrySet()) {
healthIndicator.addHealthIndicator(getKey(entry.getKey()), entry.getValue());
}
this.healthIndicator = healthIndicator;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:HealthEndpoint.java