mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #26145 from izeye
* pr/26145: Update copyright year of changed file Polish Closes gh-26145
This commit is contained in:
commit
661ff34dcd
@ -71,13 +71,13 @@ public class DataSourceHealthContributorAutoConfiguration implements Initializin
|
||||
|
||||
private DataSourcePoolMetadataProvider poolMetadataProvider;
|
||||
|
||||
public DataSourceHealthContributorAutoConfiguration(Map<String, DataSource> dataSources,
|
||||
public DataSourceHealthContributorAutoConfiguration(
|
||||
ObjectProvider<DataSourcePoolMetadataProvider> metadataProviders) {
|
||||
this.metadataProviders = metadataProviders.orderedStream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider(this.metadataProviders);
|
||||
}
|
||||
|
||||
@ -97,15 +97,15 @@ public class DataSourceHealthContributorAutoConfiguration implements Initializin
|
||||
private HealthContributor createContributor(Map<String, DataSource> beans) {
|
||||
Assert.notEmpty(beans, "Beans must not be empty");
|
||||
if (beans.size() == 1) {
|
||||
return createIndicator(beans.values().iterator().next());
|
||||
return createContributor(beans.values().iterator().next());
|
||||
}
|
||||
return CompositeHealthContributor.fromMap(beans, this::createIndicator);
|
||||
return CompositeHealthContributor.fromMap(beans, this::createContributor);
|
||||
}
|
||||
|
||||
private HealthContributor createIndicator(DataSource source) {
|
||||
private HealthContributor createContributor(DataSource source) {
|
||||
if (source instanceof AbstractRoutingDataSource) {
|
||||
AbstractRoutingDataSource routingDataSource = (AbstractRoutingDataSource) source;
|
||||
return new RoutingDataSourceHealthIndicator(routingDataSource, this::createIndicator);
|
||||
return new RoutingDataSourceHealthContributor(routingDataSource, this::createContributor);
|
||||
}
|
||||
return new DataSourceHealthIndicator(source, getValidationQuery(source));
|
||||
}
|
||||
@ -120,15 +120,15 @@ public class DataSourceHealthContributorAutoConfiguration implements Initializin
|
||||
* where the overall health is composed of a {@link DataSourceHealthIndicator} for
|
||||
* each routed datasource.
|
||||
*/
|
||||
static class RoutingDataSourceHealthIndicator implements CompositeHealthContributor {
|
||||
static class RoutingDataSourceHealthContributor implements CompositeHealthContributor {
|
||||
|
||||
private CompositeHealthContributor delegate;
|
||||
private final CompositeHealthContributor delegate;
|
||||
|
||||
RoutingDataSourceHealthIndicator(AbstractRoutingDataSource routingDataSource,
|
||||
Function<DataSource, HealthContributor> indicatorFunction) {
|
||||
RoutingDataSourceHealthContributor(AbstractRoutingDataSource routingDataSource,
|
||||
Function<DataSource, HealthContributor> contributorFunction) {
|
||||
Map<String, DataSource> routedDataSources = routingDataSource.getResolvedDataSources().entrySet().stream()
|
||||
.collect(Collectors.toMap((e) -> e.getKey().toString(), Map.Entry::getValue));
|
||||
this.delegate = CompositeHealthContributor.fromMap(routedDataSources, indicatorFunction);
|
||||
this.delegate = CompositeHealthContributor.fromMap(routedDataSources, contributorFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ import javax.sql.DataSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration.RoutingDataSourceHealthIndicator;
|
||||
import org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration.RoutingDataSourceHealthContributor;
|
||||
import org.springframework.boot.actuate.health.CompositeHealthContributor;
|
||||
import org.springframework.boot.actuate.health.NamedContributor;
|
||||
import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
|
||||
@ -82,7 +82,7 @@ class DataSourceHealthContributorAutoConfigurationTests {
|
||||
CompositeHealthContributor composite = context.getBean(CompositeHealthContributor.class);
|
||||
assertThat(composite.getContributor("dataSource")).isInstanceOf(DataSourceHealthIndicator.class);
|
||||
assertThat(composite.getContributor("routingDataSource"))
|
||||
.isInstanceOf(RoutingDataSourceHealthIndicator.class);
|
||||
.isInstanceOf(RoutingDataSourceHealthContributor.class);
|
||||
});
|
||||
}
|
||||
|
||||
@ -92,16 +92,16 @@ class DataSourceHealthContributorAutoConfigurationTests {
|
||||
.withPropertyValues("management.health.db.ignore-routing-datasources:true").run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(CompositeHealthContributor.class);
|
||||
assertThat(context).hasSingleBean(DataSourceHealthIndicator.class);
|
||||
assertThat(context).doesNotHaveBean(RoutingDataSourceHealthIndicator.class);
|
||||
assertThat(context).doesNotHaveBean(RoutingDataSourceHealthContributor.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWithOnlyRoutingDataSourceShouldIncludeRoutingDataSourceWithComposedIndicators() {
|
||||
this.contextRunner.withUserConfiguration(RoutingDataSourceConfig.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(RoutingDataSourceHealthIndicator.class);
|
||||
RoutingDataSourceHealthIndicator routingHealthContributor = context
|
||||
.getBean(RoutingDataSourceHealthIndicator.class);
|
||||
assertThat(context).hasSingleBean(RoutingDataSourceHealthContributor.class);
|
||||
RoutingDataSourceHealthContributor routingHealthContributor = context
|
||||
.getBean(RoutingDataSourceHealthContributor.class);
|
||||
assertThat(routingHealthContributor.getContributor("one")).isInstanceOf(DataSourceHealthIndicator.class);
|
||||
assertThat(routingHealthContributor.getContributor("two")).isInstanceOf(DataSourceHealthIndicator.class);
|
||||
assertThat(routingHealthContributor.iterator()).toIterable().extracting("name")
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -128,7 +128,7 @@ final class ApplicationPluginAction implements PluginApplicationAction {
|
||||
private String loadResource(String name) {
|
||||
try (InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream(name))) {
|
||||
char[] buffer = new char[4096];
|
||||
int read = 0;
|
||||
int read;
|
||||
StringWriter writer = new StringWriter();
|
||||
while ((read = reader.read(buffer)) > 0) {
|
||||
writer.write(buffer, 0, read);
|
||||
|
Loading…
Reference in New Issue
Block a user