You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ad...@apache.org on 2023/02/02 19:45:13 UTC

[ozone] branch master updated: HDDS-7868. Intermittent failure in TestOmAcls (#4239)

This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 8741083374 HDDS-7868. Intermittent failure in TestOmAcls (#4239)
8741083374 is described below

commit 874108337421a1204b41ceaf1f0a85ab5de77f50
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Thu Feb 2 20:45:07 2023 +0100

    HDDS-7868. Intermittent failure in TestOmAcls (#4239)
---
 .../hadoop/ozone/audit/AuditLogTestUtils.java      | 56 +++++++++++-----------
 .../org/apache/hadoop/ozone/om/TestOmAcls.java     |  9 ++--
 2 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java b/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
index d619c91f0d..9989443f46 100644
--- a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
+++ b/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
@@ -17,14 +17,15 @@
  */
 package org.apache.hadoop.ozone.audit;
 
-import java.io.BufferedReader;
+import org.apache.commons.io.FileUtils;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.util.concurrent.TimeoutException;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ozone.test.GenericTestUtils.waitFor;
 
 /**
  * Utility class to read audit logs.
@@ -47,33 +48,34 @@ public final class AuditLogTestUtils {
    * Searches for the given action in the audit log file.
    */
   public static void verifyAuditLog(AuditAction action,
-                                    AuditEventStatus eventStatus) {
-    Path file = Paths.get(AUDITLOG_FILENAME);
-    try (BufferedReader br = Files.newBufferedReader(file,
-            StandardCharsets.UTF_8)) {
-      String line;
-      while ((line = br.readLine()) != null) {
-        if (line.contains(action.getAction()) &&
-                line.contains(eventStatus.getStatus())) {
-          return;
+      AuditEventStatus eventStatus)
+      throws InterruptedException, TimeoutException {
+    waitFor(
+        () -> auditLogContains(action.getAction(), eventStatus.getStatus()),
+        1000, 10000);
+  }
+
+  public static boolean auditLogContains(String... strings) {
+    File file = new File(AUDITLOG_FILENAME);
+    try {
+      String contents = FileUtils.readFileToString(file, UTF_8);
+      for (String s : strings) {
+        if (!contents.contains(s)) {
+          return false;
         }
       }
-    } catch (Exception e) {
-      throw new AssertionError(e);
-    } finally {
-      truncateAuditLogFile();
+      return true;
+    } catch (IOException e) {
+      return false;
     }
-    throw new AssertionError("Audit log file doesn't contain " +
-            "the message with params  event=" + action.getAction() +
-            " result=" + eventStatus.getStatus());
   }
 
-  private static void truncateAuditLogFile() {
+  public static void truncateAuditLogFile() throws IOException {
     File auditLogFile = new File(AUDITLOG_FILENAME);
-    try {
-      new FileOutputStream(auditLogFile).getChannel().truncate(0).close();
-    } catch (IOException e) {
-      System.out.println("Failed to truncate file: " + AUDITLOG_FILENAME);
-    }
+    new FileOutputStream(auditLogFile).getChannel().truncate(0).close();
+  }
+
+  public static void deleteAuditLogFile() {
+    FileUtils.deleteQuietly(new File(AUDITLOG_FILENAME));
   }
 }
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java
index b920f57344..a3164e6792 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java
@@ -38,6 +38,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.Timeout;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.UUID;
 
@@ -102,11 +103,13 @@ public class TestOmAcls {
     if (cluster != null) {
       cluster.shutdown();
     }
+    AuditLogTestUtils.deleteAuditLogFile();
   }
 
   @Before
-  public void setup() {
+  public void setup() throws IOException {
     logCapturer.clearOutput();
+    AuditLogTestUtils.truncateAuditLogFile();
 
     TestOmAcls.volumeAclAllow = true;
     TestOmAcls.bucketAclAllow = true;
@@ -115,7 +118,7 @@ public class TestOmAcls {
   }
 
   @Test
-  public void testCreateVolumePermissionDenied() {
+  public void testCreateVolumePermissionDenied() throws Exception {
     TestOmAcls.volumeAclAllow = false;
 
     OMException exception = assertThrows(OMException.class,
@@ -142,7 +145,7 @@ public class TestOmAcls {
   }
 
   @Test
-  public void testCreateBucketPermissionDenied() {
+  public void testCreateBucketPermissionDenied() throws Exception {
     TestOmAcls.bucketAclAllow = false;
 
     OMException exception = assertThrows(OMException.class,


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