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

noreply.jncharpin at qos.ch noreply.jncharpin at qos.ch
Fri Apr 13 13:05:06 CEST 2007


Author: jncharpin
Date: Fri Apr 13 13:05:05 2007
New Revision: 1509

Removed:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SubTimeBasedRollingPolicy.java
Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java

Log:
SubTimeBasedRollingPolicy which was used to run the test faster has been deleted. Current time can now be set into TimeBasedRollingPolicy.

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	Fri Apr 13 13:05:05 2007
@@ -35,7 +35,10 @@
   static final String SEE_FNP_NOT_SET =
     "See also http://logback.qos.ch/codes.html#tbr_fnp_not_set";
   RollingCalendar rc;
+  long currentTime;
   long nextCheck;
+  //indicate whether the time has been forced or not
+  boolean isTimeForced=false;
   Date lastCheck = new Date();
   String elapsedPeriodsFileName;
   FileNamePattern activeFileNamePattern;
@@ -43,6 +46,21 @@
   Compress compress = new Compress();
   String lastGeneratedFileName;
   
+  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 start() {
     // set the LR for our utility object
     util.setContext(this.context);
@@ -88,8 +106,8 @@
         fileNamePattern.getPattern()+"'.");
     rc.printPeriodicity(this);
 
-    long n = System.currentTimeMillis();
-    lastCheck.setTime(n);
+    //currentTime = System.currentTimeMillis();
+    lastCheck.setTime(getCurrentTime());
     nextCheck = rc.getNextCheckMillis(lastCheck);
 
     //Date nc = new Date();
@@ -168,9 +186,9 @@
   }
 
   public boolean isTriggeringEvent(File activeFile, final Object event) {
-    long n = System.currentTimeMillis();
+    //currentTime= System.currentTimeMillis();
 
-    if (n >= nextCheck) {
+    if (getCurrentTime() >= nextCheck) {
       //addInfo("Time to trigger roll-over");
       // We set the elapsedPeriodsFileName before we set the 'lastCheck' variable
       // The elapsedPeriodsFileName corresponds to the file name of the period
@@ -178,7 +196,7 @@
       elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
       //addInfo("elapsedPeriodsFileName set to "+elapsedPeriodsFileName);
 
-      lastCheck.setTime(n);
+      lastCheck.setTime(currentTime);
       nextCheck = rc.getNextCheckMillis(lastCheck);
 
       Date x = new Date();

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	Fri Apr 13 13:05:05 2007
@@ -90,14 +90,14 @@
     rfa.setContext(context);
     rfa.setLayout(layout);
 
-    SubTimeBasedRollingPolicy tbrpt = new SubTimeBasedRollingPolicy();
-    tbrpt.setContext(context);
-    tbrpt.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test1-%d{"
+    TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+    tbrp.setContext(context);
+    tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test1-%d{"
         + DATE_PATTERN + "}");
-    tbrpt.setParent(rfa);
-    tbrpt.setSimulatedTime(currentTime);
-    tbrpt.start();
-    rfa.setRollingPolicy(tbrpt);
+    tbrp.setParent(rfa);
+    tbrp.setCurrentTime(currentTime);
+    tbrp.start();
+    rfa.setRollingPolicy(tbrp);
     rfa.start();
 
     SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -110,12 +110,12 @@
     }
 
     // System.out.println("Waiting until next second and 100 millis.");
-    tbrpt.setSimulatedTime(addTime(currentTime, 1100));
+    tbrp.setCurrentTime(addTime(currentTime, 1100));
     // System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
-      tbrpt.setSimulatedTime(addTime(tbrpt.getSimulatedTime(), 500));
+      tbrp.setCurrentTime(addTime(tbrp.getCurrentTime(), 500));
       // Thread.sleep(500);
     }
 
@@ -141,14 +141,14 @@
     rfa1.setContext(context);
     rfa1.setLayout(layout);
 
-    SubTimeBasedRollingPolicy tbrpt1 = new SubTimeBasedRollingPolicy();
-    tbrpt1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
+    TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
+    tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
         + DATE_PATTERN + "}");
-    tbrpt1.setContext(context);
-    tbrpt1.setParent(rfa1);
-    tbrpt1.setSimulatedTime(currentTime);
-    tbrpt1.start();
-    rfa1.setRollingPolicy(tbrpt1);
+    tbrp1.setContext(context);
+    tbrp1.setParent(rfa1);
+    tbrp1.setCurrentTime(currentTime);
+    tbrp1.start();
+    rfa1.setRollingPolicy(tbrp1);
     rfa1.start();
 
     SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -161,12 +161,12 @@
     }
 
     // System.out.println("Waiting until next second and 100 millis.");
