The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
DRFATestCase.java
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.log4j;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.TestFailure;
import junit.framework.Test;
import org.apache.log4j.*;
/**
Exhaustive test of the DailyRollingFileAppender compute algorithm.
@author Ceki Gülcü
*/
public class DRFATestCase extends TestCase {
public DRFATestCase(String name) {
super(name);
}
public
void testComputeCheckPeriod() {
DailyRollingFileAppender drfa = new DailyRollingFileAppender();
drfa.setName("testComputeCheckPeriod");
drfa.setDatePattern("yyyy-MM-dd.'log'");
drfa.activateOptions();
int x = drfa.computeCheckPeriod();
int y = DailyRollingFileAppender.TOP_OF_DAY;
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.TOP_OF_DAY);
drfa.setDatePattern("yyyy-MM-dd mm.'log'");
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.TOP_OF_MINUTE);
drfa.setDatePattern("yyyy-MM-dd a.'log'");
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.HALF_DAY);
drfa.setDatePattern("yyyy-MM-dd HH.'log'");
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.TOP_OF_HOUR);
drfa.setDatePattern("yyyy-MM.'log'");
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.TOP_OF_MONTH);
drfa.setDatePattern("'log'HH'log'");
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.TOP_OF_HOUR);
}
public
void testRC1() {
RollingCalendar rc = new RollingCalendar();
rc.setType(DailyRollingFileAppender.TOP_OF_DAY);
Calendar c = Calendar.getInstance();
// jan, mar, may, july, aug, oct, dec have 31 days
int [] M31 = {0,2,4,6,7,9,11};
for(int i = 0; i < M31.length; i ++) {
for(int d = 1; d <=31; d++) {
for(int h = 0; h < 23; h++) {
c.clear();
c.set(Calendar.YEAR, 20);
c.set(Calendar.MONTH, Calendar.JANUARY + M31[i]);
c.set(Calendar.DAY_OF_MONTH, d);
c.set(Calendar.HOUR_OF_DAY, h);
c.set(Calendar.MINUTE, 10);
c.set(Calendar.SECOND, 10);
c.set(Calendar.MILLISECOND, 88);
c.setTime(rc.getNextCheckDate(c.getTime()));
if(d == 31) {
assertEquals(c.get(Calendar.MONTH),(Calendar.JANUARY+M31[i]+1)%12);
assertEquals(c.get(Calendar.DAY_OF_MONTH), 1);
} else {
assertEquals(c.get(Calendar.MONTH), Calendar.JANUARY+M31[i]);
assertEquals(c.get(Calendar.DAY_OF_MONTH), d+1);
}
assertEquals(c.get(Calendar.HOUR_OF_DAY), 0);
assertEquals(c.get(Calendar.MINUTE), 0);
assertEquals(c.get(Calendar.SECOND), 0);
assertEquals(c.get(Calendar.MILLISECOND), 0);
}
}
}
}
public
void testRC2() {
RollingCalendar rc = new RollingCalendar();
rc.setType(DailyRollingFileAppender.TOP_OF_HOUR);
Calendar c = Calendar.getInstance();
TimeZone tz = c.getTimeZone();
// jan, mar, may, july, aug, oct, dec have 31 days
int [] M31 = {0,2,4,6,7,9,11};
for(int i = 0; i < M31.length; i ++) {
System.out.println("Month = "+(M31[i]+1));
for(int d = 1; d <= 31; d++) {
for(int h = 0; h < 23; h++) {
for(int m = 0; m <= 59; m++) {
c.clear();
c.set(Calendar.YEAR, 20);
c.set(Calendar.MONTH, Calendar.JANUARY + M31[i]);
c.set(Calendar.DAY_OF_MONTH, d);
c.set(Calendar.HOUR_OF_DAY, h);
c.set(Calendar.MINUTE, m);
c.set(Calendar.SECOND, 12);
c.set(Calendar.MILLISECOND, 88);
boolean dltState0 = c.getTimeZone().inDaylightTime(c.getTime());
c.setTime(rc.getNextCheckDate(c.getTime()));
boolean dltState1 = c.getTimeZone().inDaylightTime(c.getTime());
assertEquals(c.get(Calendar.MILLISECOND), 0);
assertEquals(c.get(Calendar.SECOND), 0);
assertEquals(c.get(Calendar.MINUTE), 0);
if(dltState0 == dltState1) {
assertEquals(c.get(Calendar.HOUR_OF_DAY), (h+1)%24);
} else {
// returning to standard time
if(dltState0) {
assertEquals(c.get(Calendar.HOUR_OF_DAY), h);
} else { // switching to day light saving time
//System.err.println("m="+m+", h="+h+", d="+d+", i="+i);
//if(h==2) {
// System.err.println(c);
//}
//assertEquals(c.get(Calendar.HOUR_OF_DAY), (h+2)%24);
}
}
if(h == 23) {
assertEquals(c.get(Calendar.DAY_OF_MONTH), (d+1)%32);
if(d == 31) {
assertEquals(c.get(Calendar.MONTH),
(Calendar.JANUARY+M31[i]+1)%12);
} else {
assertEquals(c.get(Calendar.MONTH),
Calendar.JANUARY+M31[i]);
}
} else {
assertEquals(c.get(Calendar.DAY_OF_MONTH), d);
assertEquals(c.get(Calendar.MONTH), Calendar.JANUARY+M31[i]);
}
}
}
}
}
}
public
void testRC3() {
RollingCalendar rc = new RollingCalendar();
rc.setType(DailyRollingFileAppender.TOP_OF_MINUTE);
int[] S = {0, 1, 5, 10, 21, 30, 59};
int[] M = {0, 1, 5, 10, 21, 30, 59};
Calendar c = Calendar.getInstance();
// jan, mar, may, july, aug, oct, dec have 31 days
int [] M31 = {2,9,0,4,6,7,11};
for(int i = 0; i < M31.length; i ++) {
System.out.println("Month = "+(M31[i]+1));
for(int d = 1; d <= 31; d++) {
for(int h = 0; h < 23; h++) {
for(int m = 0; m < M.length; m++) {
for(int s = 0; s < S.length; s++) {
c.clear();
c.set(Calendar.YEAR, 20);
c.set(Calendar.MONTH, Calendar.JANUARY + M31[i]);
c.set(Calendar.DAY_OF_MONTH, d);
c.set(Calendar.HOUR_OF_DAY, h);
c.set(Calendar.MINUTE, M[m]);
c.set(Calendar.SECOND, S[s]);
c.set(Calendar.MILLISECOND, 88);
c.add(Calendar.MILLISECOND, 1);
boolean dltState0 = c.getTimeZone().inDaylightTime(c.getTime());
c.setTime(rc.getNextCheckDate(c.getTime()));
c.add(Calendar.MILLISECOND, 0);
boolean dltState1 = c.getTimeZone().inDaylightTime(c.getTime());
assertEquals(c.get(Calendar.MILLISECOND), 0);
assertEquals(c.get(Calendar.SECOND), 0);
assertEquals(c.get(Calendar.MINUTE), (M[m]+1)%60);
if(M[m] == 59) {
if(dltState0 == dltState1) {
assertEquals(c.get(Calendar.HOUR_OF_DAY), (h+1)%24);
}
if(h == 23) {
assertEquals(c.get(Calendar.DAY_OF_MONTH), (d+1)%32);
if(d == 31) {
assertEquals(c.get(Calendar.MONTH),
(Calendar.JANUARY+M31[i]+1)%12);
} else {
assertEquals(c.get(Calendar.MONTH),
Calendar.JANUARY+M31[i]);
}
} else {
assertEquals(c.get(Calendar.DAY_OF_MONTH), d);
}
} else {
// allow discrepancies only if we are switching from std to dls time
if(c.get(Calendar.HOUR_OF_DAY) != h) {
c.add(Calendar.HOUR_OF_DAY, +1);
boolean dltState2 = c.getTimeZone().inDaylightTime(c.getTime());
if(dltState1 == dltState2) {
fail("No switch");
}
}
assertEquals(c.get(Calendar.DAY_OF_MONTH), d);
assertEquals(c.get(Calendar.MONTH), Calendar.JANUARY+M31[i]);
}
}
}
}
}
}
}
public
static
Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new DRFATestCase("testComputeCheckPeriod"));
suite.addTest(new DRFATestCase("testRC1"));
suite.addTest(new DRFATestCase("testRC2"));
suite.addTest(new DRFATestCase("testRC3"));
return suite;
}
}