sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject sentry git commit: SENTRY-2403: Incorrect naming in RollingFileWithoutDeleteAppender (Peter Somogyi, reviewed by Sergio Pena)
Date Tue, 18 Sep 2018 14:33:19 GMT
Repository: sentry
Updated Branches:
  refs/heads/master e38d8b017 -> 44ada78c3


SENTRY-2403: Incorrect naming in RollingFileWithoutDeleteAppender (Peter Somogyi, reviewed
by Sergio Pena)


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

Branch: refs/heads/master
Commit: 44ada78c356aa70c875357472a6711e80acc905a
Parents: e38d8b0
Author: Sergio Pena <sergio.pena@cloudera.com>
Authored: Tue Sep 18 09:32:54 2018 -0500
Committer: Sergio Pena <sergio.pena@cloudera.com>
Committed: Tue Sep 18 09:32:54 2018 -0500

----------------------------------------------------------------------
 .../RollingFileWithoutDeleteAppender.java       | 20 +++++++++++++++++---
 .../TestRollingFileWithoutDeleteAppender.java   | 19 +++++++++----------
 2 files changed, 26 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/44ada78c/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/log/appender/RollingFileWithoutDeleteAppender.java
----------------------------------------------------------------------
diff --git a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/log/appender/RollingFileWithoutDeleteAppender.java
b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/log/appender/RollingFileWithoutDeleteAppender.java
index fd133f3..39ea9f7 100644
--- a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/log/appender/RollingFileWithoutDeleteAppender.java
+++ b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/log/appender/RollingFileWithoutDeleteAppender.java
@@ -48,7 +48,7 @@ public class RollingFileWithoutDeleteAppender extends FileAppender {
 
   /**
    * Instantiate a RollingFileAppender and open the file designated by
-   * <code>filename</code>. The opened filename will become the ouput
+   * <code>filename</code>. The opened filename will become the output
    * destination for this appender.
    * <p>
    * If the <code>append</code> parameter is true, the file will be appended
to.
@@ -86,7 +86,7 @@ public class RollingFileWithoutDeleteAppender extends FileAppender {
    * <code>File</code> is renamed <code>File.yyyyMMddHHmmss</code>
and closed. A
    * new <code>File</code> is created to receive further log output.
    */
-  // synchronization not necessary since doAppend is alreasy synched
+  // synchronization not necessary since doAppend is already synched
   public void rollOver() {
     if (qw != null) {
       long size = ((CountingQuietWriter) qw).getCount();
@@ -170,6 +170,20 @@ public class RollingFileWithoutDeleteAppender extends FileAppender {
 
   // Mangled file name. Append the current timestamp
   private static String getLogFileName(String oldFileName) {
-    return oldFileName + "." + Long.toString(System.currentTimeMillis());
+    return getFileNameWithoutTimestamp(oldFileName) + "."
+        + Long.toString(System.currentTimeMillis());
+  }
+
+  /**
+   * Remove trailing timestamp from filename
+   * @param fileName original filename with or without trailing timestamp
+   * @return Filename without trailing timestamp
+   */
+  private static String getFileNameWithoutTimestamp(String fileName) {
+    if (fileName.matches("^.*\\.\\d+$")) {
+      return fileName.substring(0, fileName.lastIndexOf('.'));
+    } else {
+      return fileName;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/sentry/blob/44ada78c/sentry-service/sentry-service-server/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java
----------------------------------------------------------------------
diff --git a/sentry-service/sentry-service-server/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java
b/sentry-service/sentry-service-server/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java
index ca9062b..5db15a3 100644
--- a/sentry-service/sentry-service-server/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java
+++ b/sentry-service/sentry-service-server/src/test/java/org/apache/sentry/provider/db/log/appender/TestRollingFileWithoutDeleteAppender.java
@@ -19,6 +19,7 @@
 package org.apache.sentry.provider.db.log.appender;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 import static org.junit.Assert.assertTrue;
 
@@ -55,7 +56,7 @@ public class TestRollingFileWithoutDeleteAppender {
     for (int i = 0; i < 99; i++) {
       if (i < 10) {
         sentryLogger.debug("Hello---" + i);
-      } else if (i < 100) {
+      } else {
         sentryLogger.debug("Hello--" + i);
       }
     }
@@ -63,7 +64,7 @@ public class TestRollingFileWithoutDeleteAppender {
     if (dataDir != null) {
       File[] files = dataDir.listFiles();
       if (files != null) {
-        assertEquals(files.length, 10);
+        assertEquals(10, files.length);
       } else {
         fail("Excepted 10 log files.");
       }
@@ -74,8 +75,7 @@ public class TestRollingFileWithoutDeleteAppender {
   }
 
   /***
-   * Generate log enough to cause a single rollover. Verify the file name format
-   * @throws Throwable
+   * Generate log enough to cause rollovers. Verify the file name format
    */
   @Test
   public void testFileNamePattern() throws Throwable {
@@ -87,13 +87,12 @@ public class TestRollingFileWithoutDeleteAppender {
     appender.setMaximumFileSize(10);
     sentryLogger.addAppender(appender);
     sentryLogger.debug("123456789012345");
+    sentryLogger.debug("123456789012345");
     File[] files = dataDir.listFiles();
-    if (files != null) {
-      assertEquals(files.length, 2);
-      assertTrue(files[0].getName().contains("auditLog.log."));
-      assertTrue(files[1].getName().contains("auditLog.log."));
-    } else {
-      fail("Excepted 2 log files.");
+    assertNotNull(files);
+    assertEquals(3, files.length);
+    for (int i = 0; i < 3; i++) {
+      assertTrue(files[i].getName().matches("auditLog\\.log\\.\\d+"));
     }
   }
 


Mime
View raw message