-    tbrpt1.setSimulatedTime(addTime(currentTime, 1100));
+    tbrp1.setCurrentTime(addTime(currentTime, 1100));
     // System.out.println("Done waiting.");
 
     for (int i = 0; i <= 2; i++) {
       rfa1.doAppend("Hello---" + i);
-      tbrpt1.setSimulatedTime(addTime(tbrpt1.getSimulatedTime(), 500));
+      tbrp1.setCurrentTime(addTime(tbrp1.getCurrentTime(), 500));
       // Thread.sleep(500);
     }
 
@@ -176,19 +176,19 @@
     rfa2.setContext(context);
     rfa2.setLayout(layout);
 
-    SubTimeBasedRollingPolicy tbrpt2 = new SubTimeBasedRollingPolicy();
-    tbrpt2.setContext(context);
-    tbrpt2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
+    TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
+    tbrp2.setContext(context);
+    tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
         + DATE_PATTERN + "}");
-    tbrpt2.setParent(rfa2);
-    tbrpt2.setSimulatedTime(tbrpt1.getSimulatedTime());
-    tbrpt2.start();
-    rfa2.setRollingPolicy(tbrpt2);
+    tbrp2.setParent(rfa2);
+    tbrp2.setCurrentTime(tbrp1.getCurrentTime());
+    tbrp2.start();
+    rfa2.setRollingPolicy(tbrp2);
     rfa2.start();
 
     for (int i = 0; i <= 2; i++) {
       rfa2.doAppend("Hello---" + i);
-      tbrpt2.setSimulatedTime(addTime(tbrpt2.getSimulatedTime(), 100));
+      tbrp2.setCurrentTime(addTime(tbrp2.getCurrentTime(), 100));
       // Thread.sleep(100);
     }
 
@@ -210,14 +210,14 @@
     rfa.setContext(context);
     rfa.setLayout(layout);
 
-    SubTimeBasedRollingPolicy tbrpt = new SubTimeBasedRollingPolicy();
-    tbrpt.setContext(context);
-    tbrpt.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test3-%d{"
+    TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+    tbrp.setContext(context);
+    tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test3-%d{"
         + DATE_PATTERN + "}.gz");
-    tbrpt.setParent(rfa);
-    tbrpt.setSimulatedTime(currentTime);
-    tbrpt.start();
-    rfa.setRollingPolicy(tbrpt);
+    tbrp.setParent(rfa);
+    tbrp.setCurrentTime(currentTime);
+    tbrp.start();
+    rfa.setRollingPolicy(tbrp);
     rfa.start();
 
     SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -233,12 +233,12 @@
         + sdf.format(cal.getTime());
 
     // System.out.println("Waiting until next second and 100 millis.");
-    tbrpt.setSimulatedTime(addTime(currentTime, 1100));
+    tbrp.setCurrentTime(addTime(currentTime, 1100));
     // System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
-      tbrpt.setSimulatedTime(addTime(tbrpt.getSimulatedTime(), 500));
+      tbrp.setCurrentTime(addTime(tbrp.getCurrentTime(), 500));
     }
 
     // for (int i = 0; i < 3; i++) {
@@ -267,15 +267,15 @@
     rfa1.setLayout(layout);
     rfa1.setFile(Constants.TEST_DIR_PREFIX + "output/test4.log");
 
-    SubTimeBasedRollingPolicy tbrpt1 = new SubTimeBasedRollingPolicy();
-    tbrpt1.setContext(context);
+    TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
+    tbrp1.setContext(context);
     // tbrp1.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
-    tbrpt1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
+    tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
         + DATE_PATTERN + "}");
-    tbrpt1.setParent(rfa1);
-    tbrpt1.setSimulatedTime(currentTime);
-    tbrpt1.start();
-    rfa1.setRollingPolicy(tbrpt1);
+    tbrp1.setParent(rfa1);
+    tbrp1.setCurrentTime(currentTime);
+    tbrp1.start();
+    rfa1.setRollingPolicy(tbrp1);
     rfa1.start();
 
     SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -289,12 +289,12 @@
     filenames[2] = Constants.TEST_DIR_PREFIX + "output/test4.log";
 
     // System.out.println("Waiting until next second and 100 millis.");
-    tbrpt1.setSimulatedTime(addTime(currentTime, 1100));
+    tbrp1.setCurrentTime(addTime(currentTime, 1100));
     // System.out.println("Done waiting.");
 
     for (int i = 0; i <= 2; i++) {
       rfa1.doAppend("Hello---" + i);
-      tbrpt1.setSimulatedTime(addTime(tbrpt1.getSimulatedTime(), 500));
+      tbrp1.setCurrentTime(addTime(tbrp1.getCurrentTime(), 500));
     }
 
     rfa1.stop();
