Skip to content

Commit

Permalink
Merge pull request #44952 from thibaultmeyer/feature/44923-spring-clo…
Browse files Browse the repository at this point in the history
…ud-config-ordinal-custom

Spring Cloud Configuration ordinal customization
  • Loading branch information
geoand authored Dec 6, 2024
2 parents 9777061 + 20c598d commit 1fada28
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
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;
}
}

0 comments on commit 1fada28

Please sign in to comment.