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

FISH-8317 - Microprofile Config NPE for profiled setting #6550

Merged
merged 2 commits into from
Mar 22, 2024
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 @@ -109,8 +109,12 @@ private ConfigValueImpl resolve(String propertyName, String propertyDefault, boo

if(profile != null && result != null) {
ConfigValueImpl resultWithoutProfile = getValue(resolveExpression(propertyName));
result = resultWithoutProfile.getSourceOrdinal() == result.getSourceOrdinal() ? result :
(resultWithoutProfile.getSourceOrdinal() > result.getSourceOrdinal()) ? resultWithoutProfile : result;
// Note: In case there is a non-profiled value from a source with the same ordinal value, it will be ignored.
// All spec versions including v3.1 do not include a definition for this edge case -
// all sources are supposed to have a unique ordinal value.
if (resultWithoutProfile != null && resultWithoutProfile.getSourceOrdinal() > result.getSourceOrdinal()) {
result = resultWithoutProfile;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.junit.Test;

import java.util.HashMap;
import java.util.Set;

import static fish.payara.nucleus.microprofile.config.spi.ConfigTestUtils.createSource;
import static java.util.Collections.singleton;
Expand All @@ -55,7 +56,10 @@
public class ConfigExpressionResolverTest {

private final ConfigSource source = createSource("S1", 100, new HashMap<>());
private final ConfigExpressionResolver resolver = new ConfigExpressionResolver(singleton(source), "test");
private final ConfigSource sourceHigherOrdinal = createSource("SHO", 110, new HashMap<>());
private final ConfigSource sourceEqualOrdinal = createSource("SEO", 100, new HashMap<>());
private final ConfigSource sourceLowerOrdinal = createSource("SEO", 90, new HashMap<>());
private final ConfigExpressionResolver resolver = new ConfigExpressionResolver(Set.of(source, sourceHigherOrdinal, sourceEqualOrdinal, sourceLowerOrdinal), "test");

@Before
public void configureConfigProperties() {
Expand All @@ -74,6 +78,13 @@ public void configureConfigProperties() {
source.getProperties().put("default.key.reference", "${${not.existing:key}:not.found}");
source.getProperties().put("%test.fish.payara.badger", "mushroom");
source.getProperties().put("fish.payara.badger", "badger");
source.getProperties().put("%test.fish.payara.rod", "bites");

sourceHigherOrdinal.getProperties().put("fish.payara.rod", "nobites");
sourceHigherOrdinal.getProperties().put("%test.fish.payara.profile-only", "gotcha");

sourceEqualOrdinal.getProperties().put("fish.payara.badger", "i-shall-be-ignored");
sourceLowerOrdinal.getProperties().put("fish.payara.badger", "i-shall-be-ignored");
}

@Test
Expand Down Expand Up @@ -180,9 +191,25 @@ public void testExpressionExpansionDisabled() {

@Test
public void testProfiles() {
// This test case does not only test if the profiled value is used from the same source, but also if the
// defined equal and lower ordinal sources are ignored
ConfigValue result = resolver.resolve("fish.payara.badger");
assertEquals("mushroom", result.getValue());
assertEquals("mushroom", result.getRawValue());
}

@Test
public void testProfilesOverrideProfiledValueFromSourceWithHigherOrdinal() {
ConfigValue result = resolver.resolve("fish.payara.rod");
assertEquals("nobites", result.getValue());
assertEquals("nobites", result.getRawValue());
}

@Test
public void testProfilesDoNotFailToLookupWhenOnlyProfiledValueExists() {
ConfigValue result = resolver.resolve("fish.payara.profile-only");
assertEquals("gotcha", result.getValue());
assertEquals("gotcha", result.getRawValue());
}

}