Repository: hadoop
Updated Branches:
  refs/heads/YARN-3409 6854f092b -> 5e64e62de (forced update)


HDDS-425. Move unit test of the genconf tool to hadoop-ozone/tools module. 
Contributed by Dinesh Chitlangia.


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

Branch: refs/heads/YARN-3409
Commit: 901156716990fa00b44515dafcb9916c20556a0e
Parents: 76d0365
Author: Márton Elek <e...@apache.org>
Authored: Wed Sep 12 11:11:12 2018 +0200
Committer: Márton Elek <e...@apache.org>
Committed: Wed Sep 12 11:11:12 2018 +0200

----------------------------------------------------------------------
 ...TestGenerateOzoneRequiredConfigurations.java | 152 -------------------
 ...TestGenerateOzoneRequiredConfigurations.java | 152 +++++++++++++++++++
 .../hadoop/ozone/genconf/package-info.java      |  22 +++
 3 files changed, 174 insertions(+), 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/90115671/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
deleted file mode 100644
index 8c75ebb..0000000
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
+++ /dev/null
@@ -1,152 +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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.ozone.genconf;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.hadoop.test.GenericTestUtils;
-import org.hamcrest.CoreMatchers;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-
-
-/**
- * Tests GenerateOzoneRequiredConfigurations.
- */
-public class TestGenerateOzoneRequiredConfigurations {
-  private static File outputBaseDir;
-  /**
-   * Creates output directory which will be used by the test-cases.
-   * If a test-case needs a separate directory, it has to create a random
-   * directory inside {@code outputBaseDir}.
-   *
-   * @throws Exception In case of exception while creating output directory.
-   */
-  @BeforeClass
-  public static void init() throws Exception {
-    outputBaseDir = GenericTestUtils.getTestDir();
-    FileUtils.forceMkdir(outputBaseDir);
-  }
-
-  /**
-   * Cleans up the output base directory.
-   */
-  @AfterClass
-  public static void cleanup() throws IOException {
-    FileUtils.deleteDirectory(outputBaseDir);
-  }
-
-  /**
-   * Tests a valid path and generates ozone-site.xml by calling
-   * {@code GenerateOzoneRequiredConfigurations#generateConfigurations}.
-   *
-   * @throws Exception
-   */
-  @Test
-  public void testGenerateConfigurations() throws Exception {
-    File tempPath = getRandomTempDir();
-    String[] args = new String[]{"-output", tempPath.getAbsolutePath()};
-
-    Assert.assertEquals("Path is valid",
-        true, GenerateOzoneRequiredConfigurations.isValidPath(args[1]));
-
-    Assert.assertEquals("Permission is valid",
-        true, GenerateOzoneRequiredConfigurations.canWrite(args[1]));
-
-    Assert.assertEquals("Config file generated",
-        0, 
GenerateOzoneRequiredConfigurations.generateConfigurations(args[1]));
-  }
-
-  /**
-   * Tests ozone-site.xml generation by calling
-   * {@code GenerateOzoneRequiredConfigurations#main}.
-   *
-   * @throws Exception
-   */
-  @Test
-  public void testGenerateConfigurationsThroughMainMethod() throws Exception {
-    File tempPath = getRandomTempDir();
-    String[] args = new String[]{"-output", tempPath.getAbsolutePath()};
-    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
-    PrintStream oldStream = System.out;
-    try (PrintStream ps = new PrintStream(outContent)) {
-      System.setOut(ps);
-      GenerateOzoneRequiredConfigurations.main(args);
-      Assert.assertThat(outContent.toString(), CoreMatchers.containsString(
-          "ozone-site.xml has been generated at"));
-      System.setOut(oldStream);
-    }
-  }
-
-  /**
-   * Test to avoid generating ozone-site.xml when invalid permission.
-   * @throws Exception
-   */
-  @Test
-  public void generateConfigurationsFailure() throws Exception {
-    File tempPath = getRandomTempDir();
-    tempPath.setReadOnly();
-    String[] args = new String[]{"-output", tempPath.getAbsolutePath()};
-    GenerateOzoneRequiredConfigurations.main(args);
-
-    Assert.assertEquals("Path is valid",
-        true, GenerateOzoneRequiredConfigurations.isValidPath(args[1]));
-
-    Assert.assertEquals("Invalid permission",
-        false, GenerateOzoneRequiredConfigurations.canWrite(args[1]));
-
-    Assert.assertEquals("Config file not generated",
-        1, 
GenerateOzoneRequiredConfigurations.generateConfigurations(args[1]));
-    tempPath.setWritable(true);
-  }
-
-  /**
-   * Test to avoid generating ozone-site.xml when invalid permission.
-   * @throws Exception
-   */
-  @Test
-  public void generateConfigurationsFailureForInvalidPath() throws Exception {
-    File tempPath = getRandomTempDir();
-    tempPath.setReadOnly();
-    String[] args = new String[]{"-output",
-        tempPath.getAbsolutePath() + "/ozone-site.xml"};
-    GenerateOzoneRequiredConfigurations.main(args);
-
-    Assert.assertEquals("Path is invalid", false,
-        GenerateOzoneRequiredConfigurations.isValidPath(args[1]));
-
-    Assert.assertEquals("Config file not generated", 1,
-        GenerateOzoneRequiredConfigurations.generateConfigurations(args[1]));
-    tempPath.setWritable(true);
-  }
-
-  private File getRandomTempDir() throws IOException {
-    File tempDir = new File(outputBaseDir,
-        RandomStringUtils.randomAlphanumeric(5));
-    FileUtils.forceMkdir(tempDir);
-    return tempDir;
-  }
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/90115671/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
new file mode 100644
index 0000000..8c75ebb
--- /dev/null
+++ 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
@@ -0,0 +1,152 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.genconf;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.hamcrest.CoreMatchers;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+
+
+/**
+ * Tests GenerateOzoneRequiredConfigurations.
+ */
+public class TestGenerateOzoneRequiredConfigurations {
+  private static File outputBaseDir;
+  /**
+   * Creates output directory which will be used by the test-cases.
+   * If a test-case needs a separate directory, it has to create a random
+   * directory inside {@code outputBaseDir}.
+   *
+   * @throws Exception In case of exception while creating output directory.
+   */
+  @BeforeClass
+  public static void init() throws Exception {
+    outputBaseDir = GenericTestUtils.getTestDir();
+    FileUtils.forceMkdir(outputBaseDir);
+  }
+
+  /**
+   * Cleans up the output base directory.
+   */
+  @AfterClass
+  public static void cleanup() throws IOException {
+    FileUtils.deleteDirectory(outputBaseDir);
+  }
+
+  /**
+   * Tests a valid path and generates ozone-site.xml by calling
+   * {@code GenerateOzoneRequiredConfigurations#generateConfigurations}.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testGenerateConfigurations() throws Exception {
+    File tempPath = getRandomTempDir();
+    String[] args = new String[]{"-output", tempPath.getAbsolutePath()};
+
+    Assert.assertEquals("Path is valid",
+        true, GenerateOzoneRequiredConfigurations.isValidPath(args[1]));
+
+    Assert.assertEquals("Permission is valid",
+        true, GenerateOzoneRequiredConfigurations.canWrite(args[1]));
+
+    Assert.assertEquals("Config file generated",
+        0, 
GenerateOzoneRequiredConfigurations.generateConfigurations(args[1]));
+  }
+
+  /**
+   * Tests ozone-site.xml generation by calling
+   * {@code GenerateOzoneRequiredConfigurations#main}.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testGenerateConfigurationsThroughMainMethod() throws Exception {
+    File tempPath = getRandomTempDir();
+    String[] args = new String[]{"-output", tempPath.getAbsolutePath()};
+    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+    PrintStream oldStream = System.out;
+    try (PrintStream ps = new PrintStream(outContent)) {
+      System.setOut(ps);
+      GenerateOzoneRequiredConfigurations.main(args);
+      Assert.assertThat(outContent.toString(), CoreMatchers.containsString(
+          "ozone-site.xml has been generated at"));
+      System.setOut(oldStream);
+    }
+  }
+
+  /**
+   * Test to avoid generating ozone-site.xml when invalid permission.
+   * @throws Exception
+   */
+  @Test
+  public void generateConfigurationsFailure() throws Exception {
+    File tempPath = getRandomTempDir();
+    tempPath.setReadOnly();
+    String[] args = new String[]{"-output", tempPath.getAbsolutePath()};
+    GenerateOzoneRequiredConfigurations.main(args);
+
+    Assert.assertEquals("Path is valid",
+        true, GenerateOzoneRequiredConfigurations.isValidPath(args[1]));
+
+    Assert.assertEquals("Invalid permission",
+        false, GenerateOzoneRequiredConfigurations.canWrite(args[1]));
+
+    Assert.assertEquals("Config file not generated",
+        1, 
GenerateOzoneRequiredConfigurations.generateConfigurations(args[1]));
+    tempPath.setWritable(true);
+  }
+
+  /**
+   * Test to avoid generating ozone-site.xml when invalid permission.
+   * @throws Exception
+   */
+  @Test
+  public void generateConfigurationsFailureForInvalidPath() throws Exception {
+    File tempPath = getRandomTempDir();
+    tempPath.setReadOnly();
+    String[] args = new String[]{"-output",
+        tempPath.getAbsolutePath() + "/ozone-site.xml"};
+    GenerateOzoneRequiredConfigurations.main(args);
+
+    Assert.assertEquals("Path is invalid", false,
+        GenerateOzoneRequiredConfigurations.isValidPath(args[1]));
+
+    Assert.assertEquals("Config file not generated", 1,
+        GenerateOzoneRequiredConfigurations.generateConfigurations(args[1]));
+    tempPath.setWritable(true);
+  }
+
+  private File getRandomTempDir() throws IOException {
+    File tempDir = new File(outputBaseDir,
+        RandomStringUtils.randomAlphanumeric(5));
+    FileUtils.forceMkdir(tempDir);
+    return tempDir;
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/90115671/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/package-info.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/package-info.java
 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/package-info.java
new file mode 100644
index 0000000..8f58a82
--- /dev/null
+++ 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.genconf;
+/**
+ * Tests for ozone genconf tool
+ */


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to