hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From waltersu4...@apache.org
Subject hadoop git commit: HDFS-9410. Some tests should always reset sysout and syserr. Contributed by Xiao Chen.
Date Fri, 13 Nov 2015 06:31:26 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 7ff280fca -> cccf88480


HDFS-9410. Some tests should always reset sysout and syserr. Contributed by Xiao Chen.


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

Branch: refs/heads/trunk
Commit: cccf88480b0df71f15fb36e9693d492c9e16c685
Parents: 7ff280f
Author: Walter Su <waltersu4549@apache.org>
Authored: Fri Nov 13 14:21:14 2015 +0800
Committer: Walter Su <waltersu4549@apache.org>
Committed: Fri Nov 13 14:26:43 2015 +0800

----------------------------------------------------------------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt     |  3 +
 .../org/apache/hadoop/hdfs/TestDFSShell.java    | 69 +++++++++++---------
 .../hadoop/hdfs/TestFsShellPermission.java      | 12 ++--
 .../java/org/apache/hadoop/hdfs/TestQuota.java  | 19 ++++--
 .../hdfs/server/namenode/TestClusterId.java     | 36 +++++-----
 .../namenode/TestMetadataVersionOutput.java     | 25 +++----
 .../namenode/snapshot/TestSnapshotDeletion.java | 45 +++++++------
 .../namenode/snapshot/TestSnapshotRename.java   | 45 +++++++------
 .../hadoop/hdfs/tools/TestDFSAdminWithHA.java   | 17 ++---
 .../org/apache/hadoop/tools/TestJMXGet.java     | 17 +++--
 .../java/org/apache/hadoop/tools/TestTools.java |  5 ++
 .../apache/hadoop/tracing/TestTraceAdmin.java   |  9 ++-
 12 files changed, 179 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index 1b98d65..c91522b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -2299,6 +2299,9 @@ Release 2.8.0 - UNRELEASED
     HDFS-9396. Total files and directories on jmx and web UI on standby is
     uninitialized. (kihwal)
 
+    HDFS-9410. Some tests should always reset sysout and syserr.
+    (Xiao Chen via waltersu4549)
+
 Release 2.7.3 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
index c04e355..0753ab8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
@@ -955,9 +955,9 @@ public class TestDFSShell {
       assertEquals(dirs, in.nextLong());
       assertEquals(files, in.nextLong());
     } finally {
+      System.setOut(oldOut);
       if (in!=null) in.close();
       IOUtils.closeStream(out);
-      System.setOut(oldOut);
       System.out.println("results:\n" + results);
     }
   }
@@ -1720,9 +1720,9 @@ public class TestDFSShell {
       assertEquals(returnvalue, shell.run(new String[]{"-lsr", root}));
       results = bytes.toString();
     } finally {
-      IOUtils.closeStream(out);
       System.setOut(oldOut);
       System.setErr(oldErr);
+      IOUtils.closeStream(out);
     }
     System.out.println("results:\n" + results);
     return results;
@@ -3179,15 +3179,16 @@ public class TestDFSShell {
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream ps = new PrintStream(baos);
     System.setErr(ps);
+    try {
+      runCmd(shell, "-ls", "/.reserved");
+      assertEquals(0, baos.toString().length());
 
-    runCmd(shell, "-ls", "/.reserved");
-    assertEquals(0, baos.toString().length());
-
-    runCmd(shell, "-ls", "/.reserved/raw/.reserved");
-    assertTrue(baos.toString().contains("No such file or directory"));
-
-    System.setErr(syserr);
-    cluster.shutdown();
+      runCmd(shell, "-ls", "/.reserved/raw/.reserved");
+      assertTrue(baos.toString().contains("No such file or directory"));
+    } finally {
+      System.setErr(syserr);
+      cluster.shutdown();
+    }
   }
 
   @Test (timeout = 30000)
