79
79
*/
80
80
public class HealthIndicatorAutoConfigurationTests {
81
81
82
- public final ContextLoader contextLoader = new ContextLoader ()
83
- .autoConfig (HealthIndicatorAutoConfiguration .class ,
84
- ManagementServerProperties .class );
82
+ public final ContextLoader contextLoader = new ContextLoader ().autoConfig (
83
+ HealthIndicatorAutoConfiguration .class , ManagementServerProperties .class );
85
84
86
85
@ Test
87
86
public void defaultHealthIndicator () {
@@ -99,12 +98,12 @@ public void defaultHealthIndicatorsDisabled() {
99
98
public void defaultHealthIndicatorsDisabledWithCustomOne () {
100
99
this .contextLoader .config (CustomHealthIndicator .class )
101
100
.env ("management.health.defaults.enabled:false" ).load (context -> {
102
- Map <String , HealthIndicator > beans = context
103
- .getBeansOfType (HealthIndicator .class );
104
- assertThat (beans ).hasSize (1 );
105
- assertThat (context .getBean ("customHealthIndicator" ))
106
- .isSameAs (beans .values ().iterator ().next ());
107
- });
101
+ Map <String , HealthIndicator > beans = context
102
+ .getBeansOfType (HealthIndicator .class );
103
+ assertThat (beans ).hasSize (1 );
104
+ assertThat (context .getBean ("customHealthIndicator" ))
105
+ .isSameAs (beans .values ().iterator ().next ());
106
+ });
108
107
}
109
108
110
109
@ Test
@@ -132,16 +131,18 @@ public void notRedisHealthIndicator() {
132
131
133
132
@ Test
134
133
public void mongoHealthIndicator () {
135
- this .contextLoader .autoConfigFirst (MongoAutoConfiguration .class ,
136
- MongoDataAutoConfiguration .class )
134
+ this .contextLoader
135
+ .autoConfigFirst (MongoAutoConfiguration .class ,
136
+ MongoDataAutoConfiguration .class )
137
137
.env ("management.health.diskspace.enabled:false" )
138
138
.load (hasSingleHealthIndicator (MongoHealthIndicator .class ));
139
139
}
140
140
141
141
@ Test
142
142
public void notMongoHealthIndicator () {
143
- this .contextLoader .autoConfigFirst (MongoAutoConfiguration .class ,
144
- MongoDataAutoConfiguration .class )
143
+ this .contextLoader
144
+ .autoConfigFirst (MongoAutoConfiguration .class ,
145
+ MongoDataAutoConfiguration .class )
145
146
.env ("management.health.mongo.enabled:false" ,
146
147
"management.health.diskspace.enabled:false" )
147
148
.load (hasSingleHealthIndicator (ApplicationHealthIndicator .class ));
@@ -152,10 +153,10 @@ public void combinedHealthIndicator() {
152
153
this .contextLoader .autoConfigFirst (MongoAutoConfiguration .class ,
153
154
RedisAutoConfiguration .class , MongoDataAutoConfiguration .class ,
154
155
SolrAutoConfiguration .class ).load (context -> {
155
- Map <String , HealthIndicator > beans = context
156
- .getBeansOfType (HealthIndicator .class );
157
- assertThat (beans ).hasSize (4 );
158
- });
156
+ Map <String , HealthIndicator > beans = context
157
+ .getBeansOfType (HealthIndicator .class );
158
+ assertThat (beans ).hasSize (4 );
159
+ });
159
160
}
160
161
161
162
@ Test
@@ -167,9 +168,9 @@ public void dataSourceHealthIndicator() {
167
168
168
169
@ Test
169
170
public void dataSourceHealthIndicatorWithSeveralDataSources () {
170
- this .contextLoader . config ( EmbeddedDataSourceConfiguration . class ,
171
- DataSourceConfig . class ). env ( "management.health.diskspace.enabled:false" )
172
- .load (context -> {
171
+ this .contextLoader
172
+ . config ( EmbeddedDataSourceConfiguration . class , DataSourceConfig . class )
173
+ .env ( "management.health.diskspace.enabled:false" ). load (context -> {
173
174
Map <String , HealthIndicator > beans = context
174
175
.getBeansOfType (HealthIndicator .class );
175
176
assertThat (beans ).hasSize (1 );
@@ -182,34 +183,38 @@ public void dataSourceHealthIndicatorWithSeveralDataSources() {
182
183
183
184
@ Test
184
185
public void dataSourceHealthIndicatorWithAbstractRoutingDataSource () {
185
- this .contextLoader .config (EmbeddedDataSourceConfiguration .class ,
186
- RoutingDatasourceConfig .class )
186
+ this .contextLoader
187
+ .config (EmbeddedDataSourceConfiguration .class ,
188
+ RoutingDatasourceConfig .class )
187
189
.env ("management.health.diskspace.enabled:false" )
188
190
.load (hasSingleHealthIndicator (DataSourceHealthIndicator .class ));
189
191
}
190
192
191
193
@ Test
192
194
public void dataSourceHealthIndicatorWithCustomValidationQuery () {
193
- this .contextLoader .config (DataSourceConfig .class ,
194
- DataSourcePoolMetadataProvidersConfiguration .class ,
195
- HealthIndicatorAutoConfiguration .class ).env (
196
- "spring.datasource.test.validation-query:SELECT from FOOBAR" ,
197
- "management.health.diskspace.enabled:false" ).load (context -> {
198
- Map <String , HealthIndicator > beans = context
199
- .getBeansOfType (HealthIndicator .class );
200
- assertThat (beans ).hasSize (1 );
201
- HealthIndicator healthIndicator = beans .values ().iterator ().next ();
202
- assertThat (healthIndicator .getClass ()).isEqualTo (DataSourceHealthIndicator .class );
203
- DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator ) healthIndicator ;
204
- assertThat (dataSourceHealthIndicator .getQuery ()).isEqualTo ("SELECT from FOOBAR" );
205
- });
195
+ this .contextLoader
196
+ .config (DataSourceConfig .class ,
197
+ DataSourcePoolMetadataProvidersConfiguration .class ,
198
+ HealthIndicatorAutoConfiguration .class )
199
+ .env ("spring.datasource.test.validation-query:SELECT from FOOBAR" ,
200
+ "management.health.diskspace.enabled:false" )
201
+ .load (context -> {
202
+ Map <String , HealthIndicator > beans = context
203
+ .getBeansOfType (HealthIndicator .class );
204
+ assertThat (beans ).hasSize (1 );
205
+ HealthIndicator healthIndicator = beans .values ().iterator ().next ();
206
+ assertThat (healthIndicator .getClass ())
207
+ .isEqualTo (DataSourceHealthIndicator .class );
208
+ DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator ) healthIndicator ;
209
+ assertThat (dataSourceHealthIndicator .getQuery ())
210
+ .isEqualTo ("SELECT from FOOBAR" );
211
+ });
206
212
}
207
213
208
214
@ Test
209
215
public void notDataSourceHealthIndicator () {
210
216
this .contextLoader .config (EmbeddedDataSourceConfiguration .class )
211
- .env (
212
- "management.health.db.enabled:false" ,
217
+ .env ("management.health.db.enabled:false" ,
213
218
"management.health.diskspace.enabled:false" )
214
219
.load (hasSingleHealthIndicator (ApplicationHealthIndicator .class ));
215
220
}
@@ -283,25 +288,30 @@ public void notJmsHealthIndicator() {
283
288
284
289
@ Test
285
290
public void elasticsearchHealthIndicator () {
286
- this .contextLoader .autoConfigFirst (JestClientConfiguration .class ,
287
- JestAutoConfiguration .class , ElasticsearchAutoConfiguration .class )
291
+ this .contextLoader
292
+ .autoConfigFirst (JestClientConfiguration .class ,
293
+ JestAutoConfiguration .class , ElasticsearchAutoConfiguration .class )
288
294
.env ("spring.data.elasticsearch.cluster-nodes:localhost:0" ,
289
295
"management.health.diskspace.enabled:false" )
296
+ .systemProperty ("es.set.netty.runtime.available.processors" , "false" )
290
297
.load (hasSingleHealthIndicator (ElasticsearchHealthIndicator .class ));
291
298
}
292
299
293
300
@ Test
294
301
public void elasticsearchJestHealthIndicator () {
295
- this .contextLoader .autoConfigFirst (JestClientConfiguration .class ,
296
- JestAutoConfiguration .class )
302
+ this .contextLoader
303
+ .autoConfigFirst (JestClientConfiguration .class ,
304
+ JestAutoConfiguration .class )
297
305
.env ("management.health.diskspace.enabled:false" )
306
+ .systemProperty ("es.set.netty.runtime.available.processors" , "false" )
298
307
.load (hasSingleHealthIndicator (ElasticsearchJestHealthIndicator .class ));
299
308
}
300
309
301
310
@ Test
302
311
public void notElasticsearchHealthIndicator () {
303
- this .contextLoader .autoConfigFirst (JestClientConfiguration .class ,
304
- JestAutoConfiguration .class , ElasticsearchAutoConfiguration .class )
312
+ this .contextLoader
313
+ .autoConfigFirst (JestClientConfiguration .class ,
314
+ JestAutoConfiguration .class , ElasticsearchAutoConfiguration .class )
305
315
.env ("management.health.elasticsearch.enabled:false" ,
306
316
"spring.data.elasticsearch.properties.path.home:target" ,
307
317
"management.health.diskspace.enabled:false" )
0 commit comments