[logback-dev] svn commit: r960 - in logback/trunk/logback-core: . src/test/java/ch/qos/logback/core/appender src/test/java/ch/qos/logback/core/rolling src/test/java/ch/qos/logback/core/util

noreply.ceki at qos.ch noreply.ceki at qos.ch
Sun Nov 19 17:10:41 CET 2006


Author: ceki
Date: Sun Nov 19 17:10:41 2006
New Revision: 960

Added:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
Modified:
   logback/trunk/logback-core/pom.xml
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.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/util/TeeOutputStream.java

Log:
- Added TimeBasedRolloverTest to the list of excluded tests in pom.xml as it takes as much as 12 seconds to execute
- Modified Modified ConsoleAppenderTest to output nothing on the console. In a related change, TeeOutputStream now 
  admit a null parameter in the constructor
- Moved delaying methods into DelayerUtil class
- Silent tests are beautiful.


Modified: logback/trunk/logback-core/pom.xml
==============================================================================
--- logback/trunk/logback-core/pom.xml	(original)
+++ logback/trunk/logback-core/pom.xml	Sun Nov 19 17:10:41 2006
@@ -66,6 +66,7 @@
 						<exclude>**/AllTest.java</exclude>
 						<exclude>**/PackageTest.java</exclude>
 						<exclude>**/SizeBasedRollingTest.java</exclude>
+            <exclude>**/TimeBasedRollingTest.java</exclude>
 					</excludes>
 				</configuration>
 			</plugin>

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java	Sun Nov 19 17:10:41 2006
@@ -38,7 +38,11 @@
     // tee will output bytes on System out but it will also
     // collect them so that the output can be compared against
     // some expected output data
-    tee = new TeeOutputStream(original);
+    // tee = new TeeOutputStream(original);
+    
+    // keep the console quiet
+    tee = new TeeOutputStream(null);
+    
     // redirect System.out to tee
     System.setOut(new PrintStream(tee));
   }

Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java	Sun Nov 19 17:10:41 2006
@@ -0,0 +1,51 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * 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.
+ */
+
+package ch.qos.logback.core.rolling;
+
+import java.util.Calendar;
+import java.util.Date;
+
+public class DelayerUtil {
+  
+  // delay until millis in the next second
+  static void delayUntilNextSecond(int millis) {
+    long now = System.currentTimeMillis();
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(new Date(now));
+
+    cal.set(Calendar.MILLISECOND, millis);
+    cal.add(Calendar.SECOND, 1);
+
+    long next = cal.getTime().getTime();
+
+    try {
+      Thread.sleep(next - now);
+    } catch (Exception e) {
+    }
+  }
+
+  static void delayUntilNextMinute(int seconds) {
+    long now = System.currentTimeMillis();
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(new Date(now));
+
+    cal.set(Calendar.SECOND, seconds);
+    cal.add(Calendar.MINUTE, 1);
+
+    long next = cal.getTime().getTime();
+
+    try {
+      Thread.sleep(next - now);
+    } catch (Exception e) {
+    }
+  }
+
+}

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java	Sun Nov 19 17:10:41 2006
@@ -20,7 +20,6 @@
 import ch.qos.logback.core.Layout;
 import ch.qos.logback.core.layout.EchoLayout;
 import ch.qos.logback.core.util.Compare;
-import ch.qos.logback.core.util.StatusPrinter;
 
 /**
  * 
@@ -74,21 +73,21 @@
     rfa.setRollingPolicy(tbrp);
     rfa.start();
 
-    StatusPrinter.print(context.getStatusManager());
+    //StatusPrinter.print(context.getStatusManager());
     Calendar cal = Calendar.getInstance();
 
     rfa.doAppend("Hello 0");
-    Thread.sleep(5000);
+    DelayerUtil.delayUntilNextSecond(50);
     rfa.doAppend("Hello 1");
 
     filenames[0] = "src/test/output/test-" + sdf.format(cal.getTime());
     filenames[1] = "src/test/output/test.log";
 
     for (int i = 0; i < filenames.length; i++) {
-      System.out.println("before i=" + i);
+      //System.out.println("before i=" + i);
       assertTrue(Compare.compare(filenames[i],
           "src/test/witness/rolling/renaming." + i));
-      System.out.println("post i=" + i);
+      //System.out.println("post i=" + i);
     }
   }
 }

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	Sun Nov 19 17:10:41 2006
@@ -13,11 +13,12 @@
 import java.io.File;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
-import java.util.Date;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+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.Constants;
@@ -32,13 +33,13 @@
  * with witness files.
  * 
  * <pre>
- *  Compression    ActiveFileName  Stop/Restart 
- *  Test1      NO              BLANK          NO
- *  Test2      NO              BLANK          YES
- *  Test3      YES             BLANK          NO
- *  Test4      NO                SET          YES 
- *  Test5      NO                SET          NO
- *  Test6      YES               SET          NO
+ *             Compression     ActiveFileName  Stop/Restart 
+ *  Test1      NO              BLANK           NO
+ *  Test2      NO              BLANK           YES
+ *  Test3      YES             BLANK           NO
+ *  Test4      NO              SET             YES 
+ *  Test5      NO              SET             NO
+ *  Test6      YES             SET             NO
  * </pre>
  * 
  * @author Ceki G&uuml;lc&uuml;
@@ -48,12 +49,14 @@
   static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss";
 
   EchoLayout layout = new EchoLayout();
-
+  Context context = new  ContextBase();
+  
   public TimeBasedRollingTest(String name) {
     super(name);
   }
 
   public void setUp() {
+    context.setName("test");
     // Delete .log files
     {
       File target = new File(Constants.TEST_DIR_PREFIX + "output/test4.log");
@@ -81,9 +84,11 @@
   public void test1() throws Exception {
 
     RollingFileAppender rfa = new RollingFileAppender();
+    rfa.setContext(context);
     rfa.setLayout(layout);
 
     TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+    tbrp.setContext(context);
     tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test1-%d{"
         + DATE_PATTERN + "}");
     tbrp.setParent(rfa);
@@ -102,9 +107,9 @@
       cal.add(Calendar.SECOND, 1);
     }
     
-    System.out.println("Waiting until next second and 100 millis.");
-    delayUntilNextSecond(100);
-    System.out.println("Done waiting.");
+    //System.out.println("Waiting until next second and 100 millis.");
+    DelayerUtil.delayUntilNextSecond(100);
+    //System.out.println("Done waiting.");
     
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
@@ -126,11 +131,13 @@
    */
   public void test2() throws Exception {
     RollingFileAppender rfa1 = new RollingFileAppender();
+    rfa1.setContext(context);
     rfa1.setLayout(layout);
 
     TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
     tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
         + DATE_PATTERN + "}");
