You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/04 04:57:43 UTC

svn commit: r1077264 - in /hadoop/common/branches/branch-0.20-security-patches/src/test/system: aop/org/apache/hadoop/test/system/ java/org/apache/hadoop/test/system/

Author: omalley
Date: Fri Mar  4 03:57:43 2011
New Revision: 1077264

URL: http://svn.apache.org/viewvc?rev=1077264&view=rev
Log:
commit b6805127eaacf440f91a79d7806941a88349f8cd
Author: Sharad Agarwal <sh...@yahoo-inc.com>
Date:   Wed Mar 3 11:12:10 2010 +0530

     patch from

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/test/system/aop/org/apache/hadoop/test/system/DaemonProtocolAspect.aj
    hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonClient.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonCluster.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/DaemonProtocol.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/system/aop/org/apache/hadoop/test/system/DaemonProtocolAspect.aj
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/system/aop/org/apache/hadoop/test/system/DaemonProtocolAspect.aj?rev=1077264&r1=1077263&r2=1077264&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/system/aop/org/apache/hadoop/test/system/DaemonProtocolAspect.aj (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/system/aop/org/apache/hadoop/test/system/DaemonProtocolAspect.aj Fri Mar  4 03:57:43 2011
@@ -1,5 +1,6 @@
 package org.apache.hadoop.test.system;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
@@ -8,6 +9,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.util.Shell.ShellCommandExecutor;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -207,4 +209,32 @@ public aspect DaemonProtocolAspect {
       actions.clear();
     }
   }
+
+  public String DaemonProtocol.getFilePattern() {
+    //We use the environment variable HADOOP_LOGFILE to get the
+    //pattern to use in the search.
+    String logDir = System.getenv("HADOOP_LOG_DIR");
+    String daemonLogPattern = System.getenv("HADOOP_LOGFILE");
+    if(daemonLogPattern == null && daemonLogPattern.isEmpty()) {
+      return "*";
+    }
+    return  logDir+File.separator+daemonLogPattern+"*";
+  }
+
+  public int DaemonProtocol.getNumberOfMatchesInLogFile(String pattern)
+      throws IOException {
+    String filePattern = getFilePattern();
+    String[] cmd =
+        new String[] {
+            "bash",
+            "-c",
+            "grep -c "
+                + pattern + " " + filePattern
+                + " | awk -F: '{s+=$2} END {print s}'" };
+    ShellCommandExecutor shexec = new ShellCommandExecutor(cmd);
+    shexec.execute();
+    String output = shexec.getOutput();
+    return Integer.parseInt(output.replaceAll("\n", "").trim());
+  }
 }
+

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonClient.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonClient.java?rev=1077264&r1=1077263&r2=1077264&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonClient.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonClient.java Fri Mar  4 03:57:43 2011
@@ -2,8 +2,13 @@ package org.apache.hadoop.test.system;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
 import java.util.List;
 
+import junit.framework.Assert;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.test.system.process.RemoteProcess;
@@ -18,6 +23,8 @@ public abstract class AbstractDaemonClie
   private RemoteProcess process;
   private boolean connected;
 
