You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "chia7712 (via GitHub)" <gi...@apache.org> on 2025/11/06 16:19:16 UTC
Re: [PR] KAFKA-19112 Unifying LIST-Type Configuration Validation and Default Values [kafka]
chia7712 commented on code in PR #20334:
URL: https://github.com/apache/kafka/pull/20334#discussion_r2499701737
##########
clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java:
##########
@@ -758,4 +758,59 @@ public void testListSizeValidatorToString() {
assertEquals("List containing maximum of 5 elements", ListSize.atMostOfSize(5).toString());
}
+ @Test
+ public void testListValidatorAnyNonDuplicateValues() {
+ ConfigDef.ValidList allowAnyNonDuplicateValues = ConfigDef.ValidList.anyNonDuplicateValues(true, true);
+ assertDoesNotThrow(() -> allowAnyNonDuplicateValues.ensureValid("test.config", List.of("a", "b", "c")));
+ assertDoesNotThrow(() -> allowAnyNonDuplicateValues.ensureValid("test.config", List.of()));
+ assertDoesNotThrow(() -> allowAnyNonDuplicateValues.ensureValid("test.config", null));
+ ConfigException exception1 = assertThrows(ConfigException.class, () -> allowAnyNonDuplicateValues.ensureValid("test.config", List.of("a", "a")));
+ assertEquals("Configuration 'test.config' values must not be duplicated.", exception1.getMessage());
+ ConfigException exception2 = assertThrows(ConfigException.class, () -> allowAnyNonDuplicateValues.ensureValid("test.config", List.of("")));
+ assertEquals("Configuration 'test.config' values must not be empty.", exception2.getMessage());
+
+ ConfigDef.ValidList allowAnyNonDuplicateValuesAndNull = ConfigDef.ValidList.anyNonDuplicateValues(false, true);
+ assertDoesNotThrow(() -> allowAnyNonDuplicateValuesAndNull.ensureValid("test.config", List.of("a", "b", "c")));
+ assertDoesNotThrow(() -> allowAnyNonDuplicateValuesAndNull.ensureValid("test.config", null));
+ ConfigException exception3 = assertThrows(ConfigException.class, () -> allowAnyNonDuplicateValuesAndNull.ensureValid("test.config", List.of()));
+ assertEquals("Configuration 'test.config' must not be empty. Valid values include: any non-empty value", exception3.getMessage());
+ ConfigException exception4 = assertThrows(ConfigException.class, () -> allowAnyNonDuplicateValuesAndNull.ensureValid("test.config", List.of("a", "a")));
+ assertEquals("Configuration 'test.config' values must not be duplicated.", exception4.getMessage());
+ ConfigException exception5 = assertThrows(ConfigException.class, () -> allowAnyNonDuplicateValuesAndNull.ensureValid("test.config", List.of("")));
+ assertEquals("Configuration 'test.config' values must not be empty.", exception5.getMessage());
+
+ ConfigDef.ValidList allowAnyNonDuplicateValuesAndEmptyList = ConfigDef.ValidList.anyNonDuplicateValues(true, false);
Review Comment:
Is there a test for `anyNonDuplicateValues(false, false);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org