Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Cloud Configuration ordinal customization #44952

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public interface SpringCloudConfigClientConfig {
*/
Optional<List<String>> profiles();

/**
* Microprofile Config ordinal.
*/
@WithDefault("450")
int ordinal();

/** */
default boolean usernameAndPasswordSet() {
return username().isPresent() && password().isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context

log.debug("Obtained " + responses.size() + " from the config server");

int ordinal = 450;
int ordinal = config.ordinal();
// Profiles are looked from the highest ordinal to lowest, so we reverse the collection to build the source list
Collections.reverse(responses);
for (Response response : responses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void testExtensionDisabled() {

// Arrange
final ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class);
final SpringCloudConfigClientConfig config = configForTesting(false, "foo", MOCK_SERVER_PORT, true);
final SpringCloudConfigClientConfig config = configForTesting(false, "foo", MOCK_SERVER_PORT, true, 450);
final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory();

// Act
Expand All @@ -62,7 +62,7 @@ void testNameNotProvided() {

// Arrange
final ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class);
final SpringCloudConfigClientConfig config = configForTesting(true, null, MOCK_SERVER_PORT, true);
final SpringCloudConfigClientConfig config = configForTesting(true, null, MOCK_SERVER_PORT, true, 450);
final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory();

// Act
Expand All @@ -77,7 +77,7 @@ void testInAppCDsGeneration() {

// Arrange
final ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class);
final SpringCloudConfigClientConfig config = configForTesting(true, "foo", MOCK_SERVER_PORT, true);
final SpringCloudConfigClientConfig config = configForTesting(true, "foo", MOCK_SERVER_PORT, true, 450);
final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory();

System.setProperty(ApplicationLifecycleManager.QUARKUS_APPCDS_GENERATE_PROP, "true");
Expand All @@ -97,7 +97,7 @@ void testFailFastDisable() {

// Arrange
final ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class);
final SpringCloudConfigClientConfig config = configForTesting(true, "unknown-application", 1234, false);
final SpringCloudConfigClientConfig config = configForTesting(true, "unknown-application", 1234, false, 450);
final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory();

Mockito.when(context.getProfiles()).thenReturn(List.of("dev"));
Expand All @@ -114,7 +114,7 @@ void testFailFastEnabled() {

// Arrange
final ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class);
final SpringCloudConfigClientConfig config = configForTesting(true, "unknown-application", 1234, true);
final SpringCloudConfigClientConfig config = configForTesting(true, "unknown-application", 1234, true, 450);
final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory();

Mockito.when(context.getProfiles()).thenReturn(List.of("dev"));
Expand All @@ -130,7 +130,7 @@ void testBasic() throws IOException {
// Arrange
final String profile = "dev";
final ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class);
final SpringCloudConfigClientConfig config = configForTesting(true, "foo", MOCK_SERVER_PORT, true);
final SpringCloudConfigClientConfig config = configForTesting(true, "foo", MOCK_SERVER_PORT, true, 450);
final SpringCloudConfigClientConfigSourceFactory factory = new SpringCloudConfigClientConfigSourceFactory();

Mockito.when(context.getProfiles()).thenReturn(List.of(profile));
Expand Down Expand Up @@ -176,7 +176,7 @@ void testBasic() throws IOException {
}

private SpringCloudConfigClientConfig configForTesting(final boolean isEnabled, final String appName,
final int serverPort, final boolean isFailFastEnabled) {
final int serverPort, final boolean isFailFastEnabled, final int ordinal) {

final SpringCloudConfigClientConfig config = Mockito.mock(SpringCloudConfigClientConfig.class);
when(config.enabled()).thenReturn(isEnabled);
Expand All @@ -192,6 +192,7 @@ private SpringCloudConfigClientConfig configForTesting(final boolean isEnabled,
when(config.keyStore()).thenReturn(Optional.empty());
when(config.trustCerts()).thenReturn(false);
when(config.headers()).thenReturn(new HashMap<>());
when(config.ordinal()).thenReturn(ordinal);

return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private static SpringCloudConfigClientConfig configForTesting() {
when(config.keyStore()).thenReturn(Optional.empty());
when(config.trustCerts()).thenReturn(false);
when(config.headers()).thenReturn(new HashMap<>());
when(config.ordinal()).thenReturn(450);
return config;
}
}
Loading