+    tbrp1.setContext(context);
     tbrp1.setParent(rfa1);
     tbrp1.start();
     rfa1.setRollingPolicy(tbrp1);
@@ -147,9 +154,9 @@
       cal.add(Calendar.SECOND, 1);
     }
 
-    System.out.println("Waiting until next second and 100 millis.");
-    delayUntilNextSecond(100);
-    System.out.println("Done waiting.");
+    //System.out.println("Waiting until next second and 100 millis.");
+    DelayerUtil.delayUntilNextSecond(100);
+    //System.out.println("Done waiting.");
 
     for (int i = 0; i <= 2; i++) {
       rfa1.doAppend("Hello---" + i);
@@ -159,9 +166,11 @@
     rfa1.stop();
 
     RollingFileAppender rfa2 = new RollingFileAppender();
+    rfa2.setContext(context);
     rfa2.setLayout(layout);
 
     TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
+    tbrp2.setContext(context);
     tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
         + DATE_PATTERN + "}");
     tbrp2.setParent(rfa2);
@@ -185,9 +194,11 @@
    */
   public void test3() throws Exception {
     RollingFileAppender rfa = new RollingFileAppender();
+    rfa.setContext(context);
     rfa.setLayout(layout);
 
     TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+    tbrp.setContext(context);
     tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test3-%d{"
         + DATE_PATTERN + "}.gz");
     tbrp.setParent(rfa);
@@ -208,9 +219,9 @@
 
     filenames[3] = "src/test/output/test3-" + sdf.format(cal.getTime());
 
-    System.out.println("Waiting until next second and 100 millis.");
-    delayUntilNextSecond(100);
-    System.out.println("Done waiting.");
+    //System.out.println("Waiting until next second and 100 millis.");
+    DelayerUtil.delayUntilNextSecond(100);
+    //System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
@@ -235,10 +246,12 @@
    */
   public void test4() throws Exception {
     RollingFileAppender rfa1 = new RollingFileAppender();
+    rfa1.setContext(context);
     rfa1.setLayout(layout);
     rfa1.setFile(Constants.TEST_DIR_PREFIX + "output/test4.log");
 
     TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
+    tbrp1.setContext(context);
     //tbrp1.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
     tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
         + DATE_PATTERN + "}");
@@ -259,9 +272,9 @@
     }
     filenames[2] = Constants.TEST_DIR_PREFIX + "output/test4.log";
 
