You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/05/16 19:34:19 UTC

[GitHub] [pulsar] jerrypeng commented on a change in pull request #6972: Add Annotations for config validation checking

jerrypeng commented on a change in pull request #6972:
URL: https://github.com/apache/pulsar/pull/6972#discussion_r426183847



##########
File path: pulsar-common/src/test/java/org/apache/pulsar/common/validator/ConfigValidationTest.java
##########
@@ -0,0 +1,148 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.common.validator;
+
+import org.testng.annotations.Test;
+
+import java.util.*;
+import static org.testng.Assert.*;
+
+public class ConfigValidationTest {
+
+    private final List<String> testStringList = Arrays.asList(new String[]{"foo", "bar"});
+    private final List<Integer> testIntegerList = Arrays.asList(new Integer[]{0, 1});
+    private final Map<String, Integer> testStringIntegerMap = new HashMap<String, Integer>() {
+        {
+            put("one", 1);
+            put("two", 2);
+        }
+    };
+    private final Map<String, String> testStringStringMap = new HashMap<String, String>() {
+        {
+            put("one", "one");
+            put("two", "two");
+        }
+    };
+    private final String topic = "persistent://public/default/topic";
+
+    public static class TestValidator extends Validator {
+        @Override
+        public void validateField(String name, Object o) {
+            if (o instanceof String) {
+                String value = (String)o;
+                if (!value.startsWith("ABCDE")) {
+                    throw new IllegalArgumentException(String.format("Field %s does not start with ABCDE", name));
+                }
+            } else {
+                throw new IllegalArgumentException(String.format("Field %s is not a string", name));
+            }
+        }
+    }
+
+    class TestConfig {

Review comment:
       I don't fee strongly about it either way.   However, if we feel we can simplify the naming of annotations and still be intuitive to the end user, we should.  The current annotations are borrowed from Storm that I created a while ago:
   
   https://github.com/apache/storm/blob/master/storm-client/src/jvm/org/apache/storm/validation/ConfigValidationAnnotations.java
   
   Others have name annotations in a more simplified way:
   
   https://www.baeldung.com/javax-validation
   
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org