@@ -3253,13 +3254,15 @@ public class TestDFSShell {
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream ps = new PrintStream(baos);
     System.setErr(ps);
-
-    FsShell shell = new FsShell();
-    shell.setConf(conf);
-    runCmd(shell, "-cp", src.toString(), "/.reserved");
-    assertTrue(baos.toString().contains("Invalid path name /.reserved"));
-    System.setErr(syserr);
-    cluster.shutdown();
+    try {
+      FsShell shell = new FsShell();
+      shell.setConf(conf);
+      runCmd(shell, "-cp", src.toString(), "/.reserved");
+      assertTrue(baos.toString().contains("Invalid path name /.reserved"));
+    } finally {
+      System.setErr(syserr);
+      cluster.shutdown();
+    }
   }
 
   @Test (timeout = 30000)
@@ -3274,13 +3277,15 @@ public class TestDFSShell {
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream ps = new PrintStream(baos);
     System.setErr(ps);
-
-    FsShell shell = new FsShell();
-    shell.setConf(conf);
-    runCmd(shell, "-chmod", "777", "/.reserved");
-    assertTrue(baos.toString().contains("Invalid path name /.reserved"));
-    System.setErr(syserr);
-    cluster.shutdown();
+    try {
+      FsShell shell = new FsShell();
+      shell.setConf(conf);
+      runCmd(shell, "-chmod", "777", "/.reserved");
+      assertTrue(baos.toString().contains("Invalid path name /.reserved"));
+    } finally {
+      System.setErr(syserr);
+      cluster.shutdown();
+    }
   }
 
   @Test (timeout = 30000)
