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

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Jul 31 13:29:02 CEST 2009


Author: ceki
Date: Fri Jul 31 13:29:02 2009
New Revision: 2387

Added:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
   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/TimeBasedRollingTest.java

Log:
- use trimmed string values for all types in PropertySetter (improved coherence)
- Less code duplication in rolling file tests

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java	Fri Jul 31 13:29:02 2009
@@ -437,7 +437,7 @@
     }
     String v = val.trim();
     if (String.class.isAssignableFrom(type)) {
-      return val;
+      return v;
     } else if (Integer.TYPE.isAssignableFrom(type)) {
       return new Integer(v);
     } else if (Long.TYPE.isAssignableFrom(type)) {
@@ -453,9 +453,9 @@
         return Boolean.FALSE;
       }
     } else if (type.isEnum()) {
-      return convertEnum(val, type);
+      return convertEnum(v, type);
     } else if (isBuildableFromString(type)) {
-      return buildFromString(type, val);
+      return buildFromString(type, v);
     }
 
     return null;

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java	Fri Jul 31 13:29:02 2009
@@ -14,33 +14,31 @@
 import ch.qos.logback.core.rolling.helper.FileNamePattern;
 import ch.qos.logback.core.spi.ContextAwareBase;
 
-
-
 /**
- * Implements methods common to most, it not all, rolling
- * policies. Currently such methods are limited to a compression mode
- * getter/setter.
- *
+ * Implements methods common to most, it not all, rolling policies. Currently
+ * such methods are limited to a compression mode getter/setter.
+ * 
  * @author Ceki Gülcü
  */
