[logback-dev] svn commit: r2402 - in logback/trunk: logback-classic/src/test/input/joran/rolling logback-classic/src/test/java/ch/qos/logback/classic/rolling logback-core/src/main/java/ch/qos/logback/core/rolling logback-core/src/test/java/ch/qos/logback/core/rolling

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Jul 31 21:30:53 CEST 2009


Author: ceki
Date: Fri Jul 31 21:30:53 2009
New Revision: 2402

Added:
   logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml
Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java

Log:
on going testing

Added: logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml	Fri Jul 31 21:30:53 2009
@@ -0,0 +1,26 @@
+<configuration>
+
+  <appender name="ROLLING"
+    class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <File>${randomOutputDir}z${testId}</File>
+    <rollingPolicy
+      class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+      <FileNamePattern>
+        ${randomOutputDir}${testId}-%d{yyyy-MM-dd_HH_mm_ss}.%i
+      </FileNamePattern>
+      <TimeBasedFileNamingAndTriggeringPolicy
+        class="ch.qos.logback.core.rolling.SizeAndTimeBasedFileNamingAndTriggeringPolicy">
+        <MaxFileSize>20</MaxFileSize>
+      </TimeBasedFileNamingAndTriggeringPolicy>
+    </rollingPolicy>
+    <layout>
+      <Pattern>%msg%n</Pattern>
+    </layout>
+  </appender>
+
+
+  <root level="debug">
+    <appender-ref ref="ROLLING" />
+  </root>
+
+</configuration>

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java	Fri Jul 31 21:30:53 2009
@@ -1,5 +1,9 @@
 package ch.qos.logback.classic.rolling;
 
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -14,13 +18,18 @@
 import ch.qos.logback.core.rolling.ScaffoldingForRollingTests;
 import ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicy;
 import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
+import ch.qos.logback.core.status.StatusChecker;
+import ch.qos.logback.core.util.StatusPrinter;
 
 public class TimeBasedRollingWithConfigFileTest extends
     ScaffoldingForRollingTests {
 
   LoggerContext lc = new LoggerContext();
   Logger logger = lc.getLogger(this.getClass());
-
+  int fileSize = 0;
+  int fileIndexCounter = 0;
+  int sizeThreshold;
+  
   @Before
   @Override
   public void setUp() {
@@ -45,7 +54,10 @@
   public void basic() throws Exception {
     String testId = "basic";
     lc.putProperty("testId", testId);
-    loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/basic.xml");
+    loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/"+testId+".xml");
+    StatusChecker sc = new StatusChecker(lc);
+    assertTrue(sc.isErrorFree());
+    
     Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
     
     expectedFilenameList.add(randomOutputDir+"z"+testId);
@@ -56,7 +68,9 @@
     TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
         .getTriggeringPolicy();
     TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp.getTimeBasedFileNamingAndTriggeringPolicy();
-     
+    
+
+    
     String prefix = "Hello---";
     int runLength = 4;
     for (int i = 0; i < runLength; i++) {
@@ -70,6 +84,79 @@
     sortedContentCheck(randomOutputDir, runLength, prefix); 
   }
   
+  @Test
+  public void timeAndSize() throws Exception {
+    String testId = "timeAndSize";
+    lc.putProperty("testId", testId);
+    loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/"+testId+".xml");
+    Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
+    
+    expectedFilenameList.add(randomOutputDir+"z"+testId);
+    
+    RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root
+        .getAppender("ROLLING");
+
+    StatusPrinter.print(lc);
+    StatusChecker sc = new StatusChecker(lc);
+    assertTrue(sc.isErrorFree());
+
+    
+    TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
+        .getTriggeringPolicy();
+    TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp.getTimeBasedFileNamingAndTriggeringPolicy();
+    
+
+    
+    String prefix = "Hello---";
+    int runLength = 4;
+    for (int i = 0; i < runLength; i++) {
+      String msg = prefix + i;
+      logger.debug(msg);
+      addExpectedFileNamedIfItsTime(testId, msg, false);
+      incCurrentTime(500);
+      tbnatp.setCurrentTime(currentTime);
+    }
+
+    System.out.println(expectedFilenameList);
+    existenceCheck(expectedFilenameList);
+    sortedContentCheck(randomOutputDir, runLength, prefix); 
+  }
+ 
+ 
+  void addExpectedFileNamedIfItsTime(String testId, String msg,
+      boolean gzExtension) {
+    fileSize += msg.getBytes().length;
+
+    if (passThresholdTime(nextRolloverThreshold)) {
+      fileIndexCounter = 0;
+      fileSize = 0;
+      addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
+          fileIndexCounter, gzExtension);
+      recomputeRolloverThreshold(currentTime);
+      return;
+    }
+
+    // windows can delay file size changes, so we only allow for
+    // fileIndexCounter 0 and 1
+    if ((fileIndexCounter < 1) && fileSize > sizeThreshold) {
+      addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
+          ++fileIndexCounter, gzExtension);
+      fileSize = 0;
+      return;
+    }
+  }
+
+  void addExpectedFileName(String testId, Date date, int fileIndexCounter,
+      boolean gzExtension) {
+
+    String fn = randomOutputDir + testId + "-" + SDF.format(date) + "-"
+        + fileIndexCounter;
+    if (gzExtension) {
+      fn += ".gz";
+    }
+    expectedFilenameList.add(fn);
+  }
+  
   @Override
   protected void addExpectedFileNamedIfItsTime_ByDate(String testId, boolean gzExtension) {
     if (passThresholdTime(nextRolloverThreshold)) {

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java	Fri Jul 31 21:30:53 2009
@@ -12,8 +12,10 @@
 import java.io.File;
 import java.util.Date;
 
+import ch.qos.logback.core.joran.spi.NoAutoStart;
 import ch.qos.logback.core.util.FileSize;
 
+ at NoAutoStart
 public class SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> extends
     TimeBasedFileNamingAndTriggeringPolicyBase<E> {
 

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java	Fri Jul 31 21:30:53 2009
@@ -130,7 +130,7 @@
     currentTime += increment;
   }
 
-  Date getDateOfCurrentPeriodsStart() {
+  protected Date getDateOfCurrentPeriodsStart() {
     long delta = currentTime % 1000;
     return new Date(currentTime - delta);
   }

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java	Fri Jul 31 21:30:53 2009
@@ -146,7 +146,6 @@
       fileSize = 0;
       return;
     }
-
   }
 
   void addExpectedFileName(String testId, Date date, int fileIndexCounter,


More information about the logback-dev mailing list