@@ -3295,13 +3300,15 @@ public class TestDFSShell {
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream ps = new PrintStream(baos);
     System.setErr(ps);
-
-    FsShell shell = new FsShell();
-    shell.setConf(conf);
-    runCmd(shell, "-chown", "user1", "/.reserved");
-    assertTrue(baos.toString().contains("Invalid path name /.reserved"));
-    System.setErr(syserr);
-    cluster.shutdown();
+    try {
+      FsShell shell = new FsShell();
+      shell.setConf(conf);
+      runCmd(shell, "-chown", "user1", "/.reserved");
+      assertTrue(baos.toString().contains("Invalid path name /.reserved"));
+    } finally {
+      System.setErr(syserr);
+      cluster.shutdown();
+    }
   }
 
   @Test (timeout = 30000)

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFsShellPermission.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFsShellPermission.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFsShellPermission.java
index ddb8fd0..cc456b2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFsShellPermission.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFsShellPermission.java
@@ -97,10 +97,14 @@ public class TestFsShellPermission {
     ByteArrayOutputStream baout = new ByteArrayOutputStream();
     PrintStream out = new PrintStream(baout, true);
     PrintStream old = System.out;
-    System.setOut(out);
-    int ret = shell.run(args);
-    out.close();
-    System.setOut(old);
+    int ret;
+    try {
+      System.setOut(out);
+      ret = shell.run(args);
+      out.close();
+    } finally {
+      System.setOut(old);
+    }
     return String.valueOf(ret);
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
index 16ab77d..961ae0e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
@@ -1054,13 +1054,18 @@ public class TestQuota {
     conf.set(FS_DEFAULT_NAME_KEY, "hdfs://127.0.0.1:8020");
     DFSAdmin admin = new DFSAdmin(conf);
     ByteArrayOutputStream err = new ByteArrayOutputStream();
-    System.setErr(new PrintStream(err));
-    String[] args = { "-setSpaceQuota", "100", "-storageType", "COLD",
-        "/testDir" };
-    admin.run(args);
-    String errOutput = new String(err.toByteArray(), Charsets.UTF_8);
-    assertTrue(errOutput.contains(StorageType.getTypesSupportingQuota()
-        .toString()));
+    PrintStream oldErr = System.err;
+    try {
+      System.setErr(new PrintStream(err));
+      String[] args =
+          { "-setSpaceQuota", "100", "-storageType", "COLD", "/testDir" };
+      admin.run(args);
+      String errOutput = new String(err.toByteArray(), Charsets.UTF_8);
+      assertTrue(
+          errOutput.contains(StorageType.getTypesSupportingQuota().toString()));
+    } finally {
+      System.setErr(oldErr);
+    }
   }
 
    /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
index 28ecd10..fa3399b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
@@ -232,12 +232,14 @@ public class TestClusterId {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream stdErr = new PrintStream(baos);
     System.setErr(stdErr);
+    try {
+      NameNode.createNameNode(argv, config);
 
-    NameNode.createNameNode(argv, config);
-
-    // Check if usage is printed
-    assertTrue(baos.toString("UTF-8").contains("Usage: hdfs namenode"));
-    System.setErr(origErr);
+      // Check if usage is printed
+      assertTrue(baos.toString("UTF-8").contains("Usage: hdfs namenode"));
+    } finally {
+      System.setErr(origErr);
+    }
 
     // check if the version file does not exists.
     File version = new File(hdfsDir, "current/VERSION");
@@ -258,12 +260,14 @@ public class TestClusterId {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream stdErr = new PrintStream(baos);
     System.setErr(stdErr);
+    try {
+      NameNode.createNameNode(argv, config);
 
-    NameNode.createNameNode(argv, config);
-
-    // Check if usage is printed
-    assertTrue(baos.toString("UTF-8").contains("Usage: hdfs namenode"));
-    System.setErr(origErr);
+      // Check if usage is printed
+      assertTrue(baos.toString("UTF-8").contains("Usage: hdfs namenode"));
+    } finally {
+      System.setErr(origErr);
+    }
 
     // check if the version file does not exists.
     File version = new File(hdfsDir, "current/VERSION");
@@ -285,12 +289,14 @@ public class TestClusterId {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream stdErr = new PrintStream(baos);
     System.setErr(stdErr);
+    try {
+      NameNode.createNameNode(argv, config);
 
-    NameNode.createNameNode(argv, config);
-
-    // Check if usage is printed
-    assertTrue(baos.toString("UTF-8").contains("Usage: hdfs namenode"));
-    System.setErr(origErr);
+      // Check if usage is printed
+      assertTrue(baos.toString("UTF-8").contains("Usage: hdfs namenode"));
+    } finally {
+      System.setErr(origErr);
+    }
 
     // check if the version file does not exists.
     File version = new File(hdfsDir, "current/VERSION");

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java
index 4e4ed0c..d426de5 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java
@@ -72,18 +72,21 @@ public class TestMetadataVersionOutput {
     final PrintStream origOut = System.out;
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
     final PrintStream stdOut = new PrintStream(baos);
-    System.setOut(stdOut);
     try {
-      NameNode.createNameNode(new String[] { "-metadataVersion" }, conf);
-    } catch (Exception e) {
-      assertExceptionContains("ExitException", e);
-    }
+      System.setOut(stdOut);
+      try {
+        NameNode.createNameNode(new String[] { "-metadataVersion" }, conf);
+      } catch (Exception e) {
+        assertExceptionContains("ExitException", e);
+      }
     /* Check if meta data version is printed correctly. */
-    final String verNumStr = HdfsServerConstants.NAMENODE_LAYOUT_VERSION + "";
-    assertTrue(baos.toString("UTF-8").
-      contains("HDFS Image Version: " + verNumStr));
-    assertTrue(baos.toString("UTF-8").
-      contains("Software format version: " + verNumStr));
-    System.setOut(origOut);
+      final String verNumStr = HdfsServerConstants.NAMENODE_LAYOUT_VERSION + "";
+      assertTrue(baos.toString("UTF-8").
+          contains("HDFS Image Version: " + verNumStr));
+      assertTrue(baos.toString("UTF-8").
+          contains("Software format version: " + verNumStr));
+    } finally {
+      System.setOut(origOut);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java
index 6f70b82..b81291a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java
@@ -1044,25 +1044,32 @@ public class TestSnapshotDeletion {
   public void testDeleteSnapshotCommandWithIllegalArguments() throws Exception {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     PrintStream psOut = new PrintStream(out);
-    System.setOut(psOut);
-    System.setErr(psOut);
-    FsShell shell = new FsShell();
-    shell.setConf(conf);
-    
-    String[] argv1 = {"-deleteSnapshot", "/tmp"};
-    int val = shell.run(argv1);
-    assertTrue(val == -1);
-    assertTrue(out.toString().contains(
-        argv1[0] + ": Incorrect number of arguments."));
-    out.reset();
-    
-    String[] argv2 = {"-deleteSnapshot", "/tmp", "s1", "s2"};
-    val = shell.run(argv2);
-    assertTrue(val == -1);
-    assertTrue(out.toString().contains(
-        argv2[0] + ": Incorrect number of arguments."));
-    psOut.close();
-    out.close();
+    PrintStream oldOut = System.out;
+    PrintStream oldErr = System.err;
+    try {
+      System.setOut(psOut);
+      System.setErr(psOut);
+      FsShell shell = new FsShell();
+      shell.setConf(conf);
+
+      String[] argv1 = { "-deleteSnapshot", "/tmp" };
+      int val = shell.run(argv1);
+      assertTrue(val == -1);
+      assertTrue(out.toString()
+          .contains(argv1[0] + ": Incorrect number of arguments."));
+      out.reset();
+
+      String[] argv2 = { "-deleteSnapshot", "/tmp", "s1", "s2" };
+      val = shell.run(argv2);
+      assertTrue(val == -1);
+      assertTrue(out.toString()
+          .contains(argv2[0] + ": Incorrect number of arguments."));
+      psOut.close();
+      out.close();
+    } finally {
+      System.setOut(oldOut);
+      System.setErr(oldErr);
+    }
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
index 3dcbad9..731b97b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
@@ -237,24 +237,31 @@ public class TestSnapshotRename {
   public void testRenameSnapshotCommandWithIllegalArguments() throws Exception {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     PrintStream psOut = new PrintStream(out);
-    System.setOut(psOut);
-    System.setErr(psOut);
-    FsShell shell = new FsShell();
-    shell.setConf(conf);
-    
-    String[] argv1 = {"-renameSnapshot", "/tmp", "s1"};
-    int val = shell.run(argv1);
-    assertTrue(val == -1);
-    assertTrue(out.toString().contains(
-        argv1[0] + ": Incorrect number of arguments."));
-    out.reset();
-    
-    String[] argv2 = {"-renameSnapshot", "/tmp", "s1", "s2", "s3"};
-    val = shell.run(argv2);
-    assertTrue(val == -1);
-    assertTrue(out.toString().contains(
-        argv2[0] + ": Incorrect number of arguments."));
-    psOut.close();
-    out.close();
+    PrintStream oldOut = System.out;
+    PrintStream oldErr = System.err;
+    try {
+      System.setOut(psOut);
+      System.setErr(psOut);
+      FsShell shell = new FsShell();
+      shell.setConf(conf);
+
+      String[] argv1 = { "-renameSnapshot", "/tmp", "s1" };
+      int val = shell.run(argv1);
+      assertTrue(val == -1);
+      assertTrue(out.toString()
+          .contains(argv1[0] + ": Incorrect number of arguments."));
+      out.reset();
+
+      String[] argv2 = { "-renameSnapshot", "/tmp", "s1", "s2", "s3" };
+      val = shell.run(argv2);
+      assertTrue(val == -1);
+      assertTrue(out.toString()
+          .contains(argv2[0] + ": Incorrect number of arguments."));
+      psOut.close();
+      out.close();
+    } finally {
+      System.setOut(oldOut);
+      System.setErr(oldErr);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java
index a6c0924..74f5e7a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java
@@ -43,8 +43,8 @@ public class TestDFSAdminWithHA {
   private MiniQJMHACluster cluster;
   private Configuration conf;
   private DFSAdmin admin;
-  private PrintStream originOut;
-  private PrintStream originErr;
+  private static final PrintStream oldOut = System.out;
+  private static final PrintStream oldErr = System.err;
 
   private static final String NSID = "ns1";
   private static String newLine = System.getProperty("line.separator");
@@ -89,18 +89,19 @@ public class TestDFSAdminWithHA {
     admin.setConf(conf);
     assertTrue(HAUtil.isHAEnabled(conf, "ns1"));
 
-    originOut = System.out;
-    originErr = System.err;
     System.setOut(new PrintStream(out));
     System.setErr(new PrintStream(err));
   }
 
   @After
   public void tearDown() throws Exception {
-    System.out.flush();
-    System.err.flush();
-    System.setOut(originOut);
-    System.setErr(originErr);
+    try {
+      System.out.flush();
+      System.err.flush();
+    } finally {
+      System.setOut(oldOut);
+      System.setErr(oldErr);
+    }
     if (admin != null) {
       admin.close();
     }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestJMXGet.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestJMXGet.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestJMXGet.java
index 370b650..be3ef48 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestJMXGet.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestJMXGet.java
@@ -125,14 +125,19 @@ public class TestJMXGet {
     String pattern = "List of all the available keys:";
     PipedOutputStream pipeOut = new PipedOutputStream();
     PipedInputStream pipeIn = new PipedInputStream(pipeOut);
+    PrintStream oldErr = System.err;
     System.setErr(new PrintStream(pipeOut));
-    jmx.printAllValues();
-    if ((size = pipeIn.available()) != 0) {
-      bytes = new byte[size];
-      pipeIn.read(bytes, 0, bytes.length);            
+    try {
+      jmx.printAllValues();
+      if ((size = pipeIn.available()) != 0) {
+        bytes = new byte[size];
+        pipeIn.read(bytes, 0, bytes.length);
+      }
+      pipeOut.close();
+      pipeIn.close();
+    } finally {
+      System.setErr(oldErr);
     }
-    pipeOut.close();
-    pipeIn.close();
     return bytes != null ? new String(bytes).contains(pattern) : false;
   }
   

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestTools.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestTools.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestTools.java
index c767ce2..346bba7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestTools.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tools/TestTools.java
@@ -103,6 +103,8 @@ public class TestTools {
   private void checkOutput(String[] args, String pattern, PrintStream out,
       Class<?> clazz) {       
     ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+    PrintStream oldOut = System.out;
+    PrintStream oldErr = System.err;
     try {
       PipedOutputStream pipeOut = new PipedOutputStream();
       PipedInputStream pipeIn = new PipedInputStream(pipeOut, PIPE_BUFFER_SIZE);
@@ -125,6 +127,9 @@ public class TestTools {
       assertTrue(new String(outBytes.toByteArray()).contains(pattern));            
     } catch (Exception ex) {
       fail("checkOutput error " + ex);
+    } finally {
+      System.setOut(oldOut);
+      System.setErr(oldErr);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/cccf8848/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTraceAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTraceAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTraceAdmin.java
index 7e10d90..198dafb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTraceAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTraceAdmin.java
@@ -44,9 +44,12 @@ public class TestTraceAdmin {
     try {
       ret = trace.run(cmd);
     } finally {
-      System.out.flush();
-      System.setOut(oldStdout);
-      System.setErr(oldStderr);
+      try {
+        System.out.flush();
+      } finally {
+        System.setOut(oldStdout);
+        System.setErr(oldStderr);
+      }
     }
     return "ret:" + ret + ", " + baos.toString();
   }


Mime
View raw message