-public abstract class RollingPolicyBase extends ContextAwareBase implements RollingPolicy {
+public abstract class RollingPolicyBase extends ContextAwareBase implements
+    RollingPolicy {
   protected CompressionMode compressionMode = CompressionMode.NONE;
   protected FileNamePattern fileNamePattern;
   protected String fileNamePatternStr;
-  
+
   private FileAppender parent;
-  
+
   private boolean started;
-  
+
   /**
    * Given the FileNamePattern string, this method determines the compression
-   * mode depending on last letters of the fileNamePatternStr. Patterns
-   * ending with .gz imply GZIP compression, endings with '.zip' imply
-   * ZIP compression. Otherwise and by default, there is no compression.
-   *
+   * mode depending on last letters of the fileNamePatternStr. Patterns ending
+   * with .gz imply GZIP compression, endings with '.zip' imply ZIP compression.
+   * Otherwise and by default, there is no compression.
+   * 
    */
   protected void determineCompressionMode() {
-     if (fileNamePatternStr.endsWith(".gz")) {
+    if (fileNamePatternStr.endsWith(".gz")) {
       addInfo("Will use gz compression");
       compressionMode = CompressionMode.GZ;
     } else if (fileNamePatternStr.endsWith(".zip")) {
@@ -52,6 +50,7 @@
     }
   }
 
+  
   public void setFileNamePattern(String fnp) {
     fileNamePatternStr = fnp;
   }
@@ -59,7 +58,7 @@
   public String getFileNamePattern() {
     return fileNamePatternStr;
   }
-  
+
   public CompressionMode getCompressionMode() {
     return compressionMode;
   }
@@ -71,11 +70,11 @@
   public void start() {
     started = true;
   }
-  
+
   public void stop() {
     started = false;
   }
-  
+
   public void setParent(FileAppender appender) {
     addInfo("Adding parent to RollingPolicy: " + appender.getName());
     this.parent = appender;
@@ -84,7 +83,7 @@
   public boolean isParentPrudent() {
     return parent.isPrudent();
   }
-  
+
   public String getParentsRawFileProperty() {
     return parent.rawFileProperty();
   }

Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java	Fri Jul 31 13:29:02 2009
@@ -0,0 +1,112 @@
+package ch.qos.logback.core.rolling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Date;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.layout.EchoLayout;
+import ch.qos.logback.core.testUtil.FileToBufferUtil;
+import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.CoreTestConstants;
+
+/**
+ * Scaffolding for various rolling tests. Some assumptions are made:
+ * - rollover periodicity is 1 second (without precluding size based roll-over)
+ * 
+ * @author Ceki Gülcü
+ *
+ */
+public class ScaffoldingForRollingTests {
+  
+  static final String DATE_PATTERN_WITH_SECONDS = "yyyy-MM-dd_HH_mm_ss";
+  SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN_WITH_SECONDS);
+  
+  int diff = RandomUtil.getPositiveInt();
+  String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
+  EchoLayout<Object> layout = new EchoLayout<Object>();
+  Context context = new ContextBase();
+  List<String> expectedFilenameList = new ArrayList<String>();
+
+  long nextRolloverThreshold; // initialized in setUp()
+  long currentTime; // initialized in setUp()
+  Calendar cal = Calendar.getInstance();
+  
+
+  public void setUp() {
+    context.setName("test");
+    cal.set(Calendar.MILLISECOND, 333);
+    currentTime = cal.getTimeInMillis();
+    recomputeRolloverThreshold(currentTime);
+    System.out.println(randomOutputDir);
+  }
+
+  void existenceCheck(String filename) {
+    assertTrue("File " + filename + " does not exist", new File(filename)
+        .exists());
+  }
+  
+  void contentCheck(int runLength, String prefix) throws IOException {
+    File outputDir = new File(randomOutputDir);
+    File[] fileArray = outputDir.listFiles();
+    List<String> stringList = new ArrayList<String>();
+    for (File file : fileArray) {
+      FileToBufferUtil.readIntoList(file, stringList);
+    }
+    
+    List<String> witnessList = new ArrayList<String>();
+    
+    for(int i = 0; i < runLength; i++) {
+      witnessList.add(prefix+i);
+    }
+    assertEquals(witnessList, stringList);
+  }
+   
+  void existenceCheck(List<String> filenameList) {
+    for (String filename : filenameList) {
+      assertTrue("File " + filename + " does not exist", new File(filename)
+          .exists());
+    }
+  }
+  
+  
+  String testId2FileName(String testId) {
+    return randomOutputDir + testId + ".log";
+  }
+
+  // assuming rollover every second
+  void recomputeRolloverThreshold(long ct) {
+    long delta = ct % 1000;
+    nextRolloverThreshold = (ct - delta) + 1000;
+  }
+  
+  boolean passThresholdTime(long nextRolloverThreshold) {
+    return currentTime >= nextRolloverThreshold;
+  }
+  
+  void incCurrentTime(long increment) {
+    currentTime += increment;
+  }
+   
+  Date getDateOfCurrentPeriodsStart() {
+    long delta = currentTime % 1000;
+    return new Date(currentTime - delta);
+  }
+
+  String addGZIfNotLast(int i) {
+    int lastIndex = expectedFilenameList.size() - 1;
+    if (i != lastIndex) {
+      return ".gz";
+    } else {
+      return "";
+    }
+  }
+}

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 13:29:02 2009
@@ -10,67 +10,27 @@
 
 package ch.qos.logback.core.rolling;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
-import java.io.File;
-import java.io.IOException;
-import java.sql.Date;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
+import java.util.Date;
 
 import org.junit.Before;
 import org.junit.Test;
 
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.layout.EchoLayout;
-import ch.qos.logback.core.testUtil.FileToBufferUtil;
-import ch.qos.logback.core.testUtil.RandomUtil;
-import ch.qos.logback.core.util.CoreTestConstants;
-
-public class SizeAndTimeBasedFileNamingAndTriggeringPolicyTest {
-  static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss";
-
-  int diff = RandomUtil.getPositiveInt();
-  String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
+public class SizeAndTimeBasedFileNamingAndTriggeringPolicyTest extends
+    ScaffoldingForRollingTests {
 
   SizeAndTimeBasedFileNamingAndTriggeringPolicy<Object> satbfnatPolicy = new SizeAndTimeBasedFileNamingAndTriggeringPolicy<Object>();
-
-  SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
-
-  EchoLayout<Object> layout = new EchoLayout<Object>();
-  Context context = new ContextBase();
-
   RollingFileAppender<Object> rfa1 = new RollingFileAppender<Object>();
   TimeBasedRollingPolicy<Object> tbrp1 = new TimeBasedRollingPolicy<Object>();
-  Calendar cal = Calendar.getInstance();
-  long currentTime; // initialized in setUp()
-  long nextRolloverThreshold; // initialized in setUp()
-  List<String> expectedFilenameList = new ArrayList<String>();
 
   int fileSize = 0;
   int fileIndexCounter = 0;
   int sizeThreshold;
 
   @Before
+  @Override
   public void setUp() {
-    context.setName("test");
-    cal.set(Calendar.MILLISECOND, 333);
-    currentTime = cal.getTimeInMillis();
-    recomputeRolloverThreshold(currentTime);
-    System.out.println(randomOutputDir);
-    // System.out.println("at setUp() currentTime="
-    // + sdf.format(new Date(currentTime)));
-
-  }
-
-  // assuming rollover every second
-  void recomputeRolloverThreshold(long ct) {
-    long delta = ct % 1000;
-    nextRolloverThreshold = (ct - delta) + 1000;
+    super.setUp();
   }
 
   void initRFA(RollingFileAppender<Object> rfa, String filename) {
@@ -105,8 +65,8 @@
     String file = randomOutputDir + "toto.log";
     initRFA(rfa1, file);
     sizeThreshold = 300;
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{" + DATE_PATTERN
-        + "}-%i.txt", sizeThreshold, currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}-%i.txt", sizeThreshold, currentTime, 0);
 
     addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
         fileIndexCounter, false);
@@ -116,7 +76,7 @@
 
     int runLength = 100;
     String prefix = "Hello -----------------";
-    
+
     for (int i = 0; i < runLength; i++) {
       String msg = prefix + i;
       rfa1.doAppend(msg);
@@ -135,8 +95,8 @@
     String testId = "test1";
     initRFA(rfa1, null);
     sizeThreshold = 300;
-    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{" + DATE_PATTERN
-        + "}-%i.txt", sizeThreshold, currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}-%i.txt", sizeThreshold, currentTime, 0);
 
     addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
         fileIndexCounter, false);
@@ -146,7 +106,7 @@
 
     int runLength = 100;
     String prefix = "Hello -----------------";
-    
+
     for (int i = 0; i < runLength; i++) {
       String msg = prefix + i;
       rfa1.doAppend(msg);
@@ -159,45 +119,12 @@
     contentCheck(runLength, prefix);
   }
 
-  
-  void existenceCheck(String filename) {
-    assertTrue("File " + filename + " does not exist", new File(filename)
-        .exists());
-  }
-
-  void contentCheck(int runLength, String prefix) throws IOException {
-    File outputDir = new File(randomOutputDir);
-    File[] fileArray = outputDir.listFiles();
-    List<String> stringList = new ArrayList<String>();
-    for (File file : fileArray) {
-      FileToBufferUtil.readIntoList(file, stringList);
-    }
-    
-    List<String> witnessList = new ArrayList<String>();
-    
-    for(int i = 0; i < runLength; i++) {
-      witnessList.add(prefix+i);
-    }
-    assertEquals(witnessList, stringList);
-  }
-
-  void existenceCheck(List<String> filenameList) {
-    for (String filename : filenameList) {
-      assertTrue("File " + filename + " does not exist", new File(filename)
-          .exists());
-    }
-  }
-
   void massageExpectedFilesToCorresponToCurrentTarget(String file) {
     // we added one too many files by date
     expectedFilenameList.remove(expectedFilenameList.size() - 1);
     expectedFilenameList.add(file);
   }
 
-  boolean passThresholdTime(long nextRolloverThreshold) {
-    return currentTime >= nextRolloverThreshold;
-  }
-
   void addExpectedFileNamedIfItsTime(String testId, String msg,
       boolean gzExtension) {
     fileSize += msg.getBytes().length;
@@ -233,12 +160,4 @@
     expectedFilenameList.add(fn);
   }
 
-  Date getDateOfCurrentPeriodsStart() {
-    long delta = currentTime % 1000;
-    return new Date(currentTime - delta);
-  }
-
-  void incCurrentTime(long increment) {
-    currentTime += increment;
-  }
 }

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 Jul 31 13:29:02 2009
@@ -12,21 +12,13 @@
 
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
 import java.sql.Date;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.layout.EchoLayout;
 import ch.qos.logback.core.util.Compare;
 import ch.qos.logback.core.util.CoreTestConstants;
 
@@ -51,13 +43,7 @@
  * 
  * @author Ceki G&uuml;lc&uuml;
  */
-public class TimeBasedRollingTest {
-
-  static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss";
-  SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
-
-  EchoLayout<Object> layout = new EchoLayout<Object>();
-  Context context = new ContextBase();
+public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
 
   RollingFileAppender<Object> rfa1 = new RollingFileAppender<Object>();
   TimeBasedRollingPolicy<Object> tbrp1 = new TimeBasedRollingPolicy<Object>();
@@ -65,33 +51,14 @@
   RollingFileAppender<Object> rfa2 = new RollingFileAppender<Object>();
   TimeBasedRollingPolicy<Object> tbrp2 = new TimeBasedRollingPolicy<Object>();
 
-  Calendar cal = Calendar.getInstance();
-  long currentTime; // initialized in setUp()
-  long nextRolloverThreshold; // initialized in setUp()
-  List<String> expectedFilenameList = new ArrayList<String>();
 
   @Before
+  @Override
   public void setUp() {
-    context.setName("test");
-    cal.set(Calendar.MILLISECOND, 333);
-    currentTime = cal.getTimeInMillis();
-    recomputeRolloverThreshold(currentTime);
-    System.out.println("at setUp() currentTime="
-        + sdf.format(new Date(currentTime)));
-
-    // Delete .log files
-    deleteStaleLogFile("test4.log");
-    deleteStaleLogFile("test4B.log");
-    deleteStaleLogFile("test5.log");
-    deleteStaleLogFile("test6.log");
-  }
-
-  void deleteStaleLogFile(String filename) {
-    File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX + filename);
-    target.mkdirs();
-    target.delete();
+    super.setUp();
   }
 
+
   @After
   public void tearDown() {
   }
@@ -126,8 +93,8 @@
   public void noCompression_FileBlank_NoRestart_1() throws Exception {
     String testId = "test1";
     initRFA(rfa1, null);
-    initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, 0);
 
     // compute the current filename
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
@@ -156,8 +123,8 @@
   public void withCompression_FileBlank_NoRestart_2() throws Exception {
     String testId = "test2";
     initRFA(rfa1, null);
-    initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}.gz", currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime, 0);
 
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
     incCurrentTime(1100);
@@ -189,8 +156,8 @@
     String testId = "test3";
 
     initRFA(rfa1, null);
-    initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, 0);
 
     // a new file is created by virtue of rfa.start();
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
@@ -208,8 +175,8 @@
     rfa1.stop();
 
     initRFA(rfa2, null);
-    initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", tbrp1.timeBasedTriggering.getCurrentTime(), 0);
+    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", tbrp1.timeBasedTriggering.getCurrentTime(), 0);
 
     for (int i = 0; i <= 2; i++) {
       addExpectedFileNamedIfItsTime_ByDate(testId, false);
@@ -232,8 +199,8 @@
   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);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, 0);
 
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
 
@@ -250,8 +217,8 @@
     rfa1.stop();
 
     initRFA(rfa2, testId2FileName(testId));
-    initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", currentTime, currentTime);
+    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, currentTime);
 
     for (int i = 0; i <= 2; i++) {
       rfa2.doAppend("World---" + i);
@@ -274,8 +241,8 @@
       throws Exception {
     String testId = "test4B";
     initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, 0);
 
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
 
@@ -294,9 +261,9 @@
     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);
+    initRFA(rfa2, randomOutputDir + "test4B.log");
+    initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, fileTimestamp);
 
     for (int i = 0; i <= 2; i++) {
       rfa2.doAppend("World---" + i);
@@ -323,8 +290,8 @@
     String testId = "test5";
 
     initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}", currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}", currentTime, 0);
 
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
 
