[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch master updated. v_1.0.0-13-gc4012ae

Gitbot git-noreply at pixie.qos.ch
Sat Nov 5 11:58:18 CET 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  c4012ae2d75b370754f327d5ad896baccf636bb7 (commit)
      from  01ae278bdf133e73f7676eebf957d07eca173a03 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=c4012ae2d75b370754f327d5ad896baccf636bb7
http://github.com/ceki/logback/commit/c4012ae2d75b370754f327d5ad896baccf636bb7

commit c4012ae2d75b370754f327d5ad896baccf636bb7
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Fri Nov 4 23:57:30 2011 +0100

    small impovents

diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
index 6010c43..45ffa3b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
@@ -39,6 +39,7 @@ public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends
     long time = getCurrentTime();
     if (time >= nextCheck) {
       Date dateOfElapsedPeriod = dateInCurrentPeriod;
+      addInfo("Elapsed period: "+dateOfElapsedPeriod);
       elapsedPeriodsFileName = tbrp.fileNamePatternWCS
           .convert(dateOfElapsedPeriod);
       setDateInCurrentPeriod(time);
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingDest.java
similarity index 96%
rename from logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
rename to logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingDest.java
index b5f1d59..ae1c5de 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingDest.java
@@ -1,411 +1,412 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- *   or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.core.rolling;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-
-import ch.qos.logback.core.testUtil.RandomUtil;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import ch.qos.logback.core.util.Compare;
-import ch.qos.logback.core.util.CoreTestConstants;
-
-/**
- * A rather exhaustive set of tests. Tests include leaving the file option
- * blank, or setting it, with and without compression, and tests with or without
- * stopping/restarting the RollingFileAppender.
- * <p/>
- * The regression tests log a few times using a RollingFileAppender. Then, they
- * predict the names of the files which should be generated and compare them
- * with witness files.
- * <p/>
- * <pre>
- *                Compression     file option    Stop/Restart
- *     Test1      NO              BLANK           NO
- *     Test2      YES             BLANK           NO
- *     Test3      NO              BLANK           YES
- *     Test4      NO              SET             YES
- *     Test5      NO              SET             NO
- *     Test6      YES             SET             NO
- * </pre>
- *
- * @author Ceki Gülcü
- */
-public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
-
-  RollingFileAppender<Object> rfa1 = new RollingFileAppender<Object>();
-  TimeBasedRollingPolicy<Object> tbrp1 = new TimeBasedRollingPolicy<Object>();
-
-  RollingFileAppender<Object> rfa2 = new RollingFileAppender<Object>();
-  TimeBasedRollingPolicy<Object> tbrp2 = new TimeBasedRollingPolicy<Object>();
-
-  @Before
-  @Override
-  public void setUp() {
-    super.setUp();
-  }
-
-  @After
-  public void tearDown() {
-  }
-
-  void initRFA(RollingFileAppender<Object> rfa, String filename) {
-    rfa.setContext(context);
-    rfa.setEncoder(encoder);
-    if (filename != null) {
-      rfa.setFile(filename);
-    }
-  }
-
-  void initTRBP(RollingFileAppender<Object> rfa,
-                TimeBasedRollingPolicy<Object> tbrp, String filenamePattern,
-                long givenTime) {
-    tbrp.setContext(context);
-    tbrp.setFileNamePattern(filenamePattern);
-    tbrp.setParent(rfa);
-    tbrp.timeBasedFileNamingAndTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
-    tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(givenTime);
-    rfa.setRollingPolicy(tbrp);
-    tbrp.start();
-    rfa.start();
-  }
-
-  /**
-   * Test rolling without compression, file option left blank, no stop/start
-   */
-  @Test
-  public void noCompression_FileBlank_NoRestart_1() throws Exception {
-    String testId = "test1";
-    initRFA(rfa1, null);
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    // compute the current filename
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i < 3; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-" + testId + "." + i++));
-    }
-  }
-
-  /**
-   * With compression, file option left blank, no stop/restart
-   */
-  @Test
-  public void withCompression_FileBlank_NoRestart_2() throws Exception {
-    String testId = "test2";
-    initRFA(rfa1, null);
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
-
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i < 3; i++) {
-      // when i == 2, file name should not have .gz extension
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, i != 2);
-      rfa1.doAppend("Hello---" + i);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-      waitForCompression(tbrp1);
-    }
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
-      i++;
-    }
-  }
-
-  /**
-   * No compression, file option left blank, with stop/restart,
-   */
-  @Test
-  public void noCompression_FileBlank_StopRestart_3() throws Exception {
-    String testId = "test3";
-
-    initRFA(rfa1, null);
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    // a new file is created by virtue of rfa.start();
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i <= 2; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    rfa1.stop();
-
-    initRFA(rfa2, null);
-    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", tbrp1.timeBasedFileNamingAndTriggeringPolicy
-            .getCurrentTime());
-
-    for (int i = 0; i <= 2; i++) {
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      rfa2.doAppend("World---" + i);
-      incCurrentTime(100);
-      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-" + testId + "." + i++));
-    }
-  }
-
-  /**
-   * Without compression, file option set, with stop/restart
-   */
-  @Test
-  public void noCompression_FileSet_StopRestart_4() throws Exception {
-    String testId = "test4";
-    initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i <= 2; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    rfa1.stop();
-
-    // change the timestamp of the currently actively file
-    File activeFile = new File(rfa1.getFile());
-    activeFile.setLastModified(currentTime);
-
-    initRFA(rfa2, testId2FileName(testId));
-    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    for (int i = 0; i <= 2; i++) {
-      rfa2.doAppend("World---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(100);
-      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    System.out.println("Before "+expectedFilenameList);
-    massageExpectedFilesToCorresponToCurrentTarget("test4.log");
-    System.out.println("After "+expectedFilenameList);
-
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-" + testId + "." + i++));
-    }
-  }
-
-  @Test
-  public void noCompression_FileSet_StopRestart_WithLongWait_4B()
-          throws Exception {
-    String testId = "test4B";
-    initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i <= 2; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    rfa1.stop();
-
-    // change the timestamp of the currently actively file
-    File activeFile = new File(rfa1.getFile());
-    activeFile.setLastModified(currentTime);
-
-    incCurrentTime(2000);
-
-    initRFA(rfa2, randomOutputDir + "test4B.log");
-    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    for (int i = 0; i <= 2; i++) {
-      rfa2.doAppend("World---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(100);
-      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    massageExpectedFilesToCorresponToCurrentTarget("test4B.log");
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-test4B." + i++));
-    }
-
-  }
-
-  /**
-   * No compression, file option set, without stop/restart
-   */
-  @Test
-  public void noCompression_FileSet_NoRestart_5() throws Exception {
-    String testId = "test5";
-
-    initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i < 3; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-
-    massageExpectedFilesToCorresponToCurrentTarget("test5.log");
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-test5." + i++));
-    }
-  }
-
-  /**
-   * With compression, file option set, no stop/restart,
-   */
-  @Test
-  public void withCompression_FileSet_NoRestart_6() throws Exception {
-
-    String testId = "test6";
-
-    initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
-
-    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i < 3; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, true);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-      waitForCompression(tbrp1);
-    }
-
-    massageExpectedFilesToCorresponToCurrentTarget("test6.log");
-
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
-      i++;
-    }
-  }
-
-  @Test
-  public void withMissingTargetDir() throws Exception {
-    String testId = "missingTargetDir";
-
-    initRFA(rfa1, testId2FileName(testId));
-    int secondDiff = RandomUtil.getPositiveInt();
-    String randomTargetDir = CoreTestConstants.OUTPUT_DIR_PREFIX + secondDiff + '/';
-
-    System.out.println("randomOutputDir"+randomOutputDir);
-    System.out.println("randomTargetDir"+randomTargetDir);
-
-    initTRBP(rfa1, tbrp1, randomTargetDir + testId + "-%d{"
-            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
-
-    addExpectedFileName_ByDate(randomTargetDir, testId, getDateOfCurrentPeriodsStart(), false);
-
-    incCurrentTime(1100);
-    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-
-    for (int i = 0; i < 3; i++) {
-      rfa1.doAppend("Hello---" + i);
-      addExpectedFileNamedIfItsTime_ByDate(randomTargetDir, testId, false);
-      incCurrentTime(500);
-      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
-    }
-    massageExpectedFilesToCorresponToCurrentTarget("missingTargetDir.log");
-    int i = 0;
-    for (String fn : expectedFilenameList) {
-      System.out.println("expectedFile="+fn);
-      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/tbr-test5." + i++));
-    }
-
-  }
-
-  // =========================================================================
-  // utility methods
-  // =========================================================================
-
-  void massageExpectedFilesToCorresponToCurrentTarget(String file) {
-    // we added one too many files by date
-    expectedFilenameList.remove(expectedFilenameList.size() - 1);
-    // since file is set, we have to add it
-    addExpectedFileName_ByFile(file);
-  }
-
-  void addExpectedFileName_ByFile(String filenameSuffix) {
-    String fn = randomOutputDir + filenameSuffix;
-    expectedFilenameList.add(fn);
-  }
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ *   or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.rolling;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import ch.qos.logback.core.testUtil.RandomUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import ch.qos.logback.core.util.Compare;
+import ch.qos.logback.core.util.CoreTestConstants;
+
+/**
+ * A rather exhaustive set of tests. Tests include leaving the file option
+ * blank, or setting it, with and without compression, and tests with or without
+ * stopping/restarting the RollingFileAppender.
+ * <p/>
+ * The regression tests log a few times using a RollingFileAppender. Then, they
+ * predict the names of the files which should be generated and compare them
+ * with witness files.
+ * <p/>
+ * <pre>
+ *                Compression     file option    Stop/Restart
+ *     Test1      NO              BLANK           NO
+ *     Test2      YES             BLANK           NO
+ *     Test3      NO              BLANK           YES
+ *     Test4      NO              SET             YES
+ *     Test5      NO              SET             NO
+ *     Test6      YES             SET             NO
+ * </pre>
+ *
+ * @author Ceki Gülcü
+ * @deprecated replaced by  TimeBasedRolling_STest
+ */
+public class TimeBasedRollingDest extends ScaffoldingForRollingTests {
+
+  RollingFileAppender<Object> rfa1 = new RollingFileAppender<Object>();
+  TimeBasedRollingPolicy<Object> tbrp1 = new TimeBasedRollingPolicy<Object>();
+
+  RollingFileAppender<Object> rfa2 = new RollingFileAppender<Object>();
+  TimeBasedRollingPolicy<Object> tbrp2 = new TimeBasedRollingPolicy<Object>();
+
+  @Before
+  @Override
+  public void setUp() {
+    super.setUp();
+  }
+
+  @After
+  public void tearDown() {
+  }
+
+  void initRFA(RollingFileAppender<Object> rfa, String filename) {
+    rfa.setContext(context);
+    rfa.setEncoder(encoder);
+    if (filename != null) {
+      rfa.setFile(filename);
+    }
+  }
+
+  void initTRBP(RollingFileAppender<Object> rfa,
+                TimeBasedRollingPolicy<Object> tbrp, String filenamePattern,
+                long givenTime) {
+    tbrp.setContext(context);
+    tbrp.setFileNamePattern(filenamePattern);
+    tbrp.setParent(rfa);
+    tbrp.timeBasedFileNamingAndTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
+    tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(givenTime);
+    rfa.setRollingPolicy(tbrp);
+    tbrp.start();
+    rfa.start();
+  }
+
+  /**
+   * Test rolling without compression, file option left blank, no stop/start
+   */
+  @Test
+  public void noCompression_FileBlank_NoRestart_1() throws Exception {
+    String testId = "test1";
+    initRFA(rfa1, null);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    // compute the current filename
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-" + testId + "." + i++));
+    }
+  }
+
+  /**
+   * With compression, file option left blank, no stop/restart
+   */
+  @Test
+  public void withCompression_FileBlank_NoRestart_2() throws Exception {
+    String testId = "test2";
+    initRFA(rfa1, null);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
+
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      // when i == 2, file name should not have .gz extension
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, i != 2);
+      rfa1.doAppend("Hello---" + i);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+      waitForCompression(tbrp1);
+    }
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
+      i++;
+    }
+  }
+
+  /**
+   * No compression, file option left blank, with stop/restart,
+   */
+  @Test
+  public void noCompression_FileBlank_StopRestart_3() throws Exception {
+    String testId = "test3";
+
+    initRFA(rfa1, null);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    // a new file is created by virtue of rfa.start();
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    rfa1.stop();
+
+    initRFA(rfa2, null);
+    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", tbrp1.timeBasedFileNamingAndTriggeringPolicy
+            .getCurrentTime());
+
+    for (int i = 0; i <= 2; i++) {
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      rfa2.doAppend("World---" + i);
+      incCurrentTime(100);
+      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-" + testId + "." + i++));
+    }
+  }
+
+  /**
+   * Without compression, file option set, with stop/restart
+   */
+  @Test
+  public void noCompression_FileSet_StopRestart_4() throws Exception {
+    String testId = "test4";
+    initRFA(rfa1, testId2FileName(testId));
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    rfa1.stop();
+
+    // change the timestamp of the currently actively file
+    File activeFile = new File(rfa1.getFile());
+    activeFile.setLastModified(currentTime);
+
+    initRFA(rfa2, testId2FileName(testId));
+    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa2.doAppend("World---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(100);
+      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    System.out.println("Before "+expectedFilenameList);
+    massageExpectedFilesToCorresponToCurrentTarget("test4.log");
+    System.out.println("After "+expectedFilenameList);
+
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-" + testId + "." + i++));
+    }
+  }
+
+  @Test
+  public void noCompression_FileSet_StopRestart_WithLongWait_4B()
+          throws Exception {
+    String testId = "test4B";
+    initRFA(rfa1, testId2FileName(testId));
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    rfa1.stop();
+
+    // change the timestamp of the currently actively file
+    File activeFile = new File(rfa1.getFile());
+    activeFile.setLastModified(currentTime);
+
+    incCurrentTime(2000);
+
+    initRFA(rfa2, randomOutputDir + "test4B.log");
+    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa2.doAppend("World---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(100);
+      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    massageExpectedFilesToCorresponToCurrentTarget("test4B.log");
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-test4B." + i++));
+    }
+
+  }
+
+  /**
+   * No compression, file option set, without stop/restart
+   */
+  @Test
+  public void noCompression_FileSet_NoRestart_5() throws Exception {
+    String testId = "test5";
+
+    initRFA(rfa1, testId2FileName(testId));
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+
+    massageExpectedFilesToCorresponToCurrentTarget("test5.log");
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-test5." + i++));
+    }
+  }
+
+  /**
+   * With compression, file option set, no stop/restart,
+   */
+  @Test
+  public void withCompression_FileSet_NoRestart_6() throws Exception {
+
+    String testId = "test6";
+
+    initRFA(rfa1, testId2FileName(testId));
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
+
+    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, true);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+      waitForCompression(tbrp1);
+    }
+
+    massageExpectedFilesToCorresponToCurrentTarget("test6.log");
+
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
+      i++;
+    }
+  }
+
+  @Test
+  public void withMissingTargetDir() throws Exception {
+    String testId = "missingTargetDir";
+
+    initRFA(rfa1, testId2FileName(testId));
+    int secondDiff = RandomUtil.getPositiveInt();
+    String randomTargetDir = CoreTestConstants.OUTPUT_DIR_PREFIX + secondDiff + '/';
+
+    System.out.println("randomOutputDir"+randomOutputDir);
+    System.out.println("randomTargetDir"+randomTargetDir);
+
+    initTRBP(rfa1, tbrp1, randomTargetDir + testId + "-%d{"
+            + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+    addExpectedFileName_ByDate(randomTargetDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(randomTargetDir, testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
+    }
+    massageExpectedFilesToCorresponToCurrentTarget("missingTargetDir.log");
+    int i = 0;
+    for (String fn : expectedFilenameList) {
+      System.out.println("expectedFile="+fn);
+      assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+              + "witness/rolling/tbr-test5." + i++));
+    }
+
+  }
+
+  // =========================================================================
+  // utility methods
+  // =========================================================================
+
+  void massageExpectedFilesToCorresponToCurrentTarget(String file) {
+    // we added one too many files by date
+    expectedFilenameList.remove(expectedFilenameList.size() - 1);
+    // since file is set, we have to add it
+    addExpectedFileName_ByFile(file);
+  }
+
+  void addExpectedFileName_ByFile(String filenameSuffix) {
+    String fn = randomOutputDir + filenameSuffix;
+    expectedFilenameList.add(fn);
+  }
+}
diff --git a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala
index a428f45..e06ef71 100644
--- a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala
+++ b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala
@@ -8,12 +8,12 @@ import ch.qos.logback.core.encoder.EchoEncoder
 import java.util.concurrent.TimeUnit
 import java.io.{FileFilter, File}
 import collection.mutable.ListBuffer
