Search in sources :

Example 21 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class PatternProcessorTest method testGetNextTimeMonthlyReturnsFirstDayOfNextYear.

@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeMonthlyReturnsFirstDayOfNextYear() {
    final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
    final Calendar initial = Calendar.getInstance();
    initial.set(2015, Calendar.DECEMBER, 28, 0, 0, 0);
    final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
    // We expect 1st day of next month
    final Calendar expected = Calendar.getInstance();
    expected.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
    expected.set(Calendar.MILLISECOND, 0);
    assertEquals(format(expected.getTimeInMillis()), format(actual));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 22 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class PatternProcessorTest method testGetNextTimeWeeklyReturnsFirstWeekInYear_US.

/**
 * Tests https://issues.apache.org/jira/browse/LOG4J2-1232
 */
@Test
@ResourceLock(Resources.LOCALE)
public void testGetNextTimeWeeklyReturnsFirstWeekInYear_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/market_data_msg.log-%d{yyyy-MM-'W'W}");
        final Calendar initial = Calendar.getInstance();
        // Monday, December 28, 2015
        initial.set(2015, Calendar.DECEMBER, 28, 0, 0, 0);
        final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
        // expect Sunday January 3, 2016
        final Calendar expected = Calendar.getInstance();
        expected.set(2016, Calendar.JANUARY, 3, 0, 0, 0);
        expected.set(Calendar.MILLISECOND, 0);
        assertEquals(format(expected.getTimeInMillis()), format(actual));
    } finally {
        Locale.setDefault(old);
    }
}
Also used : Locale(java.util.Locale) Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 23 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class PatternProcessorTest method testGetNextTimeHourlyReturnsFirstMinuteOfNextYear.

@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeHourlyReturnsFirstMinuteOfNextYear() {
    final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
    final Calendar initial = Calendar.getInstance();
    initial.set(2015, Calendar.DECEMBER, 31, 23, 31, 59);
    final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
    final Calendar expected = Calendar.getInstance();
    expected.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
    expected.set(Calendar.MILLISECOND, 0);
    assertEquals(format(expected.getTimeInMillis()), format(actual));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 24 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class PatternProcessorTest method testGetNextTimeMinutelyReturnsFirstSecondOfNextMinute.

@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeMinutelyReturnsFirstSecondOfNextMinute() {
    final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH-mm}.log.gz");
    final Calendar initial = Calendar.getInstance();
    // Tue, March 4, 2014, 10:31
    initial.set(2014, Calendar.MARCH, 4, 10, 31, 59);
    initial.set(Calendar.MILLISECOND, 0);
    assertEquals("2014/03/04 10:31:59.000", format(initial.getTimeInMillis()));
    final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
    // expect Tue, March 4, 2014, 10:32
    final Calendar expected = Calendar.getInstance();
    expected.set(2014, Calendar.MARCH, 4, 10, 32, 0);
    expected.set(Calendar.MILLISECOND, 0);
    assertEquals(format(expected.getTimeInMillis()), format(actual));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 25 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class PatternProcessorTest method testGetNextTimeMonthlyReturnsFirstDayOfNextMonth2.

@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth2() {
    final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
    final Calendar initial = Calendar.getInstance();
    // 2014 Jan 31st
    initial.set(2014, Calendar.JANUARY, 31, 10, 31, 59);
    final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
    // Expect 1st of next month: 2014 Feb 1st
    final Calendar expected = Calendar.getInstance();
    expected.set(2014, Calendar.FEBRUARY, 1, 0, 0, 0);
    expected.set(Calendar.MILLISECOND, 0);
    assertEquals(format(expected.getTimeInMillis()), format(actual));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Aggregations

Test (org.junit.jupiter.api.Test)30 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)30 Calendar (java.util.Calendar)14 Locale (java.util.Locale)6 Transaction (org.neo4j.graphdb.Transaction)4 IndexCreator (org.neo4j.graphdb.schema.IndexCreator)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 Schema (org.neo4j.graphdb.schema.Schema)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)4 Charset (java.nio.charset.Charset)2 Properties (java.util.Properties)2 Logger (org.apache.logging.log4j.Logger)2 StatusData (org.apache.logging.log4j.status.StatusData)2 HashMap (java.util.HashMap)1 StringMapMessage (org.apache.logging.log4j.message.StringMapMessage)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Nested (org.junit.jupiter.api.Nested)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Resources (org.junit.jupiter.api.parallel.Resources)1