mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Rename CompositeDataSourcePoolMetadataProvider
Rename CompositeDataSourcePoolMetadataProvider to DataSourcePoolMetadataProviders.
This commit is contained in:
parent
a512bcf766
commit
4c8d35db43
@ -45,9 +45,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration;
|
||||
@ -109,19 +109,19 @@ public class HealthIndicatorAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "dbHealthIndicator")
|
||||
public HealthIndicator dbHealthIndicator() {
|
||||
DataSourcePoolMetadataProvider metadataProvider = new CompositeDataSourcePoolMetadataProvider(
|
||||
DataSourcePoolMetadataProvider metadataProvider = new DataSourcePoolMetadataProviders(
|
||||
this.metadataProviders);
|
||||
if (this.dataSources.size() == 1) {
|
||||
return createDataSourceHealthIndicator(metadataProvider, this.dataSources
|
||||
.values().iterator().next());
|
||||
DataSource dataSource = this.dataSources.values().iterator().next();
|
||||
return createDataSourceHealthIndicator(metadataProvider, dataSource);
|
||||
}
|
||||
CompositeHealthIndicator composite = new CompositeHealthIndicator(
|
||||
this.healthAggregator);
|
||||
for (Map.Entry<String, DataSource> entry : this.dataSources.entrySet()) {
|
||||
composite.addHealthIndicator(
|
||||
entry.getKey(),
|
||||
createDataSourceHealthIndicator(metadataProvider,
|
||||
entry.getValue()));
|
||||
String name = entry.getKey();
|
||||
DataSource dataSource = entry.getValue();
|
||||
composite.addHealthIndicator(name,
|
||||
createDataSourceHealthIndicator(metadataProvider, dataSource));
|
||||
}
|
||||
return composite;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@ -55,7 +55,7 @@ public class DataSourcePublicMetrics implements PublicMetrics {
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
DataSource primaryDataSource = getPrimaryDataSource();
|
||||
DataSourcePoolMetadataProvider provider = new CompositeDataSourcePoolMetadataProvider(
|
||||
DataSourcePoolMetadataProvider provider = new DataSourcePoolMetadataProviders(
|
||||
this.providers);
|
||||
for (Map.Entry<String, DataSource> entry : this.applicationContext
|
||||
.getBeansOfType(DataSource.class).entrySet()) {
|
||||
|
@ -29,22 +29,15 @@ import javax.sql.DataSource;
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public class CompositeDataSourcePoolMetadataProvider implements DataSourcePoolMetadataProvider {
|
||||
public class DataSourcePoolMetadataProviders implements DataSourcePoolMetadataProvider {
|
||||
|
||||
private final List<DataSourcePoolMetadataProvider> providers;
|
||||
|
||||
/**
|
||||
* Create a {@link CompositeDataSourcePoolMetadataProvider} instance with no delegate.
|
||||
*/
|
||||
public CompositeDataSourcePoolMetadataProvider() {
|
||||
this(new ArrayList<DataSourcePoolMetadataProvider>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link CompositeDataSourcePoolMetadataProvider} instance with an initial
|
||||
* Create a {@link DataSourcePoolMetadataProviders} instance with an initial
|
||||
* collection of delegates to use.
|
||||
*/
|
||||
public CompositeDataSourcePoolMetadataProvider(
|
||||
public DataSourcePoolMetadataProviders(
|
||||
Collection<? extends DataSourcePoolMetadataProvider> providers) {
|
||||
this.providers = new ArrayList<DataSourcePoolMetadataProvider>(providers);
|
||||
}
|
||||
@ -52,7 +45,8 @@ public class CompositeDataSourcePoolMetadataProvider implements DataSourcePoolMe
|
||||
@Override
|
||||
public DataSourcePoolMetadata getDataSourcePoolMetadata(DataSource dataSource) {
|
||||
for (DataSourcePoolMetadataProvider provider : this.providers) {
|
||||
DataSourcePoolMetadata metadata = provider.getDataSourcePoolMetadata(dataSource);
|
||||
DataSourcePoolMetadata metadata = provider
|
||||
.getDataSourcePoolMetadata(dataSource);
|
||||
if (metadata != null) {
|
||||
return metadata;
|
||||
}
|
||||
@ -60,11 +54,4 @@ public class CompositeDataSourcePoolMetadataProvider implements DataSourcePoolMe
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link DataSourcePoolMetadataProvider} delegate to the list.
|
||||
*/
|
||||
public void addDataSourceMetadataProvider(DataSourcePoolMetadataProvider provider) {
|
||||
this.providers.add(provider);
|
||||
}
|
||||
|
||||
}
|
@ -24,20 +24,17 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata;
|
||||
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeDataSourcePoolMetadataProvider}.
|
||||
* Tests for {@link DataSourcePoolMetadataProviders}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CompositeDataSourceMetadataProviderTests {
|
||||
public class DataSourcePoolMetadataProvidersTests {
|
||||
|
||||
@Mock
|
||||
private DataSourcePoolMetadataProvider firstProvider;
|
||||
@ -63,27 +60,19 @@ public class CompositeDataSourceMetadataProviderTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(this.firstProvider.getDataSourcePoolMetadata(this.firstDataSource)).willReturn(
|
||||
this.first);
|
||||
given(this.firstProvider.getDataSourcePoolMetadata(this.firstDataSource))
|
||||
.willReturn(this.first);
|
||||
given(this.firstProvider.getDataSourcePoolMetadata(this.secondDataSource))
|
||||
.willReturn(this.second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithProviders() {
|
||||
CompositeDataSourcePoolMetadataProvider provider = new CompositeDataSourcePoolMetadataProvider(
|
||||
DataSourcePoolMetadataProviders provider = new DataSourcePoolMetadataProviders(
|
||||
Arrays.asList(this.firstProvider, this.secondProvider));
|
||||
assertSame(this.first, provider.getDataSourcePoolMetadata(this.firstDataSource));
|
||||
assertSame(this.second, provider.getDataSourcePoolMetadata(this.secondDataSource));
|
||||
assertNull(provider.getDataSourcePoolMetadata(this.unknownDataSource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addProvider() {
|
||||
CompositeDataSourcePoolMetadataProvider provider = new CompositeDataSourcePoolMetadataProvider();
|
||||
assertNull(provider.getDataSourcePoolMetadata(this.firstDataSource));
|
||||
provider.addDataSourceMetadataProvider(this.firstProvider);
|
||||
assertSame(this.first, provider.getDataSourcePoolMetadata(this.firstDataSource));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user