Search in sources :

Example 1 with CompositeHealthContributor

use of org.springframework.boot.actuate.health.CompositeHealthContributor in project spring-boot by spring-projects.

the class DataSourceHealthContributorAutoConfigurationTests method runWithRoutingAndEmbeddedDataSourceShouldIncludeRoutingDataSource.

@Test
void runWithRoutingAndEmbeddedDataSourceShouldIncludeRoutingDataSource() {
    this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, RoutingDataSourceConfig.class).run((context) -> {
        CompositeHealthContributor composite = context.getBean(CompositeHealthContributor.class);
        assertThat(composite.getContributor("dataSource")).isInstanceOf(DataSourceHealthIndicator.class);
        assertThat(composite.getContributor("routingDataSource")).isInstanceOf(RoutingDataSourceHealthContributor.class);
    });
}
Also used : CompositeHealthContributor(org.springframework.boot.actuate.health.CompositeHealthContributor) EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with CompositeHealthContributor

use of org.springframework.boot.actuate.health.CompositeHealthContributor in project spring-cloud-gcp by spring-cloud.

the class PubSubHealthIndicatorAutoConfigurationTests method compositeHealthIndicatorPresentMultiplePubSubTemplate.

@Test
public void compositeHealthIndicatorPresentMultiplePubSubTemplate() {
    PubSubTemplate mockPubSubTemplate1 = mock(PubSubTemplate.class);
    PubSubTemplate mockPubSubTemplate2 = mock(PubSubTemplate.class);
    this.baseContextRunner.withBean("pubSubTemplate1", PubSubTemplate.class, () -> mockPubSubTemplate1).withBean("pubSubTemplate2", PubSubTemplate.class, () -> mockPubSubTemplate2).withPropertyValues("management.health.pubsub.enabled=true").run(ctx -> {
        assertThatThrownBy(() -> ctx.getBean(PubSubHealthIndicator.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
        CompositeHealthContributor healthContributor = ctx.getBean("pubSubHealthContributor", CompositeHealthContributor.class);
        assertThat(healthContributor).isNotNull();
        assertThat(healthContributor.stream()).hasSize(2);
        healthContributor.stream().forEach(System.out::println);
        assertThat(healthContributor.stream().map(c -> ((NamedContributor) c).getName())).containsExactlyInAnyOrder("pubSubTemplate1", "pubSubTemplate2");
    });
}
Also used : CompositeHealthContributor(org.springframework.boot.actuate.health.CompositeHealthContributor) PubSubTemplate(org.springframework.cloud.gcp.pubsub.core.PubSubTemplate) Test(org.junit.Test)

Example 3 with CompositeHealthContributor

use of org.springframework.boot.actuate.health.CompositeHealthContributor in project spring-boot by spring-projects.

the class DataSourceHealthContributorAutoConfigurationTests method runWhenMultipleDataSourceBeansShouldCreateCompositeIndicator.

@Test
void runWhenMultipleDataSourceBeansShouldCreateCompositeIndicator() {
    this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, DataSourceConfig.class).run((context) -> {
        assertThat(context).hasSingleBean(CompositeHealthContributor.class);
        CompositeHealthContributor contributor = context.getBean(CompositeHealthContributor.class);
        String[] names = contributor.stream().map(NamedContributor::getName).toArray(String[]::new);
        assertThat(names).containsExactlyInAnyOrder("dataSource", "testDataSource");
    });
}
Also used : CompositeHealthContributor(org.springframework.boot.actuate.health.CompositeHealthContributor) EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeHealthContributor (org.springframework.boot.actuate.health.CompositeHealthContributor)3 Test (org.junit.jupiter.api.Test)2 EmbeddedDataSourceConfiguration (org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration)2 Test (org.junit.Test)1 PubSubTemplate (org.springframework.cloud.gcp.pubsub.core.PubSubTemplate)1