hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmcc...@apache.org
Subject hadoop git commit: HADOOP-11430. Add GenericTestUtils#disableLog, GenericTestUtils#setLogLevel (cmccabe) (cherry picked from commit 6635ccd21766faf8f6a15d937dc8919a9075c988)
Date Fri, 19 Dec 2014 03:42:06 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 99c176ea6 -> fe38ed2ee


HADOOP-11430. Add GenericTestUtils#disableLog, GenericTestUtils#setLogLevel (cmccabe)
(cherry picked from commit 6635ccd21766faf8f6a15d937dc8919a9075c988)


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

Branch: refs/heads/branch-2
Commit: fe38ed2ee7bd3be5c502d217f13d848c4ca0d9c3
Parents: 99c176e
Author: Colin Patrick Mccabe <cmccabe@cloudera.com>
Authored: Thu Dec 18 19:39:04 2014 -0800
Committer: Colin Patrick Mccabe <cmccabe@cloudera.com>
Committed: Thu Dec 18 19:41:59 2014 -0800

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  3 ++
 .../fs/FileContextCreateMkdirBaseTest.java      | 11 ++---
 .../apache/hadoop/test/GenericTestUtils.java    | 42 ++++++++++++++++++++
 .../org/apache/hadoop/hdfs/DFSTestUtil.java     |  5 ---
 .../org/apache/hadoop/hdfs/TestDFSShell.java    |  4 +-
 .../namenode/snapshot/SnapshotTestHelper.java   | 35 ++++++++--------
 6 files changed, 67 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/fe38ed2e/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 22e5083..d1429dc 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -79,6 +79,9 @@ Release 2.7.0 - UNRELEASED
     HADOOP-11427. ChunkedArrayList: fix removal via iterator and implement get
     (cmccabe)
 
+    HADOOP-11430. Add GenericTestUtils#disableLog, GenericTestUtils#setLogLevel
+    (cmccabe)
+
   OPTIMIZATIONS
 
     HADOOP-11323. WritableComparator#compare keeps reference to byte array.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fe38ed2e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
index bd1f0ae..d91091f 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java
@@ -28,6 +28,7 @@ import org.junit.Before;
 import org.junit.Test;
 import static org.apache.hadoop.fs.FileContextTestHelper.*;
 import org.apache.commons.logging.impl.Log4JLogger;
