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
Expand Up @@ -146,6 +146,9 @@ public <T> Integer getIntOrDefault(ConfigProperty<T> configProperty) {
}

public <T> Boolean getBoolean(ConfigProperty<T> configProperty) {
if (configProperty.hasDefaultValue()) {
return getBooleanOrDefault(configProperty);
}
Option<Object> rawValue = getRawValue(configProperty);
return rawValue.map(v -> Boolean.parseBoolean(v.toString())).orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class TestConfigProperty extends HoodieConfig {
.defaultValue("false")
.withDocumentation("Fake config only for testing");

public static ConfigProperty<String> FAKE_BOOLEAN_CONFIG_NO_DEFAULT = ConfigProperty
.key("test.fake.boolean.config")
.noDefaultValue()
.withDocumentation("Fake config only for testing");

public static ConfigProperty<Integer> FAKE_INTEGER_CONFIG = ConfigProperty
.key("test.fake.integer.config")
.defaultValue(0)
Expand All @@ -58,11 +63,23 @@ public void testGetTypedValue() {
hoodieConfig.setValue(FAKE_STRING_CONFIG, "5");
assertEquals(5, hoodieConfig.getInt(FAKE_STRING_CONFIG));

assertNull(hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
assertEquals(false, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
hoodieConfig.setValue(FAKE_BOOLEAN_CONFIG, "true");
assertEquals(true, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
}

@Test
public void testGetBooleanShouldReturnFalseWhenDefaultValueFalseButNotSet() {
HoodieConfig hoodieConfig = new HoodieConfig();
assertEquals(false, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
}

@Test
public void testGetBooleanShouldReturnNullWhenNoDefaultValuePresent() {
HoodieConfig hoodieConfig = new HoodieConfig();
assertNull(hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG_NO_DEFAULT));
}

@Test
public void testGetOrDefault() {
Properties props = new Properties();
Expand Down