added failFast option
fixes gh-1
This commit is contained in:
@@ -57,12 +57,14 @@ public class PropertySourceBootstrapConfiguration implements
|
||||
.getLog(PropertySourceBootstrapConfiguration.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<PropertySourceLocator> propertySourceLocators = new ArrayList<PropertySourceLocator>();
|
||||
private List<PropertySourceLocator> propertySourceLocators = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private ConfigClientProperties configClientProperties;
|
||||
|
||||
public void setPropertySourceLocators(
|
||||
Collection<PropertySourceLocator> propertySourceLocators) {
|
||||
this.propertySourceLocators = new ArrayList<PropertySourceLocator>(
|
||||
propertySourceLocators);
|
||||
this.propertySourceLocators = new ArrayList<>(propertySourceLocators);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,6 +79,9 @@ public class PropertySourceBootstrapConfiguration implements
|
||||
source = locator.locate(applicationContext.getEnvironment());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (configClientProperties.isFailFast()) {
|
||||
throw new IllegalStateException("Could not locate PropertySource. The fail fast property is set, failing", e);
|
||||
}
|
||||
logger.error("Could not locate PropertySource: " + e.getMessage());
|
||||
}
|
||||
if (source == null) {
|
||||
|
||||
@@ -52,6 +52,8 @@ public class ConfigClientProperties {
|
||||
|
||||
private Discovery discovery = new Discovery();
|
||||
|
||||
private boolean failFast = false;
|
||||
|
||||
private ConfigClientProperties() {
|
||||
}
|
||||
|
||||
@@ -127,6 +129,14 @@ public class ConfigClientProperties {
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
public boolean isFailFast() {
|
||||
return failFast;
|
||||
}
|
||||
|
||||
public void setFailFast(boolean failFast) {
|
||||
this.failFast = failFast;
|
||||
}
|
||||
|
||||
private String[] extractCredentials() {
|
||||
String[] result = new String[3];
|
||||
String uri = this.uri;
|
||||
@@ -216,7 +226,8 @@ public class ConfigClientProperties {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigClientProperties [name=" + name + ", env=" + env + ", label="
|
||||
+ label + ", uri=" + uri + ", discovery.enabled=" + discovery.enabled + "]";
|
||||
+ label + ", uri=" + uri + ", discovery.enabled=" + discovery.enabled
|
||||
+ ", failFast="+ failFast + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ApplicationFailFastTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
try {
|
||||
new SpringApplicationBuilder()
|
||||
.sources(Application.class)
|
||||
.run("--server.port=0",
|
||||
"--spring.cloud.config.failFast=true",
|
||||
"--spring.cloud.config.uit=http://server-host-doesnt-exist:1234");
|
||||
fail("failFast option did not produce an exception");
|
||||
} catch (Exception e) {
|
||||
assertTrue("Exception not caused by fail fast", e.getMessage().contains("fail fast"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,7 +60,8 @@ public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
public void vanilla() throws IOException {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo();
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
|
||||
.properties("spring.cloud.config.server.git.uri=" + uri).run();
|
||||
//TODO: why didn't .properties() work for me?
|
||||
.run("--spring.cloud.config.server.git.uri=" + uri);
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
@@ -72,8 +73,9 @@ public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(false)
|
||||
.properties("spring.cloud.config.server.git.uri=" + uri,
|
||||
"spring.cloud.config.server.git.searchPaths=sub").run();
|
||||
//TODO: why didn't .properties() work for me?
|
||||
.run("--spring.cloud.config.server.git.uri=" + uri,
|
||||
"--spring.cloud.config.server.git.searchPaths=sub");
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
|
||||
Reference in New Issue
Block a user