@@ -356,8 +323,8 @@
     String testId = "test6";
 
     initRFA(rfa1, testId2FileName(testId));
-    initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-        + DATE_PATTERN + "}.gz", currentTime, 0);
+    initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
+        + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime, 0);
 
     addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
 
@@ -388,9 +355,6 @@
   // utility methods
   // =========================================================================
 
-  String testId2FileName(String testId) {
-    return CoreTestConstants.OUTPUT_DIR_PREFIX + testId + ".log";
-  }
 
   void massageExpectedFilesToCorresponToCurrentTarget(String file) {
     // we added one too many files by date
@@ -399,24 +363,15 @@
     addExpectedFileName_ByFile(file);
   }
 
-  String addGZIfNotLast(int i) {
-    int lastIndex = expectedFilenameList.size() - 1;
-    if (i != lastIndex) {
-      return ".gz";
-    } else {
-      return "";
-    }
-  }
-
   void addExpectedFileName_ByDate(String testId, Date date, boolean gzExtension) {
-    String fn = CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-"
+    String fn = randomOutputDir + testId + "-"
         + sdf.format(date);
     if (gzExtension) {
       fn += ".gz";
-    }
+    } 
     expectedFilenameList.add(fn);
   }
-
+ 
   void addExpectedFileNamedIfItsTime_ByDate(String testId, boolean gzExtension) {
     if (passThresholdTime(nextRolloverThreshold)) {
       addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(),
@@ -426,40 +381,7 @@
   }
 
   void addExpectedFileName_ByFile(String filenameSuffix) {
-    String fn = CoreTestConstants.OUTPUT_DIR_PREFIX + filenameSuffix;
+    String fn = randomOutputDir + filenameSuffix;
     expectedFilenameList.add(fn);
   }
-
-  Date getDateOfCurrentPeriodsStart() {
-    long delta = currentTime % 1000;
-    return new Date(currentTime - delta);
-  }
-
-  Date getDateOfPastPeriodsStart() {
-    long delta = currentTime % 1000;
-    return new Date(currentTime - delta - 1000);
-  }
-
-  static long addTime(long currentTime, long timeToWait) {
-    return currentTime + timeToWait;
-  }
-
-  boolean passThresholdTime(long nextRolloverThreshold) {
-    return currentTime >= nextRolloverThreshold;
-  }
-
-  // assuming rollover every second
-  void recomputeRolloverThreshold(long ct) {
-    long delta = ct % 1000;
-    nextRolloverThreshold = (ct - delta) + 1000;
-  }
-
-  void incCurrentTime(long increment) {
-    currentTime += increment;
-  }
-
-  void printLongAsDate(String msg, long time) {
-    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
-    System.out.println(msg + sdf.format(new Date(time)));
-  }
 }


More information about the logback-dev mailing list