@@ -304,20 +304,20 @@
     rfa2.setLayout(layout);
     rfa2.setFile(Constants.TEST_DIR_PREFIX + "output/test4.log");
 
-    SubTimeBasedRollingPolicy tbrpt2 = new SubTimeBasedRollingPolicy();
-    tbrpt2.setContext(context);
-    tbrpt2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
+    TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
+    tbrp2.setContext(context);
+    tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
         + DATE_PATTERN + "}");
     // tbrp2.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
-    tbrpt2.setParent(rfa2);
-    tbrpt2.setSimulatedTime(tbrpt1.getSimulatedTime());
-    tbrpt2.start();
-    rfa2.setRollingPolicy(tbrpt2);
+    tbrp2.setParent(rfa2);
+    tbrp2.setCurrentTime(tbrp1.getCurrentTime());
+    tbrp2.start();
+    rfa2.setRollingPolicy(tbrp2);
     rfa2.start();
 
     for (int i = 0; i <= 2; i++) {
       rfa2.doAppend("Hello---" + i);
-      tbrpt2.setSimulatedTime(addTime(tbrpt2.getSimulatedTime(), 100));
+      tbrp2.setCurrentTime(addTime(tbrp2.getCurrentTime(), 100));
     }
 
     for (int i = 0; i < 3; i++) {
@@ -339,15 +339,15 @@
     rfa.setLayout(layout);
     rfa.setFile(Constants.TEST_DIR_PREFIX + "output/test5.log");
 
-    SubTimeBasedRollingPolicy tbrpt = new SubTimeBasedRollingPolicy();
-    tbrpt.setContext(context);
-    tbrpt.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test5-%d{"
+    TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+    tbrp.setContext(context);
+    tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test5-%d{"
         + DATE_PATTERN + "}");
     // tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test5.log");
-    tbrpt.setParent(rfa);
-    tbrpt.setSimulatedTime(currentTime);
-    tbrpt.start();
-    rfa.setRollingPolicy(tbrpt);
+    tbrp.setParent(rfa);
+    tbrp.setCurrentTime(currentTime);
+    tbrp.start();
+    rfa.setRollingPolicy(tbrp);
     rfa.start();
 
     SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -362,12 +362,12 @@
     filenames[2] = Constants.TEST_DIR_PREFIX + "output/test5.log";
 
     // System.out.println("Waiting until next second and 100 millis.");
-    tbrpt.setSimulatedTime(addTime(currentTime, 1100));
+    tbrp.setCurrentTime(addTime(currentTime, 1100));
     // System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
-      tbrpt.setSimulatedTime(addTime(tbrpt.getSimulatedTime(), 500));
+      tbrp.setCurrentTime(addTime(tbrp.getCurrentTime(), 500));
     }
 
     for (int i = 0; i < 3; i++) {
@@ -389,15 +389,15 @@
     rfa.setLayout(layout);
     rfa.setFile(Constants.TEST_DIR_PREFIX + "output/test6.log");
 
-    SubTimeBasedRollingPolicy tbrpt = new SubTimeBasedRollingPolicy();
-    tbrpt.setContext(context);
-    tbrpt.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test6-%d{"
+    TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+    tbrp.setContext(context);
+    tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test6-%d{"
         + DATE_PATTERN + "}.gz");
     // tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test6.log");
-    tbrpt.setParent(rfa);
-    tbrpt.setSimulatedTime(currentTime);
-    tbrpt.start();
-    rfa.setRollingPolicy(tbrpt);
+    tbrp.setParent(rfa);
+    tbrp.setCurrentTime(currentTime);
+    tbrp.start();
+    rfa.setRollingPolicy(tbrp);
     rfa.start();
 
     SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -412,12 +412,12 @@
     filenames[2] = Constants.TEST_DIR_PREFIX + "output/test6.log";
 
     // System.out.println("Waiting until next second and 100 millis.");
-    tbrpt.setSimulatedTime(addTime(currentTime, 1100));
+    tbrp.setCurrentTime(addTime(currentTime, 1100));
     // System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
-      tbrpt.setSimulatedTime(addTime(tbrpt.getSimulatedTime(), 500));
+      tbrp.setCurrentTime(addTime(tbrp.getCurrentTime(), 500));
     }
 
     // for (int i = 0; i < 4; i++) {
@@ -432,7 +432,7 @@
     assertTrue(Compare.compare(filenames[2], Constants.TEST_DIR_PREFIX
         + "witness/rolling/tbr-test6.2"));
   }
-
+  
   public static Test suite() {
     TestSuite suite = new TestSuite();
     suite.addTestSuite(TimeBasedRollingTest.class);



More information about the logback-dev mailing list