sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-1927: Sqoop2: Move CSVURIValidator into validators package
Date Mon, 05 Jan 2015 07:03:19 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 fdc40d39c -> d56d6417f


SQOOP-1927: Sqoop2: Move CSVURIValidator into validators package

(Abraham Elmahrek via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/d56d6417
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/d56d6417
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/d56d6417

Branch: refs/heads/sqoop2
Commit: d56d6417f4cb908c0cf67d404b20f55abd0061f7
Parents: fdc40d3
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Jan 5 08:02:47 2015 +0100
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Jan 5 08:02:47 2015 +0100

----------------------------------------------------------------------
 .../validation/validators/CSVURIValidator.java  | 55 +++++++++++++
 .../validators/TestCSVURIValidator.java         | 68 ++++++++++++++++
 .../kafka/configuration/LinkConfig.java         | 20 +----
 .../connector/kafka/TestConfigValidator.java    | 59 --------------
 .../connector/kafka/TestConfiguration.java      | 85 ++++++++++++++++++++
 5 files changed, 209 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/d56d6417/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
b/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
new file mode 100644
index 0000000..a82a238
--- /dev/null
+++ b/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
@@ -0,0 +1,55 @@
+/**
+ * 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.sqoop.validation.validators;
+
+import org.apache.sqoop.validation.Status;
+
+/**
+ * Validate a string takes on the form: host:port,host:port,...
+ */
+public class CSVURIValidator extends AbstractValidator<String> {
+
+  // validate that given string is a comma-separated list of host:port
+  @Override
+  public void validate(String str) {
+    if(str != null && str != "") {
+      String[] pairs = str.split("\\s*,\\s*");
+      for (String pair: pairs) {
+        String[] parts = pair.split("\\s*:\\s*");
+        if (parts.length != 2) {
+          addMessage(Status.ERROR,"can't parse into host:port pairs");
+        } else {
+          String[] rightParts = parts[1].split("/");
+
+          try {
+            int port = Integer.parseInt(rightParts[0]);
+            if (port < 0) {
+              addMessage(Status.ERROR, "Can't parse port less than 0");
+            } else if (port > 65535) {
+              addMessage(Status.ERROR, "Can't parse port greater than 65535");
+            }
+          } catch(NumberFormatException e) {
+            addMessage(Status.ERROR, "Can't parse port");
+          }
+        }
+      }
+    } else {
+      addMessage(Status.ERROR, "Can't be null nor empty");
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d56d6417/common/src/test/java/org/apache/sqoop/validation/validators/TestCSVURIValidator.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/validation/validators/TestCSVURIValidator.java
b/common/src/test/java/org/apache/sqoop/validation/validators/TestCSVURIValidator.java
new file mode 100644
index 0000000..dfb6fdd
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/validation/validators/TestCSVURIValidator.java
@@ -0,0 +1,68 @@
+/**
+ * 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.sqoop.validation.validators;
+
+import org.apache.sqoop.validation.Status;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ */
+public class TestCSVURIValidator {
+
+  AbstractValidator validator = new CSVURIValidator();
+
+  @Test
+  public void test() {
+    assertEquals(0, validator.getMessages().size());
+
+    validator.validate("host1:1,host2:2");
+    assertEquals(Status.OK, validator.getStatus());
+    assertEquals(0, validator.getMessages().size());
+  }
+
+  @Test
+  public void testBad() {
+    assertEquals(0, validator.getMessages().size());
+
+    validator.validate("host1");
+    assertEquals(Status.ERROR, validator.getStatus());
+    assertEquals(1, validator.getMessages().size());
+
+    validator.reset();
+    validator.validate("");
+    assertEquals(Status.ERROR, validator.getStatus());
+    assertEquals(1, validator.getMessages().size());
+
+    validator.reset();
+    validator.validate(null);
+    assertEquals(Status.ERROR, validator.getStatus());
+    assertEquals(1, validator.getMessages().size());
+
+    validator.reset();
+    validator.validate("host1:65536");
+    assertEquals(Status.ERROR, validator.getStatus());
+    assertEquals(1, validator.getMessages().size());
+
+    validator.reset();
+    validator.validate("host1:-1");
+    assertEquals(Status.ERROR, validator.getStatus());
+    assertEquals(1, validator.getMessages().size());
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d56d6417/connector/connector-kafka/src/main/java/org/apache/sqoop/connector/kafka/configuration/LinkConfig.java
----------------------------------------------------------------------
diff --git a/connector/connector-kafka/src/main/java/org/apache/sqoop/connector/kafka/configuration/LinkConfig.java
b/connector/connector-kafka/src/main/java/org/apache/sqoop/connector/kafka/configuration/LinkConfig.java
index 98112e7..256ae64 100644
--- a/connector/connector-kafka/src/main/java/org/apache/sqoop/connector/kafka/configuration/LinkConfig.java
+++ b/connector/connector-kafka/src/main/java/org/apache/sqoop/connector/kafka/configuration/LinkConfig.java
@@ -22,28 +22,10 @@ import org.apache.sqoop.model.Input;
 import org.apache.sqoop.model.Validator;
 import org.apache.sqoop.validation.Status;
 import org.apache.sqoop.validation.validators.AbstractValidator;
+import org.apache.sqoop.validation.validators.CSVURIValidator;
 
 @ConfigClass
 public class LinkConfig {
   @Input(size=1024, validators = { @Validator(CSVURIValidator.class) }) public String brokerList;
   @Input(size=255, validators = { @Validator(CSVURIValidator.class) })  public String zookeeperConnect;
-
-  public static class CSVURIValidator extends AbstractValidator<String> {
-
-    // validate that given string is a comma-separated list of host:port
-    @Override
-    public void validate(String str) {
-      if(str == null || str !="") {
-        String[] pairs = str.split("\\s*,\\s*");
-        for (String pair: pairs) {
-          String[] parts = pair.split("\\s*:\\s*");
-          if (parts.length == 1) {
-            addMessage(Status.ERROR,"can't parse into host:port pairs");
-          }
-        }
-      } else {
-        addMessage(Status.ERROR, "Can't be null nor empty");
-      }
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d56d6417/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfigValidator.java
----------------------------------------------------------------------
diff --git a/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfigValidator.java
b/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfigValidator.java
deleted file mode 100644
index b61d979..0000000
--- a/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfigValidator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.sqoop.connector.kafka;
-
-import org.apache.sqoop.connector.kafka.configuration.LinkConfig;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class TestConfigValidator {
-  @Test
-  public void testValidURI() {
-    String[] URI = {
-            "broker1:9092",
-            "broker1:9092,broker2:9092",
-            "zk1:2181/kafka",
-            "zk1:2181,zk2:2181/kafka"
-    };
-
-    for (String uri: URI) {
-      LinkConfig.CSVURIValidator validator = new LinkConfig.CSVURIValidator();
-      validator.validate(uri);
-      assertTrue(validator.getStatus().canProceed());
-    }
-  }
-
-  @Test
-  public void testInvalidURI() {
-    String[] URI = {
-            "",
-            "broker",
-            "broker1:9092,broker"
-    };
-    for (String uri: URI) {
-      LinkConfig.CSVURIValidator validator = new LinkConfig.CSVURIValidator();
-      validator.validate(uri);
-      assertFalse(validator.getStatus().canProceed());
-    }
-
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d56d6417/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfiguration.java
b/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfiguration.java
new file mode 100644
index 0000000..0aca80d
--- /dev/null
+++ b/connector/connector-kafka/src/test/java/org/apache/sqoop/connector/kafka/TestConfiguration.java
@@ -0,0 +1,85 @@
+/**
+ * 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.sqoop.connector.kafka;
+
+import org.apache.sqoop.connector.kafka.configuration.LinkConfiguration;
+import org.apache.sqoop.validation.ConfigValidationResult;
+import org.apache.sqoop.validation.ConfigValidationRunner;
+import org.apache.sqoop.validation.Status;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestConfiguration {
+  @Test
+  public void testValidURI() {
+    String[] brokerList = {
+            "broker1:9092",
+            "broker1:9092,broker2:9092"
+    };
+
+    String[] zkList = {
+        "zk1:2181/kafka",
+        "zk1:2181,zk2:2181/kafka"
+    };
+
+    ConfigValidationRunner runner = new ConfigValidationRunner();
+    LinkConfiguration linkConfiguration;
+    ConfigValidationResult result;
+
+    for (String brokerURI : brokerList) {
+      for (String zkURI : zkList) {
+        linkConfiguration = new LinkConfiguration();
+        linkConfiguration.linkConfig.brokerList = brokerURI;
+        linkConfiguration.linkConfig.zookeeperConnect = zkURI;
+
+        result = runner.validate(linkConfiguration);
+        assertEquals(Status.OK, result.getStatus());
+      }
+    }
+  }
+
+  @Test
+  public void testInvalidURI() {
+    String[] brokerList = {
+        "",
+        "broker",
+        "broker1:9092,broker"
+    };
+
+    String[] zkList = {
+        "zk1:2181/kafka",
+        "zk1:2181,zk2:2181/kafka"
+    };
+
+    ConfigValidationRunner runner = new ConfigValidationRunner();
+    LinkConfiguration linkConfiguration;
+    ConfigValidationResult result;
+
+    for (String brokerURI : brokerList) {
+      for (String zkURI : zkList) {
+        linkConfiguration = new LinkConfiguration();
+        linkConfiguration.linkConfig.brokerList = brokerURI;
+        linkConfiguration.linkConfig.zookeeperConnect = zkURI;
+
+        result = runner.validate(linkConfiguration);
+        assertEquals(Status.ERROR, result.getStatus());
+      }
+    }
+  }
+}


Mime
View raw message