logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
July 2009
- 10 participants
- 153 discussions

svn commit: r2390 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 31 Jul '09
by noreply.ceki@qos.ch 31 Jul '09
31 Jul '09
Author: ceki
Date: Fri Jul 31 16:00:21 2009
New Revision: 2390
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/SizeBasedRollingTest.java
Log:
- tests were not passing on Windows
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 16:00:21 2009
@@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
+import java.util.Comparator;
import java.util.List;
import ch.qos.logback.core.Context;
@@ -80,15 +81,20 @@
fileContentCheck(fileArray, runLength, prefix);
}
- public static void reverseOrderedContentCheck(String outputDirStr,
+ public static void reverseSortedContentCheck(String outputDirStr,
int runLength, String prefix) throws IOException {
File[] fileArray = getFilesInDirectory(outputDirStr);
- File[] reversedArray = new File[fileArray.length];
- for (int i = 0; i < fileArray.length; i++) {
- reversedArray[fileArray.length - 1 - i] = fileArray[i];
+
+ Arrays.sort(fileArray, new Comparator<File>() {
+ public int compare(File o1, File o2) {
+ String o1Name = o1.getName();
+ String o2Name = o2.getName();
+ return (o2Name.compareTo(o1Name));
+ }
}
- System.out.println(Arrays.toString(reversedArray));
- fileContentCheck(reversedArray, runLength, prefix);
+ );
+ System.out.println(Arrays.toString(fileArray));
+ fileContentCheck(fileArray, runLength, prefix);
}
public static void existenceCheck(List<String> filenameList) {
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java Fri Jul 31 16:00:21 2009
@@ -130,7 +130,7 @@
expectedFilenameList.add(randomOutputDir + "sizeBased-smoke.1");
existenceCheck(expectedFilenameList);
- reverseOrderedContentCheck(randomOutputDir, runLength, prefix);
+ reverseSortedContentCheck(randomOutputDir, runLength, prefix);
}
/**
@@ -143,7 +143,7 @@
RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
rfa.setLayout(layout);
rfa.setContext(context);
- rfa.setFile(randomOutputDir + "sbr-test3.log");
+ rfa.setFile(randomOutputDir + "a-sbr-test3.log");
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
fwrp.setContext(context);
@@ -168,12 +168,12 @@
rfa.doAppend("hello"+i);
}
- expectedFilenameList.add(randomOutputDir + "sbr-test3.log");
+ expectedFilenameList.add(randomOutputDir + "a-sbr-test3.log");
expectedFilenameList.add(randomOutputDir + "sbr-test3.0.gz");
expectedFilenameList.add(randomOutputDir + "sbr-test3.1.gz");
existenceCheck(expectedFilenameList);
- reverseOrderedContentCheck(randomOutputDir, runLength, prefix);
+ reverseSortedContentCheck(randomOutputDir, runLength, prefix);
}
1
0

svn commit: r2389 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/testUtil
by noreply.ceki@qos.ch 31 Jul '09
by noreply.ceki@qos.ch 31 Jul '09
31 Jul '09
Author: ceki
Date: Fri Jul 31 15:47:12 2009
New Revision: 2389
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.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
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
Log:
- cleaned up SizeBasedRollingTest
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java Fri Jul 31 15:47:12 2009
@@ -114,7 +114,7 @@
if (toRename.exists()) {
util.rename(toRenameStr, fileNamePattern.convertInt(i + 1));
} else {
- addInfo("Skipping roll=over for inexistent file " + toRenameStr);
+ addInfo("Skipping roll-over for inexistent file " + toRenameStr);
}
}
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 15:47:12 2009
@@ -8,6 +8,7 @@
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
@@ -19,17 +20,17 @@
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)
+ * 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>();
@@ -39,7 +40,6 @@
long nextRolloverThreshold; // initialized in setUp()
long currentTime; // initialized in setUp()
Calendar cal = Calendar.getInstance();
-
public void setUp() {
context.setName("test");
@@ -49,35 +49,55 @@
System.out.println(randomOutputDir);
}
- void existenceCheck(String filename) {
+ public static 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();
+
+ public static File[] getFilesInDirectory(String outputDirStr) {
+ File outputDir = new File(outputDirStr);
+ return outputDir.listFiles();
+ }
+
+ public static void fileContentCheck(File[] fileArray, int runLength,
+ String prefix) throws IOException {
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);
+
+ for (int i = 0; i < runLength; i++) {
+ witnessList.add(prefix + i);
}
assertEquals(witnessList, stringList);
}
-
- void existenceCheck(List<String> filenameList) {
+
+ public static void contentCheck(String outputDirStr, int runLength,
+ String prefix) throws IOException {
+ File[] fileArray = getFilesInDirectory(outputDirStr);
+ fileContentCheck(fileArray, runLength, prefix);
+ }
+
+ public static void reverseOrderedContentCheck(String outputDirStr,
+ int runLength, String prefix) throws IOException {
+ File[] fileArray = getFilesInDirectory(outputDirStr);
+ File[] reversedArray = new File[fileArray.length];
+ for (int i = 0; i < fileArray.length; i++) {
+ reversedArray[fileArray.length - 1 - i] = fileArray[i];
+ }
+ System.out.println(Arrays.toString(reversedArray));
+ fileContentCheck(reversedArray, runLength, prefix);
+ }
+
+ public static 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";
}
@@ -87,15 +107,15 @@
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);
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 15:47:12 2009
@@ -87,7 +87,7 @@
massageExpectedFilesToCorresponToCurrentTarget(file);
existenceCheck(expectedFilenameList);
- contentCheck(runLength, prefix);
+ contentCheck(randomOutputDir, runLength, prefix);
}
@Test
@@ -116,7 +116,7 @@
}
existenceCheck(expectedFilenameList);
- contentCheck(runLength, prefix);
+ contentCheck(randomOutputDir, runLength, prefix);
}
void massageExpectedFilesToCorresponToCurrentTarget(String file) {
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java Fri Jul 31 15:47:12 2009
@@ -1,22 +1,14 @@
-/*
- * Copyright 1999,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (C) 2000-2009, QOS.ch
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 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 static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
@@ -29,8 +21,7 @@
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.Layout;
import ch.qos.logback.core.layout.DummyLayout;
-import ch.qos.logback.core.testUtil.Env;
-import ch.qos.logback.core.util.Compare;
+import ch.qos.logback.core.layout.EchoLayout;
import ch.qos.logback.core.util.CoreTestConstants;
/**
@@ -41,19 +32,21 @@
* @author Sébastien Pennec
*
*/
-public class SizeBasedRollingTest {
-
+public class SizeBasedRollingTest extends ScaffoldingForRollingTests {
@Before
+ @Override
public void setUp() {
+ super.setUp();
{
File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.log");
+ + "sizeBased-smoke.log");
target.mkdirs();
target.delete();
}
{
- File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "sbr-test3.log");
+ File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX
+ + "sbr-test3.log");
target.mkdirs();
target.delete();
}
@@ -93,8 +86,6 @@
} catch (IllegalStateException e) {
return;
}
-
- // StatusPrinter.print(context.getStatusManager());
}
/**
@@ -104,14 +95,14 @@
public void smoke() throws Exception {
Context context = new ContextBase();
- DummyLayout<Object> layout = new DummyLayout<Object>("0123456789");
+ EchoLayout<Object> layout = new EchoLayout<Object>();
RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
rfa.setName("ROLLING");
rfa.setLayout(layout);
rfa.setContext(context);
- rfa.setFile(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.log");
-
+ // make the .log show first
+ rfa.setFile(randomOutputDir + "a-sizeBased-smoke.log");
+
FixedWindowRollingPolicy swrp = new FixedWindowRollingPolicy();
swrp.setContext(context);
SizeBasedTriggeringPolicy<Object> sbtp = new SizeBasedTriggeringPolicy<Object>();
@@ -119,11 +110,7 @@
sbtp.setMaxFileSize("100");
swrp.setMinIndex(0);
-// swrp.setActiveFileName(Constants.TEST_DIR_PREFIX
-// + "output/sizeBased-test2.log");
-
- swrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.%i");
+ swrp.setFileNamePattern(randomOutputDir + "sizeBased-smoke.%i");
swrp.setParent(rfa);
swrp.start();
@@ -131,46 +118,19 @@
rfa.setTriggeringPolicy(sbtp);
rfa.start();
- // Write exactly 10 bytes with each log
- // for (int i = 0; i < 25; i++) {
- // Thread.sleep(100);
- // if (i < 10) {
- // rfa.doAppend("Hello---" + i);
- // //logger.debug("Hello---" + i);
- // } else if (i < 100) {
- // rfa.doAppend("Hello---" + i);
- // //logger.debug("Hello--" + i);
- // }
- // }
-
- for (int i = 0; i < 45; i++) {
+ int runLength = 45;
+ String prefix = "hello";
+ for (int i = 0; i < runLength; i++) {
Thread.sleep(10);
- rfa.doAppend("hello");
+ rfa.doAppend(prefix+i);
}
- assertTrue(new File(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.log").exists());
- assertTrue(new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "sizeBased-test2.0")
- .exists());
- assertTrue(new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "sizeBased-test2.1")
- .exists());
-
- // The File.length() method is not accurate under Windows
-
- if (!Env.isWindows()) {
-
- assertTrue(Compare.compare(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.log", CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/sbr-test2.l"));
- assertTrue(Compare.compare(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.0", CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/sbr-test2.0"));
- assertTrue(Compare.compare(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sizeBased-test2.1", CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/sbr-test2.1"));
- }
+ expectedFilenameList.add(randomOutputDir + "a-sizeBased-smoke.log");
+ expectedFilenameList.add(randomOutputDir + "sizeBased-smoke.0");
+ expectedFilenameList.add(randomOutputDir + "sizeBased-smoke.1");
+ existenceCheck(expectedFilenameList);
- // StatusPrinter.print(context.getStatusManager());
+ reverseOrderedContentCheck(randomOutputDir, runLength, prefix);
}
/**
@@ -179,11 +139,11 @@
@Test
public void test3() throws Exception {
Context context = new ContextBase();
- DummyLayout<Object> layout = new DummyLayout<Object>("0123456789");
+ EchoLayout<Object> layout = new EchoLayout<Object>();
RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
rfa.setLayout(layout);
rfa.setContext(context);
- rfa.setFile(CoreTestConstants.OUTPUT_DIR_PREFIX + "sbr-test3.log");
+ rfa.setFile(randomOutputDir + "sbr-test3.log");
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
fwrp.setContext(context);
@@ -192,54 +152,29 @@
sbtp.setMaxFileSize("100");
fwrp.setMinIndex(0);
- //fwrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
- fwrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX
- + "sbr-test3.%i.gz");
+ // fwrp.setActiveFileName(Constants.TEST_DIR_PREFIX +
+ // "output/sbr-test3.log");
+ fwrp.setFileNamePattern(randomOutputDir + "sbr-test3.%i.gz");
fwrp.setParent(rfa);
fwrp.start();
rfa.setRollingPolicy(fwrp);
rfa.setTriggeringPolicy(sbtp);
rfa.start();
- // Write exactly 10 bytes with each log
- // for (int i = 0; i < 25; i++) {
- // Thread.sleep(100);
- // if (i < 10) {
- // rfa.doAppend("Hello---" + i);
- // //logger.debug("Hello---" + i);
- // } else if (i < 100) {
- // rfa.doAppend("Hello---" + i);
- // //logger.debug("Hello--" + i);
- // }
- // }
-
- for (int i = 0; i < 25; i++) {
+ int runLength = 40;
+ String prefix = "hello";
+ for (int i = 0; i < runLength; i++) {
Thread.sleep(10);
- rfa.doAppend("hello");
+ rfa.doAppend("hello"+i);
}
- assertTrue(new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "sbr-test3.log")
- .exists());
- assertTrue(new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "sbr-test3.0.gz")
- .exists());
- assertTrue(new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "sbr-test3.1.gz")
- .exists());
-
- if (!Env.isWindows()) {
-
- assertTrue(Compare.compare(
- CoreTestConstants.OUTPUT_DIR_PREFIX+"sbr-test3.log",
- CoreTestConstants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.l"));
- assertTrue(Compare.gzCompare(
- CoreTestConstants.OUTPUT_DIR_PREFIX+"sbr-test3.0.gz",
- CoreTestConstants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.0.gz"));
- assertTrue(Compare.gzCompare(
- CoreTestConstants.OUTPUT_DIR_PREFIX+"sbr-test3.1.gz",
- CoreTestConstants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.1.gz"));
- }
+ expectedFilenameList.add(randomOutputDir + "sbr-test3.log");
+ expectedFilenameList.add(randomOutputDir + "sbr-test3.0.gz");
+ expectedFilenameList.add(randomOutputDir + "sbr-test3.1.gz");
- // StatusPrinter.print(context.getStatusManager());
+ existenceCheck(expectedFilenameList);
+ reverseOrderedContentCheck(randomOutputDir, runLength, prefix);
+
}
-
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java Fri Jul 31 15:47:12 2009
@@ -16,12 +16,21 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
+import java.util.zip.GZIPInputStream;
public class FileToBufferUtil {
static public void readIntoList(File file, List<String> stringList)
throws IOException {
+ if(file.getName().endsWith(".gz")) {
+ gzFileReadIntoList(file, stringList);
+ } else {
+ regularReadIntoList(file, stringList);
+ }
+ }
+
+ static public void regularReadIntoList(File file, List<String> stringList) throws IOException {
FileInputStream fis = new FileInputStream(file);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String line;
@@ -30,4 +39,16 @@
}
in.close();
}
+
+ static public void gzFileReadIntoList(File file, List<String> stringList) throws IOException {
+ FileInputStream fis = new FileInputStream(file);
+ GZIPInputStream gzis = new GZIPInputStream(fis);
+ BufferedReader in = new BufferedReader(new InputStreamReader(gzis));
+ String line;
+ while( (line = in.readLine()) != null) {
+ stringList.add(line);
+ }
+ in.close();
+ }
+
}
1
0

svn commit: r2388 - in logback/trunk/logback-core/src/test: input java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 31 Jul '09
by noreply.ceki@qos.ch 31 Jul '09
31 Jul '09
Author: ceki
Date: Fri Jul 31 13:37:01 2009
New Revision: 2388
Modified:
logback/trunk/logback-core/src/test/input/ (props changed)
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
Log:
- minor changes
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java Fri Jul 31 13:37:01 2009
@@ -30,7 +30,7 @@
/**
* @author Ceki Gulcu
*/
-public class CompressTest {
+public class CompressTest {
Context context = new ContextBase();
@@ -39,9 +39,11 @@
// Copy source files
// Delete output files
{
- File source = new File(CoreTestConstants.TEST_DIR_PREFIX + "input/compress1.copy");
- File dest = new File(CoreTestConstants.TEST_DIR_PREFIX + "input/compress1.txt");
-
+ File source = new File(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress1.copy");
+ File dest = new File(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress1.txt");
+
copy(source, dest);
File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX
+ "compress1.txt.gz");
@@ -49,8 +51,10 @@
target.delete();
}
{
- File source = new File(CoreTestConstants.TEST_DIR_PREFIX + "input/compress2.copy");
- File dest = new File(CoreTestConstants.TEST_DIR_PREFIX + "input/compress2.txt");
+ File source = new File(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress2.copy");
+ File dest = new File(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress2.txt");
copy(source, dest);
File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX
+ "compress2.txt.gz");
@@ -58,8 +62,10 @@
target.delete();
}
{
- File source = new File(CoreTestConstants.TEST_DIR_PREFIX + "input/compress3.copy");
- File dest = new File(CoreTestConstants.TEST_DIR_PREFIX + "input/compress3.txt");
+ File source = new File(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress3.copy");
+ File dest = new File(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress3.txt");
copy(source, dest);
File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX
+ "compress3.txt.zip");
@@ -68,13 +74,13 @@
}
}
-
@Test
public void test1() throws Exception {
Compressor compressor = new Compressor(CompressionMode.GZ);
compressor.setContext(context);
- compressor.compress(CoreTestConstants.TEST_DIR_PREFIX + "input/compress1.txt",
- CoreTestConstants.OUTPUT_DIR_PREFIX + "compress1.txt.gz");
+ compressor.compress(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress1.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
+ + "compress1.txt.gz");
StatusChecker checker = new StatusChecker(context);
assertTrue(checker.isErrorFree());
@@ -87,8 +93,9 @@
public void test2() throws Exception {
Compressor compressor = new Compressor(CompressionMode.GZ);
compressor.setContext(context);
- compressor.compress(CoreTestConstants.TEST_DIR_PREFIX + "input/compress2.txt",
- CoreTestConstants.OUTPUT_DIR_PREFIX + "compress2.txt");
+ compressor.compress(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress2.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
+ + "compress2.txt");
StatusChecker checker = new StatusChecker(context);
assertTrue(checker.isErrorFree());
@@ -102,14 +109,16 @@
public void test3() throws Exception {
Compressor compressor = new Compressor(CompressionMode.ZIP);
compressor.setContext(context);
- compressor.compress(
- CoreTestConstants.TEST_DIR_PREFIX + "input/compress3.txt",
- CoreTestConstants.OUTPUT_DIR_PREFIX + "compress3.txt");
+ compressor.compress(CoreTestConstants.TEST_DIR_PREFIX
+ + "input/compress3.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
+ + "compress3.txt");
StatusChecker checker = new StatusChecker(context);
assertTrue(checker.isErrorFree());
- // assertTrue(Compare.compare("output/compress3.txt.zip",
- // "witness/compress3.txt.zip"));
+ // we don't know how to compare .zip files
+ // assertTrue(Compare.compare(CoreTestConstants.OUTPUT_DIR_PREFIX
+ // + "compress3.txt.zip", CoreTestConstants.TEST_DIR_PREFIX
+ // + "witness/compress3.txt.zip"));
}
private void copy(File src, File dst) throws IOException {
1
0

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
by noreply.ceki@qos.ch 31 Jul '09
by noreply.ceki@qos.ch 31 Jul '09
31 Jul '09
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ülcü
*/
-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)));
- }
}
1
0
Hello,
Slightly odd question, but it is logback related. I'm writing a library to redirect System.out and System.err to SLF4J. I'm envisaging this being used in application servers. I'd like it to work "correctly" with SLF4J implementations like Logback, so if the app server has child first class loading and SLF4J and logback are in webapp A's lib dir, a call to System.out.println within webapp A will be handled as per the logback.xml in webapp A's classes folder, regardless of other webapps with different config.
The only way that is possible (as far as I can see) is to work out from the thread calling the System.out methods which web app it was that made the call - and I've found the method getContextClassLoader on Thread which looks hopeful! However, I'm not completely confident that app servers that implement child first class loading will set that to the a web app specific class loader.
Does anyone know? Do some app servers use this, and others not? Might save me considerable experimentation time if this is well known info that I just don't happen to know yet.
Thanks,
Rob
2
3

[JIRA] Created: (LBCLASSIC-114) add a context listener that automatically configures JMX
by Philippe Marschall (JIRA) 31 Jul '09
by Philippe Marschall (JIRA) 31 Jul '09
31 Jul '09
add a context listener that automatically configures JMX
--------------------------------------------------------
Key: LBCLASSIC-114
URL: http://jira.qos.ch/browse/LBCLASSIC-114
Project: logback-classic
Issue Type: New Feature
Components: Other
Reporter: Philippe Marschall
Assignee: Logback dev list
Priority: Minor
Setting up logback JMX for a web application requires a bit too many manual steps. It is not enough to simply add <jmxConfigurator /> to the configuration file. You should also set the context path but often you can't know that in advance. In addition you still need to write custom code to [prevent memory leaks|http://logback.qos.ch/manual/jmxConfig.html#leak]. These issues could all be addressed by a custom context listener.
<listener>
<listener-class>ch.qos.logback.classic.selector.servlet.JmxEnabler</listener-class>
</listener>
Code attached.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
2
4

svn commit: r2386 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 23:30:59 2009
New Revision: 2386
Modified:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
Log:
Added another test case
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 Thu Jul 30 23:30:59 2009
@@ -128,9 +128,38 @@
massageExpectedFilesToCorresponToCurrentTarget(file);
existenceCheck(expectedFilenameList);
contentCheck(runLength, prefix);
-
}
+ @Test
+ public void noCompression_FileNotSet_NoRestart_2() throws Exception {
+ String testId = "test1";
+ initRFA(rfa1, null);
+ sizeThreshold = 300;
+ initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{" + DATE_PATTERN
+ + "}-%i.txt", sizeThreshold, currentTime, 0);
+
+ addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
+ fileIndexCounter, false);
+
+ incCurrentTime(100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ int runLength = 100;
+ String prefix = "Hello -----------------";
+
+ for (int i = 0; i < runLength; i++) {
+ String msg = prefix + i;
+ rfa1.doAppend(msg);
+ addExpectedFileNamedIfItsTime(testId, msg, false);
+ incCurrentTime(20);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ existenceCheck(expectedFilenameList);
+ contentCheck(runLength, prefix);
+ }
+
+
void existenceCheck(String filename) {
assertTrue("File " + filename + " does not exist", new File(filename)
.exists());
1
0

svn commit: r2385 - in logback/trunk/logback-core/src/test/java/ch/qos/logback/core: rolling testUtil
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 23:27:25 2009
New Revision: 2385
Added:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
Modified:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.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
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
Log:
Initial test case for SizeAndTimeBasedFileNamingAndTriggeringPolicy
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java Thu Jul 30 23:27:25 2009
@@ -7,6 +7,7 @@
@Suite.SuiteClasses( { RenamingTest.class, SizeBasedRollingTest.class,
TimeBasedRollingTest.class, TimeBasedRollingWithCleanTest.class,
MultiThreadedRollingTest.class,
+ SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.class,
ch.qos.logback.core.rolling.helper.PackageTest.class })
public class PackageTest {
}
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 Thu Jul 30 23:27:25 2009
@@ -1,7 +1,20 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, 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 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;
@@ -14,16 +27,15 @@
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.Compare;
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
- + "/";
+ String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
SizeAndTimeBasedFileNamingAndTriggeringPolicy<Object> satbfnatPolicy = new SizeAndTimeBasedFileNamingAndTriggeringPolicy<Object>();
@@ -42,15 +54,16 @@
int fileSize = 0;
int fileIndexCounter = 0;
int sizeThreshold;
-
+
@Before
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)));
+ System.out.println(randomOutputDir);
+ // System.out.println("at setUp() currentTime="
+ // + sdf.format(new Date(currentTime)));
}
@@ -68,11 +81,12 @@
}
}
- void initTRBP(RollingFileAppender<Object> rfa, TimeBasedRollingPolicy<Object> tbrp,
- String filenamePattern, int sizeThreshold, long givenTime, long lastCheck) {
+ void initTRBP(RollingFileAppender<Object> rfa,
+ TimeBasedRollingPolicy<Object> tbrp, String filenamePattern,
+ int sizeThreshold, long givenTime, long lastCheck) {
tbrp.setContext(context);
- satbfnatPolicy.setMaxFileSize(""+sizeThreshold);
+ satbfnatPolicy.setMaxFileSize("" + sizeThreshold);
tbrp.setTimeBasedTriggering(satbfnatPolicy);
tbrp.setFileNamePattern(filenamePattern);
tbrp.setParent(rfa);
@@ -88,81 +102,113 @@
@Test
public void noCompression_FileBSet_NoRestart_1() throws Exception {
String testId = "test1";
- System.out.println(randomOutputDir);
String file = randomOutputDir + "toto.log";
initRFA(rfa1, file);
sizeThreshold = 300;
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{" + DATE_PATTERN
+ "}-%i.txt", sizeThreshold, currentTime, 0);
- addExpectedFileName(testId, getDateOfCurrentPeriodsStart(), fileIndexCounter, false);
+ addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
+ fileIndexCounter, false);
incCurrentTime(100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
- for (int i = 0; i < 100; i++) {
- String msg = "Hello -----------------" + i;
+ int runLength = 100;
+ String prefix = "Hello -----------------";
+
+ for (int i = 0; i < runLength; i++) {
+ String msg = prefix + i;
rfa1.doAppend(msg);
addExpectedFileNamedIfItsTime(testId, msg, false);
incCurrentTime(20);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
-
massageExpectedFilesToCorresponToCurrentTarget(file);
- int i = 0;
- for (String fn : expectedFilenameList) {
- System.out.println(fn);
- //assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- // + "witness/rolling/satb-test1." + i++));
+ existenceCheck(expectedFilenameList);
+ 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) {
+
+ void addExpectedFileNamedIfItsTime(String testId, String msg,
+ boolean gzExtension) {
fileSize += msg.getBytes().length;
-
+
if (passThresholdTime(nextRolloverThreshold)) {
fileIndexCounter = 0;
fileSize = 0;
- addExpectedFileName(testId, getDateOfCurrentPeriodsStart(), fileIndexCounter,
- gzExtension);
+ addExpectedFileName(testId, getDateOfCurrentPeriodsStart(),
+ fileIndexCounter, gzExtension);
recomputeRolloverThreshold(currentTime);
return;
}
-
- // windows can delay file size changes
- if((fileIndexCounter <= 1) && fileSize > sizeThreshold) {
- addExpectedFileName(testId, getDateOfCurrentPeriodsStart(), ++fileIndexCounter,
- gzExtension);
+
+ // 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 = CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-" + sdf.format(date)+"-"+fileIndexCounter+".txt";
+ void addExpectedFileName(String testId, Date date, int fileIndexCounter,
+ boolean gzExtension) {
+
+ String fn = randomOutputDir + testId + "-" + sdf.format(date) + "-"
+ + fileIndexCounter + ".txt";
if (gzExtension) {
fn += ".gz";
}
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 Thu Jul 30 23:27:25 2009
@@ -40,13 +40,13 @@
* with witness files.
*
* <pre>
- * Compression file option Stop/Restart
- * Test1 NO BLANK NO
- * Test2 YES BLANK NO
- * Test3 NO BLANK YES
- * Test4 NO SET YES
- * Test5 NO SET NO
- * Test6 YES SET NO
+ * Compression file option Stop/Restart
+ * Test1 NO BLANK NO
+ * Test2 YES BLANK NO
+ * Test3 NO BLANK YES
+ * Test4 NO SET YES
+ * Test5 NO SET NO
+ * Test6 YES SET NO
* </pre>
*
* @author Ceki Gülcü
@@ -60,10 +60,10 @@
Context context = new ContextBase();
RollingFileAppender<Object> rfa1 = new RollingFileAppender<Object>();
- TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
+ TimeBasedRollingPolicy<Object> tbrp1 = new TimeBasedRollingPolicy<Object>();
RollingFileAppender<Object> rfa2 = new RollingFileAppender<Object>();
- TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
+ TimeBasedRollingPolicy<Object> tbrp2 = new TimeBasedRollingPolicy<Object>();
Calendar cal = Calendar.getInstance();
long currentTime; // initialized in setUp()
@@ -76,7 +76,8 @@
cal.set(Calendar.MILLISECOND, 333);
currentTime = cal.getTimeInMillis();
recomputeRolloverThreshold(currentTime);
- System.out.println("at setUp() currentTime=" + sdf.format(new Date(currentTime)));
+ System.out.println("at setUp() currentTime="
+ + sdf.format(new Date(currentTime)));
// Delete .log files
deleteStaleLogFile("test4.log");
@@ -103,11 +104,12 @@
}
}
- void initTRBP(RollingFileAppender<Object> rfa, TimeBasedRollingPolicy tbrp,
+ void initTRBP(RollingFileAppender<Object> rfa, TimeBasedRollingPolicy<Object> tbrp,
String filenamePattern, long givenTime, long lastCheck) {
tbrp.setContext(context);
tbrp.setFileNamePattern(filenamePattern);
tbrp.setParent(rfa);
+ tbrp.timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
tbrp.timeBasedTriggering.setCurrentTime(givenTime);
if (lastCheck != 0) {
tbrp.timeBasedTriggering.setDateInCurrentPeriod(new Date(lastCheck));
@@ -222,7 +224,7 @@
+ "witness/rolling/tbr-" + testId + "." + i++));
}
}
-
+
/**
* Without compression, file option set, with stop/restart
*/
@@ -293,7 +295,7 @@
incCurrentTime(2000);
initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
- initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
+ initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ DATE_PATTERN + "}", currentTime, fileTimestamp);
for (int i = 0; i <= 2; i++) {
@@ -407,7 +409,8 @@
}
void addExpectedFileName_ByDate(String testId, Date date, boolean gzExtension) {
- String fn = CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-" + sdf.format(date);
+ String fn = CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-"
+ + sdf.format(date);
if (gzExtension) {
fn += ".gz";
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java Thu Jul 30 23:27:25 2009
@@ -72,12 +72,13 @@
rfa.setContext(context);
rfa.setLayout(layout);
// rfa.setFile(Constants.OUTPUT_DIR_PREFIX + "clean.txt");
- TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+ TimeBasedRollingPolicy<Object> tbrp = new TimeBasedRollingPolicy<Object>();
tbrp.setContext(context);
tbrp.setFileNamePattern(fileNamePattern);
tbrp.setMaxHistory(maxHistory);
tbrp.setParent(rfa);
+ tbrp.timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
tbrp.timeBasedTriggering.setCurrentTime(currentTime);
tbrp.start();
rfa.setRollingPolicy(tbrp);
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java Thu Jul 30 23:27:25 2009
@@ -0,0 +1,33 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, 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.testUtil;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+
+public class FileToBufferUtil {
+
+ static public void readIntoList(File file, List<String> stringList)
+ throws IOException {
+
+ FileInputStream fis = new FileInputStream(file);
+ BufferedReader in = new BufferedReader(new InputStreamReader(fis));
+ String line;
+ while( (line = in.readLine()) != null) {
+ stringList.add(line);
+ }
+ in.close();
+ }
+}
1
0

svn commit: r2384 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 21:53:35 2009
New Revision: 2384
Added:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
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/SizeBasedTriggeringPolicy.java
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/helper/FileNamePattern.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
ongoing work
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java Thu Jul 30 21:53:35 2009
@@ -19,9 +19,9 @@
long time = getCurrentTime();
if (time >= nextCheck) {
- Date dateInElapsedPeriod = dateInCurrentPeriod;
+ Date dateOfElapsedPeriod = dateInCurrentPeriod;
elapsedPeriodsFileName = tbrp.fileNamePatternWCS
- .convert(dateInElapsedPeriod);
+ .convert(dateOfElapsedPeriod);
updateDateInCurrentPeriod(time);
computeNextCheck();
return true;
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 Thu Jul 30 21:53:35 2009
@@ -12,27 +12,67 @@
import java.io.File;
import java.util.Date;
-public class SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
+import ch.qos.logback.core.util.FileSize;
+public class SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> extends
+ TimeBasedFileNamingAndTriggeringPolicyBase<E> {
+
+ int currentPeriodsCounter = 0;
+ FileSize maxFileSize;
+ String maxFileSizeAsString;
@Override
public void start() {
super.start();
started = true;
- }
+ }
+
+ // IMPORTANT: This field can be updated by multiple threads. It follows that
+ // its values may *not* be incremented sequentially. However, we don't care
+ // about the actual value of the field except that from time to time the
+ // expression (invocationCounter++ & 0xF) == 0xF) should be true.
+ private int invocationCounter;
public boolean isTriggeringEvent(File activeFile, final E event) {
long time = getCurrentTime();
-
if (time >= nextCheck) {
Date dateInElapsedPeriod = dateInCurrentPeriod;
elapsedPeriodsFileName = tbrp.fileNamePatternWCS
- .convert(dateInElapsedPeriod);
+ .convertMultipleArguments(dateInElapsedPeriod, currentPeriodsCounter);
+ currentPeriodsCounter = 0;
updateDateInCurrentPeriod(time);
computeNextCheck();
return true;
- } else {
+ }
+
+ // for performance reasons, check for changes every 16 invocations
+ if (((invocationCounter++) & 0xF) != 0xF) {
return false;
}
+
+ if (activeFile.length() >= maxFileSize.getSize()) {
+ elapsedPeriodsFileName = tbrp.fileNamePatternWCS
+ .convertMultipleArguments(dateInCurrentPeriod, currentPeriodsCounter);
+ currentPeriodsCounter++;
+ return true;
+ }
+
+ return false;
}
+
+ @Override
+ public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
+ return tbrp.fileNamePatternWCS.convertMultipleArguments(
+ dateInCurrentPeriod, currentPeriodsCounter);
+ }
+
+ public String getMaxFileSize() {
+ return maxFileSizeAsString;
+ }
+
+ public void setMaxFileSize(String maxFileSize) {
+ this.maxFileSizeAsString = maxFileSize;
+ this.maxFileSize = FileSize.valueOf(maxFileSize);
+ }
+
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicy.java Thu Jul 30 21:53:35 2009
@@ -15,37 +15,46 @@
import ch.qos.logback.core.util.FileSize;
/**
- * SizeBasedTriggeringPolicy looks at size of the file being
- * currently written to. If it grows bigger than the specified size,
- * the FileAppender using the SizeBasedTriggeringPolicy rolls the file
- * and creates a new one.
+ * SizeBasedTriggeringPolicy looks at size of the file being currently written
+ * to. If it grows bigger than the specified size, the FileAppender using the
+ * SizeBasedTriggeringPolicy rolls the file and creates a new one.
*
* For more information about this policy, please refer to the online manual at
* http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy
*
* @author Ceki Gülcü
- *
+ *
*/
public class SizeBasedTriggeringPolicy<E> extends TriggeringPolicyBase<E> {
-
+
public static final String SEE_SIZE_FORMAT = "http://logback.qos.ch/codes.html#sbtp_size_format";
/**
* The default maximum file size.
*/
public static final long DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
-
- String maxFileSizeAsString = Long.toString(DEFAULT_MAX_FILE_SIZE);
+
+ String maxFileSizeAsString = Long.toString(DEFAULT_MAX_FILE_SIZE);
FileSize maxFileSize;
public SizeBasedTriggeringPolicy() {
}
public SizeBasedTriggeringPolicy(final String maxFileSize) {
- setMaxFileSize(maxFileSize);
+ setMaxFileSize(maxFileSize);
}
+ // IMPORTANT: This field can be updated by multiple threads. It follows that
+ // its values may *not* be incremented sequentially. However, we don't care
+ // about the actual value of the field except that from time to time the
+ // expression (invocationCounter++ & 0xF) == 0xF) should be true.
+ private int invocationCounter;
+
public boolean isTriggeringEvent(final File activeFile, final E event) {
- //System.out.println("Size"+file.length());
+ // for performance reasons, check for changes every 16 invocations
+ if (((invocationCounter++) & 0xF) != 0xF) {
+ return false;
+ }
+
return (activeFile.length() >= maxFileSize.getSize());
}
@@ -57,36 +66,34 @@
this.maxFileSizeAsString = maxFileSize;
this.maxFileSize = FileSize.valueOf(maxFileSize);
}
-
+
long toFileSize(String value) {
- if(value == null)
+ if (value == null)
return DEFAULT_MAX_FILE_SIZE;
String s = value.trim().toUpperCase();
long multiplier = 1;
int index;
- if((index = s.indexOf("KB")) != -1) {
+ if ((index = s.indexOf("KB")) != -1) {
multiplier = 1024;
s = s.substring(0, index);
- }
- else if((index = s.indexOf("MB")) != -1) {
- multiplier = 1024*1024;
+ } else if ((index = s.indexOf("MB")) != -1) {
+ multiplier = 1024 * 1024;
s = s.substring(0, index);
- }
- else if((index = s.indexOf("GB")) != -1) {
- multiplier = 1024*1024*1024;
+ } else if ((index = s.indexOf("GB")) != -1) {
+ multiplier = 1024 * 1024 * 1024;
s = s.substring(0, index);
}
- if(s != null) {
+ if (s != null) {
try {
return Long.valueOf(s).longValue() * multiplier;
- }
- catch (NumberFormatException e) {
- addError("[" + s + "] is not in proper int format. Please refer to "+SEE_SIZE_FORMAT);
+ } catch (NumberFormatException e) {
+ addError("[" + s + "] is not in proper int format. Please refer to "
+ + SEE_SIZE_FORMAT);
addError("[" + value + "] not in expected format.", e);
}
}
return DEFAULT_MAX_FILE_SIZE;
- }
+ }
}
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 Thu Jul 30 21:53:35 2009
@@ -46,8 +46,7 @@
private int maxHistory = NO_DELETE_HISTORY;
private TimeBasedCleaner tbCleaner;
- TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();
-
+ TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering;
public void start() {
// set the LR for our utility object
renameUtil.setContext(this.context);
@@ -72,6 +71,9 @@
addInfo("Will use the pattern " + fileNamePatternWCS
+ " for the active file");
+ if(timeBasedTriggering == null) {
+ timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();
+ }
timeBasedTriggering.setContext(context);
timeBasedTriggering.setTimeBasedRollingPolicy(this);
timeBasedTriggering.start();
@@ -82,6 +84,10 @@
}
}
+ public void setTimeBasedTriggering(TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering) {
+ this.timeBasedTriggering = timeBasedTriggering;
+ }
+
static String computeFileNameStr_WCS(String fileNamePatternStr,
CompressionMode compressionMode) {
int len = fileNamePatternStr.length();
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Thu Jul 30 21:53:35 2009
@@ -10,9 +10,7 @@
package ch.qos.logback.core.rolling.helper;
-import java.util.Date;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import ch.qos.logback.core.Context;
@@ -94,7 +92,7 @@
}
- public String convertList(List<Object> objectList) {
+ public String convertMultipleArguments(Object... objectList) {
StringBuilder buf = new StringBuilder();
Converter<Object> c = headTokenConverter;
while (c != null) {
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java Thu Jul 30 21:53:35 2009
@@ -0,0 +1,169 @@
+package ch.qos.logback.core.rolling;
+
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Date;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+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.RandomUtil;
+import ch.qos.logback.core.util.Compare;
+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
+ + "/";
+
+ 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
+ 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)));
+
+ }
+
+ // assuming rollover every second
+ void recomputeRolloverThreshold(long ct) {
+ long delta = ct % 1000;
+ nextRolloverThreshold = (ct - delta) + 1000;
+ }
+
+ void initRFA(RollingFileAppender<Object> rfa, String filename) {
+ rfa.setContext(context);
+ rfa.setLayout(layout);
+ if (filename != null) {
+ rfa.setFile(filename);
+ }
+ }
+
+ void initTRBP(RollingFileAppender<Object> rfa, TimeBasedRollingPolicy<Object> tbrp,
+ String filenamePattern, int sizeThreshold, long givenTime, long lastCheck) {
+
+ tbrp.setContext(context);
+ satbfnatPolicy.setMaxFileSize(""+sizeThreshold);
+ tbrp.setTimeBasedTriggering(satbfnatPolicy);
+ tbrp.setFileNamePattern(filenamePattern);
+ tbrp.setParent(rfa);
+ tbrp.timeBasedTriggering.setCurrentTime(givenTime);
+ if (lastCheck != 0) {
+ tbrp.timeBasedTriggering.setDateInCurrentPeriod(new Date(lastCheck));
+ }
+ rfa.setRollingPolicy(tbrp);
+ tbrp.start();
+ rfa.start();
+ }
+
+ @Test
+ public void noCompression_FileBSet_NoRestart_1() throws Exception {
+ String testId = "test1";
+ System.out.println(randomOutputDir);
+ String file = randomOutputDir + "toto.log";
+ initRFA(rfa1, file);
+ sizeThreshold = 300;
+ initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{" + DATE_PATTERN
+ + "}-%i.txt", sizeThreshold, currentTime, 0);
+
+ addExpectedFileName(testId, getDateOfCurrentPeriodsStart(), fileIndexCounter, false);
+
+ incCurrentTime(100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ for (int i = 0; i < 100; i++) {
+ String msg = "Hello -----------------" + i;
+ rfa1.doAppend(msg);
+ addExpectedFileNamedIfItsTime(testId, msg, false);
+ incCurrentTime(20);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+
+ massageExpectedFilesToCorresponToCurrentTarget(file);
+ int i = 0;
+ for (String fn : expectedFilenameList) {
+ System.out.println(fn);
+ //assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+ // + "witness/rolling/satb-test1." + i++));
+ }
+ }
+
+ 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;
+
+ if (passThresholdTime(nextRolloverThreshold)) {
+ fileIndexCounter = 0;
+ fileSize = 0;
+ addExpectedFileName(testId, getDateOfCurrentPeriodsStart(), fileIndexCounter,
+ gzExtension);
+ recomputeRolloverThreshold(currentTime);
+ return;
+ }
+
+ // windows can delay file size changes
+ 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 = CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-" + sdf.format(date)+"-"+fileIndexCounter+".txt";
+ if (gzExtension) {
+ fn += ".gz";
+ }
+ 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/SizeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java Thu Jul 30 21:53:35 2009
@@ -68,7 +68,7 @@
* ActiveFileName is not set.
*/
@Test
- public void test1() throws Exception {
+ public void activeFileNameNotSet() throws Exception {
// We purposefully use the \n as the line separator.
// This makes the regression test system independent.
Context context = new ContextBase();
@@ -101,7 +101,7 @@
* Test basic rolling functionality.
*/
@Test
- public void test2() throws Exception {
+ public void smoke() throws Exception {
Context context = new ContextBase();
DummyLayout<Object> layout = new DummyLayout<Object>("0123456789");
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Thu Jul 30 21:53:35 2009
@@ -11,9 +11,7 @@
import static org.junit.Assert.assertEquals;
-import java.util.ArrayList;
import java.util.Calendar;
-import java.util.List;
import org.junit.Test;
@@ -102,18 +100,10 @@
@Test
public void objectListConverter() {
- List<Object> oList = new ArrayList<Object>();
-
Calendar cal = Calendar.getInstance();
cal.set(2003, 4, 20, 17, 55);
-
- oList.add(cal.getTime());
- oList.add(79);
-
-
FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt", context);
-
- assertEquals("foo-2003.05.20-79.txt", fnp.convertList(oList));
+ assertEquals("foo-2003.05.20-79.txt", fnp.convertMultipleArguments(cal.getTime(), 79));
}
}
1
0

svn commit: r2383 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 19:00:08 2009
New Revision: 2383
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
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/TimeBasedFileNamingAndTriggeringPolicyBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
Removed convertDate method in FileNamePattern
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java Thu Jul 30 19:00:08 2009
@@ -21,7 +21,7 @@
if (time >= nextCheck) {
Date dateInElapsedPeriod = dateInCurrentPeriod;
elapsedPeriodsFileName = tbrp.fileNamePatternWCS
- .convertDate(dateInElapsedPeriod);
+ .convert(dateInElapsedPeriod);
updateDateInCurrentPeriod(time);
computeNextCheck();
return true;
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 Thu Jul 30 19:00:08 2009
@@ -27,7 +27,7 @@
if (time >= nextCheck) {
Date dateInElapsedPeriod = dateInCurrentPeriod;
elapsedPeriodsFileName = tbrp.fileNamePatternWCS
- .convertDate(dateInElapsedPeriod);
+ .convert(dateInElapsedPeriod);
updateDateInCurrentPeriod(time);
computeNextCheck();
return true;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java Thu Jul 30 19:00:08 2009
@@ -79,7 +79,7 @@
}
public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
- return tbrp.fileNamePatternWCS.convertDate(dateInCurrentPeriod);
+ return tbrp.fileNamePatternWCS.convert(dateInCurrentPeriod);
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Thu Jul 30 19:00:08 2009
@@ -128,10 +128,6 @@
return convert(integerArg);
}
- public String convertDate(Date date) {
- return convert(date);
- }
-
public void setPattern(String pattern) {
if (pattern != null) {
// Trailing spaces in the pattern are assumed to be undesired.
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedCleaner.java Thu Jul 30 19:00:08 2009
@@ -30,7 +30,7 @@
public void clean(Date now) {
Date date2delete = rc.getRelativeDate(now, numberOfPeriods);
- String filename = fileNamePattern.convertDate(date2delete);
+ String filename = fileNamePattern.convert(date2delete);
File file2Delete = new File(filename);
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Thu Jul 30 19:00:08 2009
@@ -83,13 +83,13 @@
FileNamePattern pp = new FileNamePattern("foo%d{yyyy.MM.dd}", context);
- assertEquals("foo2003.05.20", pp.convertDate(cal.getTime()));
+ assertEquals("foo2003.05.20", pp.convert(cal.getTime()));
pp = new FileNamePattern("foo%d{yyyy.MM.dd HH:mm}", context);
- assertEquals("foo2003.05.20 17:55", pp.convertDate(cal.getTime()));
+ assertEquals("foo2003.05.20 17:55", pp.convert(cal.getTime()));
pp = new FileNamePattern("%d{yyyy.MM.dd HH:mm} foo", context);
- assertEquals("2003.05.20 17:55 foo", pp.convertDate(cal.getTime()));
+ assertEquals("2003.05.20 17:55 foo", pp.convert(cal.getTime()));
}
1
0