Skip to content

Commit e21e548

Browse files
author
T2233
committed
KAFKA-19112:cleanup.policy shouldn't be empty
1 parent 14c9c65 commit e21e548

File tree

6 files changed

+457
-417
lines changed

6 files changed

+457
-417
lines changed

Diff for: clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java

+105-61
Large diffs are not rendered by default.

Diff for: clients/src/main/java/org/apache/kafka/common/config/TopicConfig.java

+86-85
Large diffs are not rendered by default.

Diff for: clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java

+121-120
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public class ConfigDefTest {
5454
@Test
5555
public void testBasicTypes() {
5656
ConfigDef def = new ConfigDef().define("a", Type.INT, 5, Range.between(0, 14), Importance.HIGH, "docs")
57-
.define("b", Type.LONG, Importance.HIGH, "docs")
58-
.define("c", Type.STRING, "hello", Importance.HIGH, "docs")
59-
.define("d", Type.LIST, Importance.HIGH, "docs")
60-
.define("e", Type.DOUBLE, Importance.HIGH, "docs")
61-
.define("f", Type.CLASS, Importance.HIGH, "docs")
62-
.define("g", Type.BOOLEAN, Importance.HIGH, "docs")
63-
.define("h", Type.BOOLEAN, Importance.HIGH, "docs")
64-
.define("i", Type.BOOLEAN, Importance.HIGH, "docs")
65-
.define("j", Type.PASSWORD, Importance.HIGH, "docs");
57+
.define("b", Type.LONG, Importance.HIGH, "docs")
58+
.define("c", Type.STRING, "hello", Importance.HIGH, "docs")
59+
.define("d", Type.LIST, Importance.HIGH, "docs")
60+
.define("e", Type.DOUBLE, Importance.HIGH, "docs")
61+
.define("f", Type.CLASS, Importance.HIGH, "docs")
62+
.define("g", Type.BOOLEAN, Importance.HIGH, "docs")
63+
.define("h", Type.BOOLEAN, Importance.HIGH, "docs")
64+
.define("i", Type.BOOLEAN, Importance.HIGH, "docs")
65+
.define("j", Type.PASSWORD, Importance.HIGH, "docs");
6666

6767
Properties props = new Properties();
6868
props.put("a", "1 ");
@@ -116,7 +116,7 @@ public void testParsingEmptyDefaultValueForStringFieldShouldSucceed() {
116116
@Test
117117
public void testDefinedTwice() {
118118
assertThrows(ConfigException.class, () -> new ConfigDef().define("a", Type.STRING,
119-
Importance.HIGH, "docs").define("a", Type.INT, Importance.HIGH, "docs"));
119+
Importance.HIGH, "docs").define("a", Type.INT, Importance.HIGH, "docs"));
120120
}
121121

122122
@Test
@@ -147,13 +147,13 @@ private void testBadInputs(Type type, Object... values) {
147147
@Test
148148
public void testInvalidDefaultRange() {
149149
assertThrows(ConfigException.class, () -> new ConfigDef().define("name", Type.INT, -1,
150-
Range.between(0, 10), Importance.HIGH, "docs"));
150+
Range.between(0, 10), Importance.HIGH, "docs"));
151151
}
152152

153153
@Test
154154
public void testInvalidDefaultString() {
155155
assertThrows(ConfigException.class, () -> new ConfigDef().define("name", Type.STRING, "bad",
156-
ValidString.in("valid", "values"), Importance.HIGH, "docs"));
156+
ValidString.in("valid", "values"), Importance.HIGH, "docs"));
157157
}
158158

