use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.
the class PatternProcessorTest method testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_US.
@Test
@ResourceLock(Resources.LOCALE)
public void testGetNextTimeWeeklyReturnsFirstDayOfNextWeek_US() {
final Locale old = Locale.getDefault();
// force 1st day of the week to be Sunday
Locale.setDefault(Locale.US);
try {
final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-W}.log.gz");
final Calendar initial = Calendar.getInstance();
// Tue, March 4, 2014
initial.set(2014, Calendar.MARCH, 4, 10, 31, 59);
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
// expect Sunday, March 9, 2014
final Calendar expected = Calendar.getInstance();
expected.set(2014, Calendar.MARCH, 9, 0, 0, 0);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
} finally {
Locale.setDefault(old);
}
}
use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.
the class PatternProcessorTest method testGetNextTimeMonthlyReturnsFirstDayOfNextMonth3.
@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth3() {
final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
final Calendar initial = Calendar.getInstance();
// 2014 Dec 31st
initial.set(2014, Calendar.DECEMBER, 31, 10, 31, 59);
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
// Expect 1st of next month: 2015 Jan 1st
final Calendar expected = Calendar.getInstance();
expected.set(2015, Calendar.JANUARY, 1, 0, 0, 0);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.
the class PatternProcessorTest method testGetNextTimeHourlyReturnsFirstMinuteOfNextHour2.
@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour2() {
final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
final Calendar initial = Calendar.getInstance();
// Tue, March 4, 2014, 23:31
initial.set(2014, Calendar.MARCH, 4, 23, 31, 59);
final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
// expect Wed, March 5, 2014, 00:00
final Calendar expected = Calendar.getInstance();
expected.set(2014, Calendar.MARCH, 5, 0, 0, 0);
expected.set(Calendar.MILLISECOND, 0);
assertEquals(format(expected.getTimeInMillis()), format(actual));
}
use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.
the class PatternProcessorTest method testDontInterpretBackslashAsEscape.
@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testDontInterpretBackslashAsEscape() {
final PatternProcessor pp = new PatternProcessor("c:\\test\\new/app-%d{HH-mm-ss}.log");
final Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 16);
cal.set(Calendar.MINUTE, 2);
cal.set(Calendar.SECOND, 15);
final StringBuilder buf = new StringBuilder();
pp.formatFileName(buf, cal.getTime(), 23);
assertEquals("c:\\test\\new/app-16-02-15.log", buf.toString());
}
use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.
the class AbstractLoggerTest method testMessageThrowsAndNullFormat.
@Test
@ResourceLock("log4j2.StatusLogger")
public void testMessageThrowsAndNullFormat() {
final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
logger.error(new TestMessage(() -> {
throw new IllegalStateException("Oops!");
}, null));
List<StatusData> statusDatalist = StatusLogger.getLogger().getStatusData();
StatusData mostRecent = statusDatalist.get(statusDatalist.size() - 1);
assertEquals(Level.WARN, mostRecent.getLevel());
assertThat(mostRecent.getFormattedStatus(), containsString("org.apache.logging.log4j.spi.AbstractLogger caught " + "java.lang.IllegalStateException logging TestMessage: "));
}
Aggregations