Make zk health indicator able to be disabled via normal properties.
Ie, use `@ConditionalOnEnabledHealthIndicator(zookeeper)` fixes gh-101
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.cloud.zookeeper.discovery;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.x.discovery.ServiceDiscovery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -69,6 +70,7 @@ public class ZookeeperDiscoveryAutoConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnEnabledHealthIndicator("zookeeper")
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
protected static class ZookeeperDiscoveryHealthConfig {
|
||||
@Autowired(required = false)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springframework.cloud.zookeeper.discovery;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.zookeeper.discovery.test.CommonTestConfig;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT,
|
||||
properties = "management.health.zookeeper.enabled=false")
|
||||
public class ZookeeperDiscoveryHealthIndicatorDisabledTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
private ZookeeperDiscoveryHealthIndicator healthIndicator;
|
||||
|
||||
// Issue: #101 - ZookeeperDiscoveryHealthIndicator should be able to be disabled with a property
|
||||
@Test public void healthIndicatorDisabled() {
|
||||
// when:
|
||||
// then:
|
||||
then(this.healthIndicator).isNull();
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@Import(CommonTestConfig.class)
|
||||
static class Config {}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user