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 sh...@apache.org on 2018/07/11 23:10:21 UTC

[21/56] [abbrv] hadoop git commit: HDDS-235. Fix TestOzoneAuditLogger#verifyDefaultLogLevel. Contributed by Xiaoyu Yao.

HDDS-235. Fix TestOzoneAuditLogger#verifyDefaultLogLevel.
Contributed by Xiaoyu Yao.


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

Branch: refs/heads/HDFS-12943
Commit: 790c563511161c901b7b667e787baca8725f9249
Parents: 2f51cd6
Author: Anu Engineer <ae...@apache.org>
Authored: Sun Jul 8 11:27:54 2018 -0700
Committer: Anu Engineer <ae...@apache.org>
Committed: Sun Jul 8 11:27:54 2018 -0700

----------------------------------------------------------------------
 .../ozone/audit/TestOzoneAuditLogger.java       | 46 +++++++++++++-------
 1 file changed, 31 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/790c5635/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java b/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
index d3cc9e4..57a7d9e 100644
--- a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
+++ b/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
@@ -100,7 +100,7 @@ public class TestOzoneAuditLogger {
     AUDIT.logReadFailure(DummyAction.READ_VOLUME, auditableObj.toAuditMap(), Level.ERROR);
     AUDIT.logReadFailure(DummyAction.READ_VOLUME, auditableObj.toAuditMap(), Level.ERROR,
         new Exception("test"));
-    verifyLog(null);
+    verifyNoLog();
   }
 
   /**
@@ -110,22 +110,38 @@ public class TestOzoneAuditLogger {
   public void notLogDebugEvents() throws IOException {
     AUDIT.logWriteSuccess(DummyAction.CREATE_VOLUME, auditableObj.toAuditMap(), Level.DEBUG);
     AUDIT.logReadSuccess(DummyAction.READ_VOLUME, auditableObj.toAuditMap(), Level.DEBUG);
-    verifyLog(null);
+    verifyNoLog();
   }
 
-  public void verifyLog(String expected) throws IOException {
-      File file = new File("audit.log");
-      List<String> lines = FileUtils.readLines(file, (String)null);
-      if(expected == null){
-        // When no log entry is expected, the log file must be empty
-        assertTrue(lines.size() == 0);
-      } else {
-        // When log entry is expected, the log file will contain one line and
-        // that must be equal to the expected string
-        assertTrue(expected.equalsIgnoreCase(lines.get(0)));
-        //empty the file
-        lines.remove(0);
-        FileUtils.writeLines(file, lines, false);
+  private void verifyLog(String expected) throws IOException {
+    File file = new File("audit.log");
+    List<String> lines = FileUtils.readLines(file, (String)null);
+      final int retry = 5;
+      int i = 0;
+      while (lines.isEmpty() && i < retry) {
+        lines = FileUtils.readLines(file, (String)null);
+        try {
+          Thread.sleep( 500 * (i + 1));
+        } catch(InterruptedException ie) {
+          Thread.currentThread().interrupt();
+          break;
+        }
+        i++;
       }
+
+      // When log entry is expected, the log file will contain one line and
+      // that must be equal to the expected string
+      assertTrue(lines.size() != 0);
+      assertTrue(expected.equalsIgnoreCase(lines.get(0)));
+      //empty the file
+      lines.remove(0);
+      FileUtils.writeLines(file, lines, false);
+  }
+
+  private void verifyNoLog() throws IOException {
+    File file = new File("audit.log");
+    List<String> lines = FileUtils.readLines(file, (String)null);
+    // When no log entry is expected, the log file must be empty
+    assertTrue(lines.size() == 0);
   }
 }


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