[logback-dev] svn commit: r2378 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/spi test/java/ch/qos/logback/core/rolling

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Jul 30 14:12:29 CEST 2009


Author: ceki
Date: Thu Jul 30 14:12:28 2009
New Revision: 2378

Added:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
      - copied, changed from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
      - copied, changed from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java
Removed:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java
Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java

Log:
	

Further refactoring of TimeBasedRollingPolicy. Most of the work
related to triggering has moved into an interface called
TimedBasedFileNamingAndTriggeringPolicy. Related to LBCORE-61.

The file attribute in RollingFileAppender is honored once again. This
reverts the changes in revision 2376. Relevant tests in
TimeBasedRollingTest have been resuscitated.
	

Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java (from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java	Thu Jul 30 14:12:28 2009
@@ -4,98 +4,118 @@
 import java.util.Date;
 
 import ch.qos.logback.core.rolling.helper.DateTokenConverter;
-import ch.qos.logback.core.rolling.helper.FileNamePattern;
 import ch.qos.logback.core.rolling.helper.RollingCalendar;
 import ch.qos.logback.core.spi.ContextAwareBase;
 
-public class DefaultTimeBasedTriggeringPolicy<E> extends ContextAwareBase
-    implements NamingAndTriggeringPolicy<E> {
+public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends ContextAwareBase
+    implements TimeBasedFileNamingAndTriggeringPolicy<E> {
 
-  FileNamePattern fileNamePattern;
-  String elapsedPeriodsFileName;
-  FileNamePattern activeFileNamePattern;
-  RollingCalendar rc;
-  long currentTime;
-  long nextCheck;
+  private TimeBasedRollingPolicy<E> tbrp;
+  private String elapsedPeriodsFileName;
+  private RollingCalendar rc;
+  private long currentTime;
+  private long nextCheck;
   // indicate whether the time has been forced or not
-  boolean isTimeForced = false;
-  Date lastCheck = null;
+  private boolean isTimeForced = false;
+  private Date dateInCurrentPeriod = null;
   boolean started = false;
 
-  public void setCurrentTime(long timeInMillis) {
-    currentTime = timeInMillis;
-    isTimeForced = true;
-  }
-
-  public long getCurrentTime() {
-    // if time is forced return the time set by user
-    if (isTimeForced) {
-      return currentTime;
-    } else {
-      return System.currentTimeMillis();
-    }
-  }
-
   public boolean isStarted() {
     return started;
   }
 
   public void start() {
 
-    DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
+    DateTokenConverter dtc = tbrp.fileNamePattern.getDateTokenConverter();
 
     if (dtc == null) {
       throw new IllegalStateException("FileNamePattern ["
-          + fileNamePattern.getPattern()
+          + tbrp.fileNamePattern.getPattern()
           + "] does not contain a valid DateToken");
     }
 
     rc = new RollingCalendar();
     rc.init(dtc.getDatePattern());
     addInfo("The date pattern is '" + dtc.getDatePattern()
-        + "' from file name pattern '" + fileNamePattern.getPattern() + "'.");
+        + "' from file name pattern '" + tbrp.fileNamePattern.getPattern()
+        + "'.");
     rc.printPeriodicity(this);
 
-    // lastCheck can be set by test classes
+    // dateInCurrentPeriod can be set by test classes
     // if it has not been set, we set it here
-    if (lastCheck == null) {
-      lastCheck = new Date();
-      lastCheck.setTime(getCurrentTime());
+    if (dateInCurrentPeriod == null) {
+      dateInCurrentPeriod = new Date();
+      updateDateInCurrentPeriod(getCurrentTime());
     }
-    nextCheck = rc.getNextTriggeringMillis(lastCheck);
-
+    computeNextCheck();
   }
-
+  
   public void stop() {
     started = false;
   }
+  
+  private void computeNextCheck() {
+    nextCheck = rc.getNextTriggeringMillis(dateInCurrentPeriod);
+  }
 
-  // allow Test classes to act on the lastCheck field to simulate old
+  // allow Test classes to act on the dateInCurrentPeriod field to simulate old
   // log files needing rollover
-  void setLastCheck(Date _lastCheck) {
-    this.lastCheck = _lastCheck;
+  public void setDateInCurrentPeriod(Date _dateInCurrentPeriod) {
+    this.dateInCurrentPeriod = _dateInCurrentPeriod;
+  }
+
+  public Date getDateInCurrentPeriod() {
+    return dateInCurrentPeriod;
   }
 
   public String getElapsedPeriodsFileName() {
     return elapsedPeriodsFileName;
   }
 
+  public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
+    return tbrp.fileNamePatternWCS.convertDate(dateInCurrentPeriod);
+  }
+
   public boolean isTriggeringEvent(File activeFile, final E event) {
     long time = getCurrentTime();
 
     if (time >= nextCheck) {
-      // We set the elapsedPeriodsFileName before we set the 'lastCheck'
-      // variable
-      // The elapsedPeriodsFileName corresponds to the file name of the period
-      // that just elapsed.
-      elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
-
-      lastCheck.setTime(time);
-      nextCheck = rc.getNextTriggeringMillis(lastCheck);
+      Date dateInElapsedPeriod = dateInCurrentPeriod;
+      elapsedPeriodsFileName = tbrp.fileNamePatternWCS
+          .convertDate(dateInElapsedPeriod);
+      updateDateInCurrentPeriod(time);
+      computeNextCheck();
       return true;
     } else {
       return false;
     }
   }
 
+  private void updateDateInCurrentPeriod(long now) {
+    dateInCurrentPeriod.setTime(now);
+  }
+
+  public void setCurrentTime(long timeInMillis) {
+    currentTime = timeInMillis;
+    isTimeForced = true;
+  }
+
+  public long getCurrentTime() {
+    // if time is forced return the time set by user
+    if (isTimeForced) {
+      return currentTime;
+    } else {
+      return System.currentTimeMillis();
+    }
+  }
+  
+  public void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> _tbrp) {
+    this.tbrp = _tbrp;
+
+  }
+
+  public RollingCalendar getRollingCalendar() {
+    return rc;
+  }
+
 }

Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java (from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java	Thu Jul 30 14:12:28 2009
@@ -10,7 +10,73 @@
 
 package ch.qos.logback.core.rolling;
 
-public interface NamingAndTriggeringPolicy<E> extends TriggeringPolicy<E> {
+import java.util.Date;
 
+import ch.qos.logback.core.rolling.helper.RollingCalendar;
+import ch.qos.logback.core.spi.ContextAware;
+
+/**
+ * This interface lists the set of methods that need to be implemented by
+ * triggering policies which are nested within a {@link TimeBasedRollingPolicy}.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ * 
+ * @param <E>
+ */
+public interface TimeBasedFileNamingAndTriggeringPolicy<E> extends
+    TriggeringPolicy<E>, ContextAware {
+
+  /**
+   * Set the host/parent {@link TimeBasedRollingPolicy}.
+   * 
+   * @param the
+   *                parent TimeBasedRollingPolicy
+   */
+  void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> tbrp);
+
+  /**
+   * Return the file name for the elapsed periods file name.
+   * 
+   * @return
+   */
   String getElapsedPeriodsFileName();
+
+  /**
+   * Return the current periods file name without the compression suffix. This
+   * value is equivalent to the active file name.
+   * 
+   * @return current period's file name (without compression suffix)
+   */
+  String getCurrentPeriodsFileNameWithoutCompressionSuffix();
+
+  /**
+   * Return the rolling calendar used by this instance.
+   * 
+   * @return
+   */
+  RollingCalendar getRollingCalendar();
+
+  /**
+   * Return the current time which is usually the value returned by
+   * System.currentMillis(). However, for <b>testing</b> purposed this value
+   * may be different than the real time.
+   * 
+   * @return current time value
+   */
+  long getCurrentTime();
+
+  /**
+   * Set the current time. Only unit tests should invoke this method.
+   * 
+   * @param now
+   */
+  void setCurrentTime(long now);
+
+  /**
+   * Set some date in the current period. Only unit tests should invoke this
+   * method.
+   * 
+   * @param date
+   */
+  void setDateInCurrentPeriod(Date date);
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java	Thu Jul 30 14:12:28 2009
@@ -1,7 +1,7 @@
 /**
  * Logback: the reliable, generic, fast and flexible logging framework.
  * 
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 1999-2009, QOS.ch
  * 
  * This library is free software, you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free
@@ -36,40 +36,28 @@
   static final String FNP_NOT_SET = "The FileNamePattern option must be set before using TimeBasedRollingPolicy. ";
   static final int NO_DELETE_HISTORY = 0;
 
-  FileNamePattern activeFileNamePattern;
-  Compressor compressor;
-  RenameUtil renameUtil = new RenameUtil();
+  // WCS: without compression suffix
+  FileNamePattern fileNamePatternWCS;
+  
+  private Compressor compressor;
+  private RenameUtil renameUtil = new RenameUtil();
   Future<?> future;
 
-  int maxHistory = NO_DELETE_HISTORY;
-  TimeBasedCleaner tbCleaner;
+  private int maxHistory = NO_DELETE_HISTORY;
+  private TimeBasedCleaner tbCleaner;
 
-  DefaultTimeBasedTriggeringPolicy<E> timeBasedTriggering = new DefaultTimeBasedTriggeringPolicy<E>();
-  
-//  public void setCurrentTime(long timeInMillis) {
-//    currentTime = timeInMillis;
-//    isTimeForced = true;
-//  }
-//
-//  public long getCurrentTime() {
-//    // if time is forced return the time set by user
-//    if (isTimeForced) {
-//      return currentTime;
-//    } else {
-//      return System.currentTimeMillis();
-//    }
-//  }
+  TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();
 
   public void start() {
     // set the LR for our utility object
     renameUtil.setContext(this.context);
 
     timeBasedTriggering.setContext(context);
+    timeBasedTriggering.setTimeBasedRollingPolicy(this);
     
     // find out period from the filename pattern
     if (fileNamePatternStr != null) {
       fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context);
-      timeBasedTriggering.fileNamePattern = fileNamePattern;
       determineCompressionMode();
     } else {
       addWarn(FNP_NOT_SET);
@@ -78,54 +66,45 @@
           + CoreConstants.SEE_FNP_NOT_SET);
     }
 
-    
     compressor = new Compressor(compressionMode);
     compressor.setContext(context);
 
-    int len = fileNamePatternStr.length();
-    switch (compressionMode) {
-    case GZ:
-      activeFileNamePattern = new FileNamePattern(fileNamePatternStr.substring(
-          0, len - 3), this.context);
-      ;
-      break;
-    case ZIP:
-      activeFileNamePattern = new FileNamePattern(fileNamePatternStr.substring(
-          0, len - 4), this.context);
-      break;
-    case NONE:
-      activeFileNamePattern = fileNamePattern;
-    }
-    
-    addInfo("Will use the pattern " + activeFileNamePattern
+    fileNamePatternWCS = new FileNamePattern(computeFileNameStr_WCS(fileNamePatternStr,
+        compressionMode), this.context);
+
+    addInfo("Will use the pattern " + fileNamePatternWCS
         + " for the active file");
 
-    timeBasedTriggering.activeFileNamePattern = activeFileNamePattern;
     timeBasedTriggering.start();
-    
+
     if (maxHistory != NO_DELETE_HISTORY) {
-      tbCleaner = new TimeBasedCleaner(fileNamePattern, timeBasedTriggering.rc, maxHistory);
+      tbCleaner = new TimeBasedCleaner(fileNamePattern, timeBasedTriggering.getRollingCalendar(),
+          maxHistory);
     }
   }
 
-
-  public long getCurrentTime() {
-    return timeBasedTriggering.getCurrentTime();
-  }
-  public void setCurrentTime(long timeInMillis) {
-    timeBasedTriggering.setCurrentTime(timeInMillis);
-  }
-  void setLastCheck(Date _lastCheck) {
-    timeBasedTriggering.setLastCheck(_lastCheck);
+  static String computeFileNameStr_WCS(String fileNamePatternStr,
+      CompressionMode compressionMode) {
+    int len = fileNamePatternStr.length();
+    switch (compressionMode) {
+    case GZ:
+      return fileNamePatternStr.substring(0, len - 3);
+    case ZIP:
+      return fileNamePatternStr.substring(0, len - 4);
+    case NONE:
+      return fileNamePatternStr;
+    }
+    throw new IllegalStateException("Execution should not reach this point");
   }
-  
+
   public void rollover() throws RolloverFailure {
 
     // when rollover is called the elapsed period's file has
     // been already closed. This is a working assumption of this method.
 
-    String elapsedPeriodsFileName = timeBasedTriggering.getElapsedPeriodsFileName();
-    
+    String elapsedPeriodsFileName = timeBasedTriggering
+        .getElapsedPeriodsFileName();
+
     if (compressionMode == CompressionMode.NONE) {
       if (getParentsRawFileProperty() != null) {
         renameUtil.rename(getParentsRawFileProperty(), elapsedPeriodsFileName);
@@ -143,14 +122,14 @@
     }
   }
 
-  Future asyncCompress(String nameOfFile2Compress,
-      String nameOfCompressedFile) throws RolloverFailure {
+  Future asyncCompress(String nameOfFile2Compress, String nameOfCompressedFile)
+      throws RolloverFailure {
     AsynchronousCompressor ac = new AsynchronousCompressor(compressor);
-    return ac.compressAsynchronously(nameOfFile2Compress,
-        nameOfCompressedFile);
+    return ac.compressAsynchronously(nameOfFile2Compress, nameOfCompressedFile);
   }
 
-  Future renamedRawAndAsyncCompress(String nameOfCompressedFile) throws RolloverFailure {
+  Future renamedRawAndAsyncCompress(String nameOfCompressedFile)
+      throws RolloverFailure {
     String parentsRawFile = getParentsRawFileProperty();
     String tmpTarget = parentsRawFile + System.nanoTime() + ".tmp";
     renameUtil.rename(parentsRawFile, tmpTarget);
@@ -178,35 +157,16 @@
    * 
    */
   public String getActiveFileName() {
-    
-      return activeFileNamePattern.convertDate(timeBasedTriggering.lastCheck);
-    
+    String parentsRawFileProperty = getParentsRawFileProperty();
+    if (parentsRawFileProperty != null) {
+      return parentsRawFileProperty;
+    } else {
+      return timeBasedTriggering.getCurrentPeriodsFileNameWithoutCompressionSuffix();
+    }
   }
 
-//  // get the active file name for the current (latest) period
-//  private String getLatestPeriodsFileName() {
-//    return activeFileNamePattern.convertDate(lastCheck);
-//  }
-
   public boolean isTriggeringEvent(File activeFile, final E event) {
-    
     return timeBasedTriggering.isTriggeringEvent(activeFile, event);
-    
-//    long time = getCurrentTime();
-//
-//    if (time >= nextCheck) {
-//      // We set the elapsedPeriodsFileName before we set the 'lastCheck'
-//      // variable
-//      // The elapsedPeriodsFileName corresponds to the file name of the period
-//      // that just elapsed.
-//      elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
-//
-//      lastCheck.setTime(time);
-//      nextCheck = rc.getNextTriggeringMillis(lastCheck);
-//      return true;
-//    } else {
-//      return false;
-//    }
   }
 
   /**
@@ -232,5 +192,4 @@
   public String toString() {
     return "c.q.l.core.rolling.TimeBasedRollingPolicy";
   }
-
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java	Thu Jul 30 14:12:28 2009
@@ -1,11 +1,11 @@
 /**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2009, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
  */
 package ch.qos.logback.core.spi;
 

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java	Thu Jul 30 14:12:28 2009
@@ -108,9 +108,9 @@
     tbrp.setContext(context);
     tbrp.setFileNamePattern(filenamePattern);
     tbrp.setParent(rfa);
-    tbrp.setCurrentTime(givenTime);
+    tbrp.timeBasedTriggering.setCurrentTime(givenTime);
     if (lastCheck != 0) {
-      tbrp.setLastCheck(new Date(lastCheck));
+      tbrp.timeBasedTriggering.setDateInCurrentPeriod(new Date(lastCheck));
     }
     rfa.setRollingPolicy(tbrp);
     tbrp.start();
@@ -131,13 +131,13 @@
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
 
     incCurrentTime(1100);
-    tbrp1.setCurrentTime(currentTime);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
 
     for (int i = 0; i < 3; i++) {
       rfa1.doAppend("Hello---" + i);
       addExpectedFileNamedIfItsTime_ByDate(testId, false);
       incCurrentTime(500);
-      tbrp1.setCurrentTime(currentTime);
+      tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
     }
 
     int i = 0;
@@ -159,14 +159,14 @@
 
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
     incCurrentTime(1100);
-    tbrp1.setCurrentTime(currentTime);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
 
     for (int i = 0; i < 3; i++) {
       // when i == 2, file name should not have .gz extension
       addExpectedFileNamedIfItsTime_ByDate(testId, i != 2);
       rfa1.doAppend("Hello---" + i);
       incCurrentTime(500);
-      tbrp1.setCurrentTime(currentTime);
+      tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
     }
 
     tbrp1.future.get(2000, TimeUnit.MILLISECONDS);
@@ -194,26 +194,26 @@
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
 
     incCurrentTime(1100);
-    tbrp1.setCurrentTime(currentTime);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
 
     for (int i = 0; i <= 2; i++) {
       rfa1.doAppend("Hello---" + i);
       addExpectedFileNamedIfItsTime_ByDate(testId, false);
       incCurrentTime(500);
-      tbrp1.setCurrentTime(currentTime);
+      tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
     }
 
     rfa1.stop();
 
     initRFA(rfa2, null);
     initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", tbrp1.getCurrentTime(), 0);
+        + DATE_PATTERN + "}", tbrp1.timeBasedTriggering.getCurrentTime(), 0);
 
     for (int i = 0; i <= 2; i++) {
       addExpectedFileNamedIfItsTime_ByDate(testId, false);
       rfa2.doAppend("World---" + i);
       incCurrentTime(100);
-      tbrp2.setCurrentTime(currentTime);
+      tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
     }
 
     int i = 0;
@@ -222,165 +222,165 @@
           + "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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-//        + DATE_PATTERN + "}", currentTime, 0);
-//
-//    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-//
-//    incCurrentTime(1100);
-//    tbrp1.setCurrentTime(currentTime);
-//
-//    for (int i = 0; i <= 2; i++) {
-//      rfa1.doAppend("Hello---" + i);
-//      addExpectedFileNamedIfItsTime_ByDate(testId, false);
-//      incCurrentTime(500);
-//      tbrp1.setCurrentTime(currentTime);
-//    }
-//
-//    rfa1.stop();
-//
-//    initRFA(rfa2, testId2FileName(testId));
-//    initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-//        + DATE_PATTERN + "}", currentTime, currentTime);
-//
-//    for (int i = 0; i <= 2; i++) {
-//      rfa2.doAppend("World---" + i);
-//      addExpectedFileNamedIfItsTime_ByDate(testId, false);
-//      incCurrentTime(100);
-//      tbrp2.setCurrentTime(currentTime);
-//    }
-//
-//    massageExpectedFilesToCorresponToCurrentTarget("test4.log");
-//
-//    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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-//        + DATE_PATTERN + "}", currentTime, 0);
-//
-//    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-//
-//    incCurrentTime(1100);
-//    tbrp1.setCurrentTime(currentTime);
-//
-//    for (int i = 0; i <= 2; i++) {
-//      rfa1.doAppend("Hello---" + i);
-//      addExpectedFileNamedIfItsTime_ByDate(testId, false);
-//      incCurrentTime(500);
-//      tbrp1.setCurrentTime(currentTime);
-//    }
-//
-//    rfa1.stop();
-//
-//    long fileTimestamp = currentTime;
-//    incCurrentTime(2000);
-//
-//    initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
-//    initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
-//        + DATE_PATTERN + "}", currentTime, fileTimestamp);
-//
-//    for (int i = 0; i <= 2; i++) {
-//      rfa2.doAppend("World---" + i);
-//      addExpectedFileNamedIfItsTime_ByDate(testId, false);
-//      incCurrentTime(100);
-//      tbrp2.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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-//        + DATE_PATTERN + "}", currentTime, 0);
-//
-//    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-//
-//    incCurrentTime(1100);
-//    tbrp1.setCurrentTime(currentTime);
-//
-//    for (int i = 0; i < 3; i++) {
-//      rfa1.doAppend("Hello---" + i);
-//      addExpectedFileNamedIfItsTime_ByDate(testId, false);
-//      incCurrentTime(500);
-//      tbrp1.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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-//        + DATE_PATTERN + "}.gz", currentTime, 0);
-//
-//    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
-//
-//    incCurrentTime(1100);
-//    tbrp1.setCurrentTime(currentTime);
-//
-//    for (int i = 0; i < 3; i++) {
-//      rfa1.doAppend("Hello---" + i);
-//      addExpectedFileNamedIfItsTime_ByDate(testId, true);
-//      incCurrentTime(500);
-//      tbrp1.setCurrentTime(currentTime);
-//    }
-//
-//    // wait for the compression task to finish
-//    tbrp1.future.get(1000, TimeUnit.MILLISECONDS);
-//
-//    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++;
-//    }
-//  }
+  
+  /**
+   * 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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+        + DATE_PATTERN + "}", currentTime, 0);
+
+    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+    }
+
+    rfa1.stop();
+
+    initRFA(rfa2, testId2FileName(testId));
+    initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+        + DATE_PATTERN + "}", currentTime, currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa2.doAppend("World---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(testId, false);
+      incCurrentTime(100);
+      tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
+    }
+
+    massageExpectedFilesToCorresponToCurrentTarget("test4.log");
+
+    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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+        + DATE_PATTERN + "}", currentTime, 0);
+
+    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+    }
+
+    rfa1.stop();
+
+    long fileTimestamp = currentTime;
+    incCurrentTime(2000);
+
+    initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
+    initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
+        + DATE_PATTERN + "}", currentTime, fileTimestamp);
+
+    for (int i = 0; i <= 2; i++) {
+      rfa2.doAppend("World---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(testId, false);
+      incCurrentTime(100);
+      tbrp2.timeBasedTriggering.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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+        + DATE_PATTERN + "}", currentTime, 0);
+
+    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(testId, false);
+      incCurrentTime(500);
+      tbrp1.timeBasedTriggering.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, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+        + DATE_PATTERN + "}.gz", currentTime, 0);
+
+    addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
+
+    incCurrentTime(1100);
+    tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+    for (int i = 0; i < 3; i++) {
+      rfa1.doAppend("Hello---" + i);
+      addExpectedFileNamedIfItsTime_ByDate(testId, true);
+      incCurrentTime(500);
+      tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+    }
+
+    // wait for the compression task to finish
+    tbrp1.future.get(1000, TimeUnit.MILLISECONDS);
+
+    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++;
+    }
+  }
 
   // =========================================================================
   // utility methods

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java	Thu Jul 30 14:12:28 2009
@@ -78,14 +78,14 @@
 
     tbrp.setMaxHistory(maxHistory);
     tbrp.setParent(rfa);
-    tbrp.setCurrentTime(currentTime);
+    tbrp.timeBasedTriggering.setCurrentTime(currentTime);
     tbrp.start();
     rfa.setRollingPolicy(tbrp);
     rfa.start();
 
     for (int i = 0; i < maxHistory * 3; i++) {
       rfa.doAppend("Hello---" + i);
-      tbrp.setCurrentTime(addTime(tbrp.getCurrentTime(), delay / 2));
+      tbrp.timeBasedTriggering.setCurrentTime(addTime(tbrp.timeBasedTriggering.getCurrentTime(), delay / 2));
       if (tbrp.future != null) {
         tbrp.future.get(200, TimeUnit.MILLISECONDS);
       }


More information about the logback-dev mailing list