Skip to content
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
@@ -1,8 +1,8 @@
package com.xtrmetl.cdc.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand All @@ -24,7 +24,7 @@
*
* <p>Not a full recursive alias of every key — only known product properties.</p>
*/
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
@Order(ConfigDataEnvironmentPostProcessor.ORDER + 1)
public class MightyEtlConfigAliasEnvironmentPostProcessor implements EnvironmentPostProcessor {

public static final String PROPERTY_SOURCE_NAME = "mightyetl-xtrmetl-aliases";
Expand Down
2 changes: 2 additions & 0 deletions cdc-service/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.env.EnvironmentPostProcessor=\
com.xtrmetl.cdc.config.MightyEtlConfigAliasEnvironmentPostProcessor
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package com.xtrmetl.cdc.config;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.env.MockEnvironment;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -34,10 +43,37 @@ void legacyOnlyIsMirroredToModern() {
assertFalse(aliases.containsKey("xtrmetl.replica.enabled"));
}

@Test
void modernConfigDataWinsOverLegacyConfigData(@TempDir Path tempDir) throws IOException {
Path configFile = tempDir.resolve("application.properties");
Files.writeString(configFile, """
mightyetl.cdc.autostart=false
xtrmetl.cdc.autostart=true
""");

SpringApplication application = new SpringApplication(AliasOrderProbeConfiguration.class);
application.setBannerMode(Banner.Mode.OFF);
application.setWebApplicationType(WebApplicationType.NONE);

try (ConfigurableApplicationContext context = application.run(
"--spring.config.location=" + configFile.toUri()
)) {
assertTrue(context.getEnvironment().getPropertySources().contains(
MightyEtlConfigAliasEnvironmentPostProcessor.PROPERTY_SOURCE_NAME
));
assertEquals("false", context.getEnvironment().getProperty("mightyetl.cdc.autostart"));
assertEquals("false", context.getEnvironment().getProperty("xtrmetl.cdc.autostart"));
}
}

@Test
void emptyWhenNeitherPrefixSet() {
MockEnvironment env = new MockEnvironment();
Map<String, Object> aliases = MightyEtlConfigAliasEnvironmentPostProcessor.buildAliases(env);
assertTrue(aliases.isEmpty());
}

@Configuration(proxyBeanMethods = false)
static class AliasOrderProbeConfiguration {
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.xtrmetl.etl.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
Expand All @@ -18,7 +18,7 @@
* <p>Only explicitly supported product keys are mirrored. See
* {@code docs/rebrand-name-matrix.md} for compatibility boundaries.</p>
*/
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
@Order(ConfigDataEnvironmentPostProcessor.ORDER + 1)
public class MightyEtlConfigAliasEnvironmentPostProcessor implements EnvironmentPostProcessor {

/** Name of the highest-precedence synthetic alias property source. */
Expand Down
2 changes: 2 additions & 0 deletions etl-service/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.env.EnvironmentPostProcessor=\
com.xtrmetl.etl.config.MightyEtlConfigAliasEnvironmentPostProcessor
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package com.xtrmetl.etl.config;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.env.MockEnvironment;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -66,8 +75,41 @@ void modernValueWinsWhenBothNamespacesAreSet() {
assertEquals("4096", aliases.get("xtrmetl.etl.max-payload-bytes"));
}

@Test
void modernConfigDataWinsOverLegacyConfigData(@TempDir Path tempDir) throws IOException {
Path configFile = tempDir.resolve("application.properties");
Files.writeString(configFile, """
mightyetl.etl.max-payload-bytes=4096
xtrmetl.etl.max-payload-bytes=1024
""");

SpringApplication application = new SpringApplication(AliasOrderProbeConfiguration.class);
application.setBannerMode(Banner.Mode.OFF);
application.setWebApplicationType(WebApplicationType.NONE);

try (ConfigurableApplicationContext context = application.run(
"--spring.config.location=" + configFile.toUri()
)) {
assertTrue(context.getEnvironment().getPropertySources().contains(
MightyEtlConfigAliasEnvironmentPostProcessor.PROPERTY_SOURCE_NAME
));
assertEquals(
"4096",
context.getEnvironment().getProperty("mightyetl.etl.max-payload-bytes")
);
assertEquals(
"4096",
context.getEnvironment().getProperty("xtrmetl.etl.max-payload-bytes")
);
}
}

@Test
void emptyWhenUnset() {
assertTrue(MightyEtlConfigAliasEnvironmentPostProcessor.buildAliases(new MockEnvironment()).isEmpty());
}

@Configuration(proxyBeanMethods = false)
static class AliasOrderProbeConfiguration {
}
}
Loading