You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ab...@apache.org on 2015/03/16 18:46:25 UTC
sqoop git commit: SQOOP-2202: Sqoop2: Add validator to check
existence of local directory on Sqoop 2 server
Repository: sqoop
Updated Branches:
refs/heads/sqoop2 e6519c76c -> 4fb5d6a92
SQOOP-2202: Sqoop2: Add validator to check existence of local directory on Sqoop 2 server
(Jarek Jarcec Cecho via Abraham Elmahrek)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/4fb5d6a9
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/4fb5d6a9
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/4fb5d6a9
Branch: refs/heads/sqoop2
Commit: 4fb5d6a920803dc0fe30d760beaf89d593901fa7
Parents: e6519c7
Author: Abraham Elmahrek <ab...@apache.org>
Authored: Mon Mar 16 10:45:40 2015 -0700
Committer: Abraham Elmahrek <ab...@apache.org>
Committed: Mon Mar 16 10:45:40 2015 -0700
----------------------------------------------------------------------
.../validators/DirectoryExistsValidator.java | 42 ++++++++++++
.../TestDirectoryExistsValidator.java | 67 ++++++++++++++++++++
2 files changed, 109 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/4fb5d6a9/common/src/main/java/org/apache/sqoop/validation/validators/DirectoryExistsValidator.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/validation/validators/DirectoryExistsValidator.java b/common/src/main/java/org/apache/sqoop/validation/validators/DirectoryExistsValidator.java
new file mode 100644
index 0000000..d81e6b0
--- /dev/null
+++ b/common/src/main/java/org/apache/sqoop/validation/validators/DirectoryExistsValidator.java
@@ -0,0 +1,42 @@
+/**
+ * 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 java.io.File;
+
+/**
+ * Verify that given directory exist on the Sqoop 2 server machine.
+ */
+public class DirectoryExistsValidator extends AbstractValidator<String> {
+ @Override
+ public void validate(String filePath) {
+ File file = new File(filePath);
+
+ if(!file.exists()) {
+ addMessage(Status.ERROR, "Directory doesn't exists on Sqoop 2 server machine");
+ return;
+ }
+
+ if(!file.isDirectory()) {
+ addMessage(Status.ERROR, "Path is not a valid directory");
+ return;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/4fb5d6a9/common/src/test/java/org/apache/sqoop/validation/validators/TestDirectoryExistsValidator.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/validation/validators/TestDirectoryExistsValidator.java b/common/src/test/java/org/apache/sqoop/validation/validators/TestDirectoryExistsValidator.java
new file mode 100644
index 0000000..e6c4ec3
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/validation/validators/TestDirectoryExistsValidator.java
@@ -0,0 +1,67 @@
+/**
+ * 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 com.google.common.io.Files;
+import org.apache.sqoop.validation.Status;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.File;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ */
+public class TestDirectoryExistsValidator {
+
+ AbstractValidator<String> validator = new DirectoryExistsValidator();
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() {
+ validator.reset();
+ assertEquals(0, validator.getMessages().size());
+ }
+
+ @Test
+ public void testExistingDirectory() {
+ File tmpDir = Files.createTempDir();
+ tmpDir.deleteOnExit();
+
+ validator.validate(tmpDir.getAbsolutePath());
+ assertEquals(Status.OK, validator.getStatus());
+ }
+
+ @Test
+ public void testFileInsteadOfDirectory() throws Exception {
+ File tmpDir = File.createTempFile("ABCDEFG", "12345");
+ tmpDir.createNewFile();
+ tmpDir.deleteOnExit();
+
+ validator.validate(tmpDir.getAbsolutePath());
+ assertEquals(Status.ERROR, validator.getStatus());
+ assertEquals(1, validator.getMessages().size());
+ }
+
+ @Test
+ public void testNonExistingPath() throws Exception {
+ validator.validate("/X/Y/Z/This/Can/Not/Exists/Right/Question-mark");
+ assertEquals(Status.ERROR, validator.getStatus());
+ assertEquals(1, validator.getMessages().size());
+ }
+}