159159
@Test
@@ -169,10 +169,11 @@ public void testValidators() {
169169
testValidators(Type.STRING, ValidString.in("good", "values", "default"), "default",
170170
new Object[]{"good", "values", "default"}, new Object[]{"bad", "inputs", "DEFAULT", null});
171171
testValidators(Type.STRING, CaseInsensitiveValidString.in("good", "values", "default"), "default",
172-
new Object[]{"gOOd", "VALUES", "default"}, new Object[]{"Bad", "iNPUts", null});
173-
testValidators(Type.LIST, ConfigDef.ValidList.in("1", "2", "3"), "1", new Object[]{"1", "2", "3"}, new Object[]{"4", "5", "6"});
174-
testValidators(Type.STRING, new ConfigDef.NonNullValidator(), "a", new Object[]{"abb"}, new Object[] {null});
175-
testValidators(Type.STRING, ConfigDef.CompositeValidator.of(new ConfigDef.NonNullValidator(), ValidString.in("a", "b")), "a", new Object[]{"a", "b"}, new Object[] {null, -1, "c"});
172+
new Object[]{"gOOd", "VALUES", "default"}, new Object[]{"Bad", "iNPUts", null});
173+
testValidators(Type.LIST, ConfigDef.ValidList.inWithEmptyCheck(true, "1", "2", "3"), "1", new Object[]{"1", "2", "3"}, new Object[]{"4", "5", "6"});
174+
testValidators(Type.LIST, ConfigDef.ValidList.inWithEmptyCheck(false, "1", "2", "3"), "1", new Object[]{"1", "2", "3"}, new Object[]{""});
175+
testValidators(Type.STRING, new ConfigDef.NonNullValidator(), "a", new Object[]{"abb"}, new Object[]{null});
176+
testValidators(Type.STRING, ConfigDef.CompositeValidator.of(new ConfigDef.NonNullValidator(), ValidString.in("a", "b")), "a", new Object[]{"a", "b"}, new Object[]{null, -1, "c"});
176177
testValidators(Type.STRING, new ConfigDef.NonEmptyStringWithoutControlChars(), "defaultname",
177178
new Object[]{"test", "name", "test/test", "test\u1234", "\u1324name\\", "/+%>&):??<&()?-", "+1", "\uD83D\uDE01", "\uF3B1", " test \n\r", "\n hello \t"},
178179
new Object[]{"nontrailing\nnotallowed", "as\u0001cii control char", "tes\rt", "test\btest", "1\t2", ""});
@@ -203,7 +204,7 @@ public void testNullDefaultWithValidator() {
203204

204205
ConfigDef def = new ConfigDef();
205206
def.define(key, Type.STRING, ConfigDef.NO_DEFAULT_VALUE,
206-
ValidString.in("ONE", "TWO", "THREE"), Importance.HIGH, "docs");
207+
ValidString.in("ONE", "TWO", "THREE"), Importance.HIGH, "docs");
207208

