Adds support for retry in profile specific properties.
in application-<profile>.{properties|yaml}
spring.config.import=configserver:http://configserver.example.com?fail-fast=true&max-attempts=10&max-interval=1500&multiplier=1.2&initial-interval=1100"
This required that the RetryTemplate be created as late as possible and it is no longer put in the bootstrap context. A RetryTemplateFactory was created so the LoaderInterceptor and the ConfigServerInstanceProvider can create a RetryTemplate. ConfigServerConfigDataLocationResolver creates RetryProperties from the url parameters if they are provided.
ConfigServerConfigDataLoader now creates a ConfigClientFailFastException and registers it in the application context rather and returns an empty ConfigData rather than throwing and exception. Then in ConfigClientAutoConfiguration an ApplicationStartedEvent is listened for and if the fail fast exception is there, throws it halting execution. This all allows logging in ConfigData to show.
Fixes gh-1797
This commit is contained in:
@@ -16,12 +16,17 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class ApplicationFailFastTests {
|
||||
|
||||
@Test
|
||||
@@ -34,13 +39,15 @@ public class ApplicationFailFastTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configDataContextFails() {
|
||||
public void configDataContextFails(CapturedOutput output) {
|
||||
assertThatThrownBy(() -> {
|
||||
new SpringApplicationBuilder().sources(Application.class).run("--server.port=0",
|
||||
"--spring.cloud.config.enabled=true", "--spring.cloud.config.fail-fast=true",
|
||||
"--spring.config.import=optional:configserver:http://serverhostdoesnotexist:1234");
|
||||
"--spring.config.import=optional:configserver:http://serverhostdoesnotexist:1234",
|
||||
"--spring.cloud.config.server.enabled=false",
|
||||
"--logging.level.org.springframework.boot.context.config=TRACE");
|
||||
}).as("Exception not caused by fail fast").hasMessageContaining("fail fast");
|
||||
|
||||
assertThat(output).contains("Retry: count=5");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user