+  private static final Log LOG = LogFactory.getLog(AbstractDaemonClient.class);
+  
   /**
    * Create a Daemon client.<br/>
    * 
@@ -195,4 +202,117 @@ public abstract class AbstractDaemonClie
     }
   }
 
+  /**
+   * Gets number of times FATAL log messages where logged in Daemon logs. 
+   * <br/>
+   * Pattern used for searching is FATAL. <br/>
+   * 
+   * @return number of occurrence of fatal message.
+   * @throws IOException
+   */
+  public int getNumberOfFatalStatementsInLog() throws IOException {
+    DaemonProtocol proxy = getProxy();
+    String pattern = "FATAL";
+    return proxy.getNumberOfMatchesInLogFile(pattern);
+  }
+
+  /**
+   * Gets number of times ERROR log messages where logged in Daemon logs. 
+   * <br/>
+   * Pattern used for searching is ERROR. <br/>
+   * 
+   * @return number of occurrence of error message.
+   * @throws IOException
+   */
+  public int getNumberOfErrorStatementsInLog() throws IOException {
+    DaemonProtocol proxy = getProxy();
+    String pattern = "ERROR";
+    return proxy.getNumberOfMatchesInLogFile(pattern);
+  }
+
+  /**
+   * Gets number of times Warning log messages where logged in Daemon logs. 
+   * <br/>
+   * Pattern used for searching is WARN. <br/>
+   * 
+   * @return number of occurrence of warning message.
+   * @throws IOException
+   */
+  public int getNumberOfWarnStatementsInLog() throws IOException {
+    DaemonProtocol proxy = getProxy();
+    String pattern = "WARN";
+    return proxy.getNumberOfMatchesInLogFile(pattern);
+  }
+
+  /**
+   * Gets number of time given Exception were present in log file. <br/>
+   * 
+   * @param e exception class.
+   * @return number of exceptions in log
+   * @throws IOException
+   */
+  public int getNumberOfExceptionsInLog(Exception e)
+      throws IOException {
+    DaemonProtocol proxy = getProxy();
+    String pattern = e.getClass().getSimpleName();
+    return proxy.getNumberOfMatchesInLogFile(pattern);
+  }
+
+  /**
+   * Number of times ConcurrentModificationException present in log file. 
+   * <br/>
+   * @return number of times exception in log file.
+   * @throws IOException
+   */
+  public int getNumberOfConcurrentModificationExceptionsInLog()
+      throws IOException {
+    return getNumberOfExceptionsInLog(new ConcurrentModificationException());
+  }
+
+  private int errorCount;
+  private int fatalCount;
+  private int concurrentExceptionCount;
+
+  /**
+   * Populate the initial exception counts to be used to assert once a testcase
+   * is done there was no exception in the daemon when testcase was run.
+   * 
+   * @throws IOException
+   */
+  protected void populateExceptionCount() throws IOException {
+    errorCount = getNumberOfErrorStatementsInLog();
+    LOG.info("Number of error messages in logs : " + errorCount);
+    fatalCount = getNumberOfFatalStatementsInLog();
+    LOG.info("Number of fatal statement in logs : " + fatalCount);
+    concurrentExceptionCount =
+        getNumberOfConcurrentModificationExceptionsInLog();
+    LOG.info("Number of concurrent modification in logs : "
+        + concurrentExceptionCount);
+  }
+
+  /**
+   * Assert if the new exceptions were logged into the log file.
+   * <br/>
+   * <b><i>
+   * Pre-req for the method is that populateExceptionCount() has 
+   * to be called before calling this method.</b></i>
+   * @throws IOException
+   */
+  protected void assertNoExceptionsOccurred() throws IOException {
+    int newerrorCount = getNumberOfErrorStatementsInLog();
+    LOG.info("Number of error messages while asserting : " + newerrorCount);
+    int newfatalCount = getNumberOfFatalStatementsInLog();
+    LOG.info("Number of fatal messages while asserting : " + newfatalCount);
+    int newconcurrentExceptionCount =
+        getNumberOfConcurrentModificationExceptionsInLog();
+    LOG.info("Number of concurrentmodification execption while asserting :"
+        + newconcurrentExceptionCount);
+    Assert.assertEquals(
+        "New Error Messages logged in the log file", errorCount, newerrorCount);
+    Assert.assertEquals(
+        "New Fatal messages logged in the log file", fatalCount, newfatalCount);
+    Assert.assertEquals(
+        "New ConcurrentModificationException in log file",
+        concurrentExceptionCount, newconcurrentExceptionCount);
+  }
 }

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonCluster.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonCluster.java?rev=1077264&r1=1077263&r2=1077264&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonCluster.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonCluster.java Fri Mar  4 03:57:43 2011
@@ -192,6 +192,7 @@ public abstract class AbstractDaemonClus
     ping();
     clearAllControlActions();
     ensureClean();
+    populateExceptionCounts();
   }
 
   public void clearAllControlActions() throws IOException {
@@ -217,7 +218,34 @@ public abstract class AbstractDaemonClus
   public void tearDown() throws IOException {
     ensureClean();
     clearAllControlActions();
+    assertNoExceptionMessages();
     disconnect();
   }
+
+  /**
+   * Populate the exception counts in all the daemons so that it can be checked when 
+   * the testcase has finished running.<br/>
+   * @throws IOException
+   */
+  protected void populateExceptionCounts() throws IOException {
+    for(List<AbstractDaemonClient> lst : daemons.values()) {
+      for(AbstractDaemonClient d : lst) {
+        d.populateExceptionCount();
+      }
+    }
+  }
+
+  /**
+   * Assert no exception has been thrown during the sequence of the actions.
+   * <br/>
+   * @throws IOException
+   */
+  protected void assertNoExceptionMessages() throws IOException {
+    for(List<AbstractDaemonClient> lst : daemons.values()) {
+      for(AbstractDaemonClient d : lst) {
+        d.assertNoExceptionsOccurred();
+      }
+    }
+  }
 }
 

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/DaemonProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/DaemonProtocol.java?rev=1077264&r1=1077263&r2=1077264&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/DaemonProtocol.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/system/java/org/apache/hadoop/test/system/DaemonProtocol.java Fri Mar  4 03:57:43 2011
@@ -122,4 +122,16 @@ public interface DaemonProtocol extends 
    */
   @SuppressWarnings("unchecked")
   ControlAction[] getActions(Writable key) throws IOException;
-}
\ No newline at end of file
+
+  /**
+   * Gets the number of times a particular pattern has been found in the 
+   * daemons log file.<br/>
+   * <b><i>Please note that search spans across all previous messages of
+   * Daemon, so better practise is to get previous counts before an operation
+   * and then recheck if the sequence of action has caused any problems</i></b>
+   * @param pattern
+   * @return number of times the pattern if found in log file.
+   * @throws IOException
+   */
+  int getNumberOfMatchesInLogFile(String pattern) throws IOException;
+}