208209
Properties props = new Properties();
209210
props.put(key, "ONE");
@@ -215,17 +216,17 @@ public void testNullDefaultWithValidator() {
215216
public void testGroupInference() {
216217
List<String> expected1 = Arrays.asList("group1", "group2");
217218
ConfigDef def1 = new ConfigDef()
218-
.define("a", Type.INT, Importance.HIGH, "docs", "group1", 1, Width.SHORT, "a")
219-
.define("b", Type.INT, Importance.HIGH, "docs", "group2", 1, Width.SHORT, "b")
220-
.define("c", Type.INT, Importance.HIGH, "docs", "group1", 2, Width.SHORT, "c");
219+
.define("a", Type.INT, Importance.HIGH, "docs", "group1", 1, Width.SHORT, "a")
220+
.define("b", Type.INT, Importance.HIGH, "docs", "group2", 1, Width.SHORT, "b")
221+
.define("c", Type.INT, Importance.HIGH, "docs", "group1", 2, Width.SHORT, "c");
221222

222223
assertEquals(expected1, def1.groups());
223224

224225
List<String> expected2 = Arrays.asList("group2", "group1");
225226
ConfigDef def2 = new ConfigDef()
226-
.define("a", Type.INT, Importance.HIGH, "docs", "group2", 1, Width.SHORT, "a")
227-
.define("b", Type.INT, Importance.HIGH, "docs", "group2", 2, Width.SHORT, "b")
228-
.define("c", Type.INT, Importance.HIGH, "docs", "group1", 2, Width.SHORT, "c");
227+
.define("a", Type.INT, Importance.HIGH, "docs", "group2", 1, Width.SHORT, "a")
228+
.define("b", Type.INT, Importance.HIGH, "docs", "group2", 2, Width.SHORT, "b")
229+
.define("c", Type.INT, Importance.HIGH, "docs", "group1", 2, Width.SHORT, "c");
229230

230231
assertEquals(expected2, def2.groups());
231232
}
@@ -251,10 +252,10 @@ public void testParseForValidate() {
251252
expected.put("d", configD);
252253

253254
ConfigDef def = new ConfigDef()
254-
.define("a", Type.INT, Importance.HIGH, "docs", "group", 1, Width.SHORT, "a", Arrays.asList("b", "c"), new IntegerRecommender(false))
255-
.define("b", Type.INT, Importance.HIGH, "docs", "group", 2, Width.SHORT, "b", new IntegerRecommender(true))
256-
.define("c", Type.INT, Importance.HIGH, "docs", "group", 3, Width.SHORT, "c", new IntegerRecommender(true))
257-
.define("d", Type.INT, Importance.HIGH, "docs", "group", 4, Width.SHORT, "d", singletonList("b"), new IntegerRecommender(false));
255+
.define("a", Type.INT, Importance.HIGH, "docs", "group", 1, Width.SHORT, "a", Arrays.asList("b", "c"), new IntegerRecommender(false))
256+
.define("b", Type.INT, Importance.HIGH, "docs", "group", 2, Width.SHORT, "b", new IntegerRecommender(true))
257+
.define("c", Type.INT, Importance.HIGH, "docs", "group", 3, Width.SHORT, "c", new IntegerRecommender(true))
258+
.define("d", Type.INT, Importance.HIGH, "docs", "group", 4, Width.SHORT, "d", singletonList("b"), new IntegerRecommender(false));
258259

259260
Map<String, String> props = new HashMap<>();
260261
props.put("a", "1");
@@ -289,10 +290,10 @@ public void testValidate() {
289290
expected.put("d", configD);
290291

291292
ConfigDef def = new ConfigDef()
292-
.define("a", Type.INT, Importance.HIGH, "docs", "group", 1, Width.SHORT, "a", Arrays.asList("b", "c"), new IntegerRecommender(false))
293-
.define("b", Type.INT, Importance.HIGH, "docs", "group", 2, Width.SHORT, "b", new IntegerRecommender(true))
294-
.define("c", Type.INT, Importance.HIGH, "docs", "group", 3, Width.SHORT, "c", new IntegerRecommender(true))
295-
.define("d", Type.INT, Importance.HIGH, "docs", "group", 4, Width.SHORT, "d", singletonList("b"), new IntegerRecommender(false));
293+
.define("a", Type.INT, Importance.HIGH, "docs", "group", 1, Width.SHORT, "a", Arrays.asList("b", "c"), new IntegerRecommender(false))
294+
.define("b", Type.INT, Importance.HIGH, "docs", "group", 2, Width.SHORT, "b", new IntegerRecommender(true))
295+
.define("c", Type.INT, Importance.HIGH, "docs", "group", 3, Width.SHORT, "c", new IntegerRecommender(true))
296+
.define("d", Type.INT, Importance.HIGH, "docs", "group", 4, Width.SHORT, "d", singletonList("b"), new IntegerRecommender(false));
296297

297298
Map<String, String> props = new HashMap<>();
298299
props.put("a", "1");
@@ -325,15 +326,15 @@ public void testValidateMissingConfigKey() {
325326
expected.put("d", configD);
326327

327328
ConfigDef def = new ConfigDef()
328-
.define("a", Type.INT, Importance.HIGH, "docs", "group", 1, Width.SHORT, "a", Arrays.asList("b", "c", "d"), new IntegerRecommender(false))
329-
.define("b", Type.INT, Importance.HIGH, "docs", "group", 2, Width.SHORT, "b", new IntegerRecommender(true))
330-
.define("c", Type.INT, Importance.HIGH, "docs", "group", 3, Width.SHORT, "c", new IntegerRecommender(true));
329+
.define("a", Type.INT, Importance.HIGH, "docs", "group", 1, Width.SHORT, "a", Arrays.asList("b", "c", "d"), new IntegerRecommender(false))
330+
.define("b", Type.INT, Importance.HIGH, "docs", "group", 2, Width.SHORT, "b", new IntegerRecommender(true))
331+
.define("c", Type.INT, Importance.HIGH, "docs", "group", 3, Width.SHORT, "c", new IntegerRecommender(true));
331332

332333
Map<String, String> props = new HashMap<>();
333334
props.put("a", "1");
334335

335336
List<ConfigValue> configs = def.validate(props);
336-
for (ConfigValue config: configs) {
337+
for (ConfigValue config : configs) {
337338
String name = config.name();
338339
ConfigValue expectedConfig = expected.get(name);
339340
assertEquals(expectedConfig, config);
@@ -352,7 +353,7 @@ public void testValidateCannotParse() {
352353
props.put("a", "non_integer");
353354

354355
List<ConfigValue> configs = def.validate(props);
355-
for (ConfigValue config: configs) {
356+
for (ConfigValue config : configs) {
356357
String name = config.name();
357358
ConfigValue expectedConfig = expected.get(name);
358359
assertEquals(expectedConfig, config);
@@ -505,32 +506,32 @@ public void toRst() {
505506

506507
final String expectedRst =
507508
"``opt2``\n" +
508-
" docs2\n" +
509-
"\n" +
510-
" * Type: int\n" +
511-
" * Importance: medium\n" +
512-
"\n" +
513-
"``opt1``\n" +
514-
" docs1\n" +
515-
"\n" +
516-
" * Type: string\n" +
517-
" * Default: a\n" +
518-
" * Valid Values: [a, b, c]\n" +
519-
" * Importance: high\n" +
520-
"\n" +
521-
"``opt3``\n" +
522-
" docs3\n" +
523-
"\n" +
524-
" * Type: list\n" +
525-
" * Default: a,b\n" +
526-
" * Importance: low\n" +
527-
"\n" +
528-
"``opt4``\n" +
529-
"\n" +
530-
" * Type: boolean\n" +
531-
" * Default: false\n" +
532-
" * Importance: low\n" +
533-
"\n";
509+
" docs2\n" +
510+
"\n" +
511+
" * Type: int\n" +
512+
" * Importance: medium\n" +
513+
"\n" +
514+
"``opt1``\n" +
515+
" docs1\n" +
516+
"\n" +
517+
" * Type: string\n" +
518+
" * Default: a\n" +
519+
" * Valid Values: [a, b, c]\n" +
520+
" * Importance: high\n" +
521+
"\n" +
522+
"``opt3``\n" +
523+
" docs3\n" +
524+
"\n" +
525+
" * Type: list\n" +
526+
" * Default: a,b\n" +
527+
" * Importance: low\n" +
528+
"\n" +
529+
"``opt4``\n" +
530+
"\n" +
531+
" * Type: boolean\n" +
532+
" * Default: false\n" +
533+
" * Importance: low\n" +
534+
"\n";
534535

535536
assertEquals(expectedRst, def.toRst());
536537
}
@@ -550,48 +551,48 @@ public void toEnrichedRst() {
550551

551552
final String expectedRst =
552553
"``poor.opt``\n" +
553-
" Doc doc doc doc.\n" +
554-
"\n" +
555-
" * Type: string\n" +
556-
" * Default: foo\n" +
557-
" * Importance: high\n" +
558-
"\n" +
559-
"Group One\n" +
560-
"^^^^^^^^^\n" +
561-
"\n" +
562-
"``opt1.of.group1``\n" +
563-
" Doc doc.\n" +
564-
"\n" +
565-
" * Type: string\n" +
566-
" * Default: a\n" +
567-
" * Valid Values: [a, b, c]\n" +
568-
" * Importance: high\n" +
569-
"\n" +
570-
"``opt2.of.group1``\n" +
571-
" Doc doc doc.\n" +
572-
"\n" +
573-
" * Type: int\n" +
574-
" * Importance: medium\n" +
575-
" * Dependents: ``some.option1``, ``some.option2``\n" +
576-
"\n" +
577-
"Group Two\n" +
578-
"^^^^^^^^^\n" +
579-
"\n" +
580-
"``opt1.of.group2``\n" +
581-
" Doc doc doc doc doc.\n" +
582-
"\n" +
583-
" * Type: boolean\n" +
584-
" * Default: false\n" +
585-
" * Importance: high\n" +
586-
" * Dependents: ``some.option``\n" +
587-
"\n" +
588-
"``opt2.of.group2``\n" +
589-
" Doc doc doc doc.\n" +
590-
"\n" +
591-
" * Type: boolean\n" +
592-
" * Default: false\n" +
593-
" * Importance: high\n" +
594-
"\n";
554+
" Doc doc doc doc.\n" +
555+
"\n" +
556+
" * Type: string\n" +
557+
" * Default: foo\n" +
558+
" * Importance: high\n" +
559+
"\n" +
560+
"Group One\n" +
561+
"^^^^^^^^^\n" +
562+
"\n" +
563+
"``opt1.of.group1``\n" +
564+
" Doc doc.\n" +
565+
"\n" +
566+
" * Type: string\n" +
567+
" * Default: a\n" +
568+
" * Valid Values: [a, b, c]\n" +
569+
" * Importance: high\n" +
570+
"\n" +
571+
"``opt2.of.group1``\n" +
572+
" Doc doc doc.\n" +
573+
"\n" +
574+
" * Type: int\n" +
575+
" * Importance: medium\n" +
576+
" * Dependents: ``some.option1``, ``some.option2``\n" +
577+
"\n" +
578+
"Group Two\n" +
579+
"^^^^^^^^^\n" +
580+
"\n" +
581+
"``opt1.of.group2``\n" +
582+
" Doc doc doc doc doc.\n" +
583+
"\n" +
584+
" * Type: boolean\n" +
585+
" * Default: false\n" +
586+
" * Importance: high\n" +
587+
" * Dependents: ``some.option``\n" +
588+
"\n" +
589+
"``opt2.of.group2``\n" +
590+
" Doc doc doc doc.\n" +
591+
"\n" +
592+
" * Type: boolean\n" +
593+
" * Default: false\n" +
594+
" * Importance: high\n" +
595+
"\n";
595596

596597
assertEquals(expectedRst, def.toEnrichedRst());
597598
}
@@ -729,34 +730,34 @@ public void testNiceTimeUnits() {
729730
@Test
730731
public void testThrowsExceptionWhenListSizeExceedsLimit() {
731732
final ConfigException exception = assertThrows(ConfigException.class, () -> new ConfigDef().define("lst",
732-
Type.LIST,
733-
asList("a", "b"),
734-
ListSize.atMostOfSize(1),
735-
Importance.HIGH,
736-
"lst doc"));
733+
Type.LIST,
734+
asList("a", "b"),
735+
ListSize.atMostOfSize(1),
736+
Importance.HIGH,
737+
"lst doc"));
737738
assertEquals("Invalid value [a, b] for configuration lst: exceeds maximum list size of [1].",
738-
exception.getMessage());
739+
exception.getMessage());
739740
}
740741

741742
@Test
742743
public void testNoExceptionIsThrownWhenListSizeEqualsTheLimit() {
743744
final List<String> lst = asList("a", "b", "c");
744745
assertDoesNotThrow(() -> new ConfigDef().define("lst",
745-
Type.LIST,
746-
lst,
747-
ListSize.atMostOfSize(lst.size()),
748-
Importance.HIGH,
749-
"lst doc"));
746+
Type.LIST,
747+
lst,
748+
ListSize.atMostOfSize(lst.size()),
749+
Importance.HIGH,
750+
"lst doc"));
750751
}
751752

752753
@Test
753754
public void testNoExceptionIsThrownWhenListSizeIsBelowTheLimit() {
754755
assertDoesNotThrow(() -> new ConfigDef().define("lst",
755-
Type.LIST,
756-
asList("a", "b"),
757-
ListSize.atMostOfSize(3),
758-
Importance.HIGH,
759-
"lst doc"));
756+
Type.LIST,
757+
asList("a", "b"),
758+
ListSize.atMostOfSize(3),
759+
Importance.HIGH,
760+
"lst doc"));
760761
}
761762

762763
@Test

0 commit comments

Comments
 (0)