-    System.out.println("Waiting until next second and 100 millis.");
-    delayUntilNextSecond(100);
-    System.out.println("Done waiting.");
+    //System.out.println("Waiting until next second and 100 millis.");
+    DelayerUtil.delayUntilNextSecond(50);
+    //System.out.println("Done waiting.");
 
     for (int i = 0; i <= 2; i++) {
       rfa1.doAppend("Hello---" + i);
@@ -271,10 +284,12 @@
     rfa1.stop();
 
     RollingFileAppender rfa2 = new RollingFileAppender();
+    rfa2.setContext(context);
     rfa2.setLayout(layout);
     rfa2.setFile(Constants.TEST_DIR_PREFIX + "output/test4.log");
 
     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");
@@ -299,10 +314,12 @@
    */
   public void test5() throws Exception {
     RollingFileAppender rfa = new RollingFileAppender();
+    rfa.setContext(context);
     rfa.setLayout(layout);
     rfa.setFile(Constants.TEST_DIR_PREFIX + "output/test5.log");
 
     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");
@@ -324,9 +341,9 @@
 
     filenames[2] = Constants.TEST_DIR_PREFIX + "output/test5.log";
 
-    System.out.println("Waiting until next second and 100 millis.");
-    delayUntilNextSecond(100);
-    System.out.println("Done waiting.");
+    //System.out.println("Waiting until next second and 100 millis.");
+    DelayerUtil.delayUntilNextSecond(100);
+    //System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
@@ -344,10 +361,12 @@
    */
   public void test6() throws Exception {
     RollingFileAppender rfa = new RollingFileAppender();
+    rfa.setContext(context);
     rfa.setLayout(layout);
     rfa.setFile(Constants.TEST_DIR_PREFIX + "output/test6.log");
 
     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");
@@ -369,9 +388,9 @@
 
     filenames[2] = Constants.TEST_DIR_PREFIX + "output/test6.log";
 
-    System.out.println("Waiting until next second and 100 millis.");
-    delayUntilNextSecond(100);
-    System.out.println("Done waiting.");
+    //System.out.println("Waiting until next second and 100 millis.");
+    DelayerUtil.delayUntilNextSecond(100);
+    //System.out.println("Done waiting.");
 
     for (int i = 0; i < 3; i++) {
       rfa.doAppend("Hello---" + i);
@@ -391,104 +410,6 @@
         + "witness/rolling/tbr-test6.2"));
   }
 
-  // public void testWithJoran1() throws Exception {
-  // JoranConfigurator jc = new JoranConfigurator();
-  // jc.doConfigure("./input/rolling/time1.xml",
-  // LogManager.getLoggerRepository());
-  // jc.dumpErrors();
-  //    
-  // String datePattern = "yyyy-MM-dd_HH_mm_ss";
-  //
-  // SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
-  // String[] filenames = new String[4];
-  //
-  // Calendar cal = Calendar.getInstance();
-  //
-  // for (int i = 0; i < 4; i++) {
-  // filenames[i] = "output/test1-" + sdf.format(cal.getTime());
-  // cal.add(Calendar.SECOND, 1);
-  // }
-  //
-  // System.out.println("Waiting until next second and 100 millis.");
-  // delayUntilNextSecond(100);
-  // System.out.println("Done waiting.");
-  //
-  // for (int i = 0; i < 5; i++) {
-  // logger.debug("Hello---" + i);
-  // Thread.sleep(500);
-  // }
-  //
-  // for (int i = 0; i < 4; i++) {
-  // //System.out.println(i + " expected filename [" + filenames[i] + "].");
-  // }
-  //
-  // for (int i = 0; i < 4; i++) {
-  // assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test1." +
-  // i));
-  // }
-  //    
-  // }
-  //  
-  // public void XXXtestWithJoran10() throws Exception {
-  // JoranConfigurator jc = new JoranConfigurator();
-  // jc.doConfigure("./input/rolling/time2.xml",
-  // LogManager.getLoggerRepository());
-  // jc.dumpErrors();
-  //    
-  // String datePattern = "yyyy-MM-dd";
-  //
-  // SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
-  // String[] filenames = new String[0];
-  //
-  // Calendar cal = Calendar.getInstance();
-  //
-  // filenames[0] = "output/test1-" + sdf.format(cal.getTime());
-  //
-  // for (int i = 0; i < 5; i++) {
-  // logger.debug("Hello---" + i);
-  // Thread.sleep(500);
-  // }
-  //
-  //
-  // for (int i = 0; i < 1; i++) {
-  // assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test10." +
-  // i));
-  // }
-  //    
-  // }
-
-  void delayUntilNextSecond(int millis) {
-    long now = System.currentTimeMillis();
-    Calendar cal = Calendar.getInstance();
-    cal.setTime(new Date(now));
-
-    cal.set(Calendar.MILLISECOND, millis);
-    cal.add(Calendar.SECOND, 1);
-
-    long next = cal.getTime().getTime();
-
-    try {
-      Thread.sleep(next - now);
-    } catch (Exception e) {
-    }
-  }
-
-  void delayUntilNextMinute(int seconds) {
-    long now = System.currentTimeMillis();
-    Calendar cal = Calendar.getInstance();
-    cal.setTime(new Date(now));
-
-    cal.set(Calendar.SECOND, seconds);
-    cal.add(Calendar.MINUTE, 1);
-
-    long next = cal.getTime().getTime();
-
-    try {
-      Thread.sleep(next - now);
-    } catch (Exception e) {
-    }
-  }
-
   public static Test suite() {
     TestSuite suite = new TestSuite();
     // CompressTest requires external copying

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TeeOutputStream.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TeeOutputStream.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TeeOutputStream.java	Sun Nov 19 17:10:41 2006
@@ -27,12 +27,15 @@
   final ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
   public TeeOutputStream(PrintStream targetPS) {
+    // allow for null arguments
     this.targetPS = targetPS;
   }
 
   public void write(int b) throws IOException {
     baos.write(b);
+    if(targetPS != null) {
     targetPS.write(b);
+    }
   }
 
   public String toString() {



More information about the logback-dev mailing list