-import java.util.Calendar
 import ch.qos.logback.core.util.{StatusPrinter, CoreTestConstants}
 import ch.qos.logback.core.CoreConstants._
 import java.util.regex.{Matcher, Pattern}
 import scala.collection.mutable.{Set, HashSet}
 import org.junit.{Ignore, Before, Test}
+import java.util.{Date, Calendar}
 
 /**
  * Created by IntelliJ IDEA.
@@ -61,14 +61,15 @@ class TimeBasedRollingWithArchiveRemoval_STest {
   def genMontlyRollover(maxHistory: Int, simulatedNumberOfPeriods: Int, startInactivity: Int, numInactivityPeriods: Int) {
     slashCount = computeSlashCount(MONTHLY_DATE_PATTERN)
     doRollover(now, randomOutputDir + "clean-%d{" + MONTHLY_DATE_PATTERN + "}.txt", MILLIS_IN_MONTH, maxHistory, simulatedNumberOfPeriods, startInactivity, numInactivityPeriods)
-    check(expectedCountWithoutFolders(maxHistory))
+    StatusPrinter.print(context)
+    check(expectedCountWithoutFoldersWithInactivity(maxHistory, simulatedNumberOfPeriods, startInactivity+numInactivityPeriods))
   }
 
   @Test
   def montlyRollover {
-    genMontlyRollover(maxHistory = 20, simulatedNumberOfPeriods = 20 * 3, startInactivity = 0, numInactivityPeriods = 0)
-    setUp
-    genMontlyRollover(maxHistory = 6, simulatedNumberOfPeriods = 70, startInactivity = 30, numInactivityPeriods = 1)
+//    genMontlyRollover(maxHistory = 20, simulatedNumberOfPeriods = 20 * 3, startInactivity = 0, numInactivityPeriods = 0)
+//    setUp
+//    genMontlyRollover(maxHistory = 6, simulatedNumberOfPeriods = 70, startInactivity = 30, numInactivityPeriods = 1)
     setUp
     genMontlyRollover(maxHistory = 6, simulatedNumberOfPeriods = 10, startInactivity = 3, numInactivityPeriods = 4)
 
@@ -111,7 +112,6 @@ class TimeBasedRollingWithArchiveRemoval_STest {
     var expectedDirMin: Int = 9 + slashCount
     var expectDirMax: Int = expectedDirMin + 1 + 1
     expectedFileAndDirCount(9, expectedDirMin, expectDirMax)
-
   }
 
   @Test def dailySizeBasedRollover {
@@ -181,10 +181,10 @@ class TimeBasedRollingWithArchiveRemoval_STest {
 
   def doRollover(currentTime: Long, fileNamePattern: String, periodDurationInMillis: Long, maxHistory: Int, simulatedNumberOfPeriods: Int, startInactivity: Int = 0, numInactivityPeriods: Int = 0): (Long, Long) = {
     val startTime = currentTime
-    var rfa: RollingFileAppender[AnyRef] = new RollingFileAppender[AnyRef]
+    val rfa: RollingFileAppender[AnyRef] = new RollingFileAppender[AnyRef]
     rfa.setContext(context)
     rfa.setEncoder(encoder)
-    var tbrp: TimeBasedRollingPolicy[AnyRef] = new TimeBasedRollingPolicy[AnyRef]
+    val tbrp: TimeBasedRollingPolicy[AnyRef] = new TimeBasedRollingPolicy[AnyRef]
     tbrp.setContext(context)
     tbrp.setFileNamePattern(fileNamePattern)
     tbrp.setMaxHistory(maxHistory)
@@ -194,22 +194,23 @@ class TimeBasedRollingWithArchiveRemoval_STest {
     tbrp.start
     rfa.setRollingPolicy(tbrp)
     rfa.start
-    var ticksPerPeriod: Int = 512
-    var runLength = simulatedNumberOfPeriods * ticksPerPeriod
+    val ticksPerPeriod: Int = 512
+    val runLength = simulatedNumberOfPeriods * ticksPerPeriod
     val startInactivityIndex: Int = 1 + startInactivity * ticksPerPeriod
-    val endInactivityIndex = startInactivity + numInactivityPeriods * ticksPerPeriod
-
+    val endInactivityIndex = startInactivityIndex + numInactivityPeriods * ticksPerPeriod
+    val tickDuration = periodDurationInMillis / ticksPerPeriod
 
     for (i <- 0 to runLength) {
       if (i < startInactivityIndex || i > endInactivityIndex) {
         rfa.doAppend("Hello ----------------------------------------------------------" + i)
       }
-      tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(addTime(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime, periodDurationInMillis / ticksPerPeriod))
+      tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(addTime(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime, tickDuration))
       if (i % (ticksPerPeriod / 2) == 0) {
         waitForCompression(tbrp)
       }
     }
 
+    println("Last date"+new Date(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime()));
     waitForCompression(tbrp)
     rfa.stop
     (startTime, tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime)
@@ -219,10 +220,16 @@ class TimeBasedRollingWithArchiveRemoval_STest {
     return maxHistory + 1
   }
 
+  def expectedCountWithoutFoldersWithInactivity(maxHistory: Int, totalPeriods: Int, endOfInactivity: Int): Int = {
+    val availableHistory = totalPeriods - endOfInactivity;
+    val actualHistory =  scala.math.min(availableHistory, maxHistory+1)
+    return actualHistory
+  }
+
 
   def genericFindMatching(matchFunc: (File, String) => Boolean, dir: File, fileList: ListBuffer[File], pattern: String = null, includeDirs: Boolean = false) {
     if (dir.isDirectory) {
-      var `match` : Array[File] = dir.listFiles(new FileFilter {
+      val `match` : Array[File] = dir.listFiles(new FileFilter {
         def accept(f: File): Boolean = {
           return f.isDirectory() || matchFunc(f, pattern)
         }
@@ -251,8 +258,8 @@ class TimeBasedRollingWithArchiveRemoval_STest {
 
 
   def expectedFileAndDirCount(expectedFileAndDirCount: Int, expectedDirCountMin: Int, expectedDirCountMax: Int): Unit = {
-    var dir: File = new File(randomOutputDir)
-    var fileList = new ListBuffer[File]
+    val dir: File = new File(randomOutputDir)
+    val fileList = new ListBuffer[File]
     findFilesInFolderRecursivelyByPatterMatch(dir, fileList, "clean")
     var dirList = new ListBuffer[File]
     findAllFoldersInFolderRecursively(dir, dirList)
@@ -260,14 +267,14 @@ class TimeBasedRollingWithArchiveRemoval_STest {
   }
 
   def check(expectedCount: Int): Unit = {
-    var dir: File = new File(randomOutputDir)
+    val dir: File = new File(randomOutputDir)
     val fileList = new ListBuffer[File]
     findAllDirsOrStringContainsFilesRecursively(dir, fileList, "clean")
     assertEquals(expectedCount, fileList.size)
   }
 
   def groupByClass(fileList: ListBuffer[File], regex: String): Set[String] = {
-    var p: Pattern = Pattern.compile(regex)
+    val p: Pattern = Pattern.compile(regex)
     val set = new HashSet[String]
     for (f <- fileList) {
       var n: String = f.getName
@@ -281,16 +288,16 @@ class TimeBasedRollingWithArchiveRemoval_STest {
   }
 
   def checkPatternCompliance(expectedClassCount: Int, regex: String) {
-    var dir: File = new File(randomOutputDir)
-    var fileList = new ListBuffer[File]
+    val dir: File = new File(randomOutputDir)
+    val fileList = new ListBuffer[File]
     findFilesInFolderRecursivelyByPatterMatch(dir, fileList, regex)
-    var set: Set[String] = groupByClass(fileList, regex)
+    val set: Set[String] = groupByClass(fileList, regex)
     assertEquals(expectedClassCount, set.size)
   }
 
   def checkDirPatternCompliance(expectedClassCount: Int): Unit = {
-    var dir: File = new File(randomOutputDir)
-    var fileList = new ListBuffer[File]
+    val dir: File = new File(randomOutputDir)
+    val fileList = new ListBuffer[File]
     findAllFoldersInFolderRecursively(dir, fileList)
     for (f <- fileList) {
       assertTrue(f.list.length >= 1)
diff --git a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling_STest.scala b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling_STest.scala
index 78a75c7..b7dffd1 100644
--- a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling_STest.scala
+++ b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling_STest.scala
@@ -44,7 +44,8 @@ class TimeBasedRolling_STest extends RollingScaffolding {
     }
   }
 
- private def initTRBP(rfa: RollingFileAppender[AnyRef], tbrp: TimeBasedRollingPolicy[AnyRef], filenamePattern: String, givenTime: Long): Unit = {
+ private def initTRBP(rfa: RollingFileAppender[AnyRef], tbrp: TimeBasedRollingPolicy[AnyRef],
+                      filenamePattern: String, givenTime: Long): Unit = {
     tbrp.setContext(context)
     tbrp.setFileNamePattern(filenamePattern)
     tbrp.setParent(rfa)
@@ -109,7 +110,6 @@ class TimeBasedRolling_STest extends RollingScaffolding {
     val witnessFileName: String = CoreTestConstants.TEST_DIR_PREFIX + "witness/rolling/tbr-" + testId
     println(lastFile+"  "+witnessFileName)
     assertTrue(Compare.compare(lastFile, witnessFileName));
-
   }
 
 
@@ -179,7 +179,6 @@ class TimeBasedRolling_STest extends RollingScaffolding {
 
   @Test
   def failed_rename: Unit = {
-
     if(!Env.isWindows) null
 
     var fos: FileOutputStream = null

-----------------------------------------------------------------------

Summary of changes:
 ...aultTimeBasedFileNamingAndTriggeringPolicy.java |    1 +
 ...dRollingTest.java => TimeBasedRollingDest.java} |  823 ++++++++++----------
 .../TimeBasedRollingWithArchiveRemoval_STest.scala |   53 +-
 .../core/rolling/TimeBasedRolling_STest.scala      |    5 +-
 4 files changed, 445 insertions(+), 437 deletions(-)
 rename logback-core/src/test/java/ch/qos/logback/core/rolling/{TimeBasedRollingTest.java => TimeBasedRollingDest.java} (96%)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list