[logback-dev] svn commit: r2400 - in logback/trunk/logback-classic/src/test: input/joran/rolling java/ch/qos/logback/classic java/ch/qos/logback/classic/rolling
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Fri Jul 31 21:11:24 CEST 2009
Author: ceki
Date: Fri Jul 31 21:11:23 2009
New Revision: 2400
Added:
logback/trunk/logback-classic/src/test/input/joran/rolling/basic.xml
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
Modified:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java
Log:
Testing configuration file driven TimeBasedRolling
Added: logback/trunk/logback-classic/src/test/input/joran/rolling/basic.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/joran/rolling/basic.xml Fri Jul 31 21:11:23 2009
@@ -0,0 +1,22 @@
+<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}
+ </FileNamePattern>
+ </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/AllClassicTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java Fri Jul 31 21:11:23 2009
@@ -19,6 +19,7 @@
ch.qos.logback.classic.util.PackageTest.class,
ch.qos.logback.classic.control.PackageTest.class,
ch.qos.logback.classic.joran.PackageTest.class,
+ ch.qos.logback.classic.rolling.PackageTest.class,
ch.qos.logback.classic.jmx.PackageTest.class,
ch.qos.logback.classic.boolex.PackageTest.class,
ch.qos.logback.classic.selector.PackageTest.class,
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/PackageTest.java Fri Jul 31 21:11:23 2009
@@ -0,0 +1,20 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, 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.classic.rolling;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+
+ at RunWith(Suite.class)
+ at SuiteClasses( { TimeBasedRollingWithConfigFileTest.class})
+public class PackageTest {
+}
\ No newline at end of file
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java Fri Jul 31 21:11:23 2009
@@ -0,0 +1,81 @@
+package ch.qos.logback.classic.rolling;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import ch.qos.logback.classic.ClassicTestConstants;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.rolling.RollingFileAppender;
+import ch.qos.logback.core.rolling.ScaffoldingForRollingTests;
+import ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicy;
+import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
+
+public class TimeBasedRollingWithConfigFileTest extends
+ ScaffoldingForRollingTests {
+
+ LoggerContext lc = new LoggerContext();
+ Logger logger = lc.getLogger(this.getClass());
+
+ @Before
+ @Override
+ public void setUp() {
+ lc.setName("test");
+ super.setUp();
+ lc.putProperty("randomOutputDir", randomOutputDir);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ void loadConfig(String confifFile) throws JoranException {
+ JoranConfigurator jc = new JoranConfigurator();
+ jc.setContext(lc);
+ jc.doConfigure(confifFile);
+ currentTime = System.currentTimeMillis();
+ recomputeRolloverThreshold(currentTime);
+ }
+
+ @Test
+ public void basic() throws Exception {
+ String testId = "basic";
+ lc.putProperty("testId", testId);
+ loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/basic.xml");
+ Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
+
+ expectedFilenameList.add(randomOutputDir+"z"+testId);
+
+ RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root
+ .getAppender("ROLLING");
+
+ TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
+ .getTriggeringPolicy();
+ TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp.getTimeBasedFileNamingAndTriggeringPolicy();
+
+ String prefix = "Hello---";
+ int runLength = 4;
+ for (int i = 0; i < runLength; i++) {
+ logger.debug(prefix + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ incCurrentTime(500);
+ tbnatp.setCurrentTime(currentTime);
+ }
+
+ existenceCheck(expectedFilenameList);
+ sortedContentCheck(randomOutputDir, runLength, prefix);
+ }
+
+ @Override
+ protected void addExpectedFileNamedIfItsTime_ByDate(String testId, boolean gzExtension) {
+ if (passThresholdTime(nextRolloverThreshold)) {
+ addExpectedFileName_ByDate(testId, getDateOfPreviousPeriodsStart(),
+ gzExtension);
+ recomputeRolloverThreshold(currentTime);
+ }
+ }
+}
More information about the logback-dev
mailing list