+import org.apache.hadoop.test.GenericTestUtils;
 
 /**
  * <p>
@@ -54,14 +55,8 @@ public abstract class FileContextCreateMkdirBaseTest {
   protected final FileContextTestHelper fileContextTestHelper;
   protected static FileContext fc;
       
-  {
-    try {
-      ((Log4JLogger)FileSystem.LOG).getLogger().setLevel(Level.DEBUG);
-    }
-    catch(Exception e) {
-      System.out.println("Cannot change log level\n"
-          + StringUtils.stringifyException(e));
-    }
+  static {
+    GenericTestUtils.setLogLevel(FileSystem.LOG, Level.DEBUG);
   }
   
   public FileContextCreateMkdirBaseTest() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fe38ed2e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
index 7be71e9..65c18d1 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
@@ -38,6 +38,8 @@ import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.Time;
 import org.apache.log4j.Layout;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.WriterAppender;
 import org.junit.Assert;
@@ -55,6 +57,46 @@ public abstract class GenericTestUtils {
 
   private static final AtomicInteger sequence = new AtomicInteger();
 
+  @SuppressWarnings("unchecked")
+  public static void disableLog(Log log) {
+    // We expect that commons-logging is a wrapper around Log4j.
+    disableLog((Log4JLogger) log);
+  }
+
+  public static Logger toLog4j(org.slf4j.Logger logger) {
+    return LogManager.getLogger(logger.getName());
+  }
+
+  public static void disableLog(Log4JLogger log) {
+    log.getLogger().setLevel(Level.OFF);
+  }
+
+  public static void disableLog(Logger logger) {
+    logger.setLevel(Level.OFF);
+  }
+
+  public static void disableLog(org.slf4j.Logger logger) {
+    disableLog(toLog4j(logger));
+  }
+
+  @SuppressWarnings("unchecked")
+  public static void setLogLevel(Log log, Level level) {
+    // We expect that commons-logging is a wrapper around Log4j.
+    setLogLevel((Log4JLogger) log, level);
+  }
+
+  public static void setLogLevel(Log4JLogger log, Level level) {
+    log.getLogger().setLevel(level);
+  }
+
+  public static void setLogLevel(Logger logger, Level level) {
+    logger.setLevel(level);
+  }
+
+  public static void setLogLevel(org.slf4j.Logger logger, Level level) {
+    setLogLevel(toLog4j(logger), level);
+  }
+
   /**
    * Extracts the name of the method where the invocation has happened
    * @return String name of the invoking method

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fe38ed2e/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java
index 864d7c5..8755d02 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java
@@ -711,11 +711,6 @@ public class DFSTestUtil {
     return ((DFSOutputStream) out.getWrappedStream()).getBlockToken();
   }
 
-  static void setLogLevel2All(org.apache.commons.logging.Log log) {
-    ((org.apache.commons.logging.impl.Log4JLogger)log
-        ).getLogger().setLevel(org.apache.log4j.Level.ALL);
-  }
-
   public static String readFile(File f) throws IOException {
     StringBuilder b = new StringBuilder();
     BufferedReader in = new BufferedReader(new FileReader(f));

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fe38ed2e/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 4860752..7af520c 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
@@ -52,6 +52,8 @@ import org.apache.hadoop.test.PathUtils;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.ToolRunner;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.apache.log4j.Level;
 import org.junit.Test;
 
 import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY;
@@ -1499,7 +1501,7 @@ public class TestDFSShell {
   
   @Test (timeout = 30000)
   public void testGet() throws IOException {
-    DFSTestUtil.setLogLevel2All(FSInputChecker.LOG);
+    GenericTestUtils.setLogLevel(FSInputChecker.LOG, Level.ALL);
 
     final String fname = "testGet.txt";
     Path root = new Path("/test/get");

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fe38ed2e/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotTestHelper.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotTestHelper.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotTestHelper.java
index f94d3eb..cffb930 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotTestHelper.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotTestHelper.java
@@ -62,6 +62,7 @@ import org.apache.hadoop.http.HttpServer2;
 import org.apache.hadoop.ipc.ProtobufRpcEngine.Server;
 import org.apache.hadoop.metrics2.impl.MetricsSystemImpl;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.log4j.Level;
 import org.junit.Assert;
 
@@ -79,28 +80,24 @@ public class SnapshotTestHelper {
         "org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetAsyncDiskService",
     };
     for(String n : lognames) {
-      setLevel2OFF(LogFactory.getLog(n));
+      GenericTestUtils.disableLog(LogFactory.getLog(n));
     }
     
-    setLevel2OFF(LogFactory.getLog(UserGroupInformation.class));
-    setLevel2OFF(LogFactory.getLog(BlockManager.class));
-    setLevel2OFF(LogFactory.getLog(FSNamesystem.class));
-    setLevel2OFF(LogFactory.getLog(DirectoryScanner.class));
-    setLevel2OFF(LogFactory.getLog(MetricsSystemImpl.class));
+    GenericTestUtils.disableLog(LogFactory.getLog(UserGroupInformation.class));
+    GenericTestUtils.disableLog(LogFactory.getLog(BlockManager.class));
+    GenericTestUtils.disableLog(LogFactory.getLog(FSNamesystem.class));
+    GenericTestUtils.disableLog(LogFactory.getLog(DirectoryScanner.class));
+    GenericTestUtils.disableLog(LogFactory.getLog(MetricsSystemImpl.class));
     
-    setLevel2OFF(DataBlockScanner.LOG);
-    setLevel2OFF(HttpServer2.LOG);
-    setLevel2OFF(DataNode.LOG);
-    setLevel2OFF(BlockPoolSliceStorage.LOG);
-    setLevel2OFF(LeaseManager.LOG);
-    setLevel2OFF(NameNode.stateChangeLog);
-    setLevel2OFF(NameNode.blockStateChangeLog);
-    setLevel2OFF(DFSClient.LOG);
-    setLevel2OFF(Server.LOG);
-  }
-
-  static void setLevel2OFF(Object log) {
-    ((Log4JLogger)log).getLogger().setLevel(Level.OFF);
+    GenericTestUtils.disableLog(DataBlockScanner.LOG);
+    GenericTestUtils.disableLog(HttpServer2.LOG);
+    GenericTestUtils.disableLog(DataNode.LOG);
+    GenericTestUtils.disableLog(BlockPoolSliceStorage.LOG);
+    GenericTestUtils.disableLog(LeaseManager.LOG);
+    GenericTestUtils.disableLog(NameNode.stateChangeLog);
+    GenericTestUtils.disableLog(NameNode.blockStateChangeLog);
+    GenericTestUtils.disableLog(DFSClient.LOG);
+    GenericTestUtils.disableLog(Server.LOG);
   }
 
   private SnapshotTestHelper() {


Mime
View raw message