Search in sources :

Example 11 with DummyFileAttributes

use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.

the class IfLastModifiedTest method testAcceptsIfFileAgeExceedsDuration.

@Test
public void testAcceptsIfFileAgeExceedsDuration() {
    final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"));
    final DummyFileAttributes attrs = new DummyFileAttributes();
    final long age = 33 * 1000 + 5;
    attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age);
    assertTrue(filter.accept(null, null, attrs));
}
Also used : DummyFileAttributes(org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes) Test(org.junit.jupiter.api.Test)

Example 12 with DummyFileAttributes

use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.

the class IfLastModifiedTest method testDoesNotAcceptIfFileAgeLessThanDuration.

@Test
public void testDoesNotAcceptIfFileAgeLessThanDuration() {
    final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"));
    final DummyFileAttributes attrs = new DummyFileAttributes();
    final long age = 33 * 1000 - 5;
    attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age);
    assertFalse(filter.accept(null, null, attrs));
}
Also used : DummyFileAttributes(org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes) Test(org.junit.jupiter.api.Test)

Example 13 with DummyFileAttributes

use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.

the class IfAccumulatedFileSizeTest method testAcceptOnceThresholdExceeded.

@Test
public void testAcceptOnceThresholdExceeded() {
    final DummyFileAttributes attribs = new DummyFileAttributes();
    final String[] sizes = { "2KB", "3MB", "4GB", "5TB" };
    for (final String size : sizes) {
        final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size);
        final long quarter = condition.getThresholdBytes() / 4;
        attribs.size = quarter;
        assertFalse(condition.accept(null, null, attribs));
        assertFalse(condition.accept(null, null, attribs));
        assertFalse(condition.accept(null, null, attribs));
        assertFalse(condition.accept(null, null, attribs));
        assertTrue(condition.accept(null, null, attribs));
    }
}
Also used : DummyFileAttributes(org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes) Test(org.junit.jupiter.api.Test)

Aggregations

DummyFileAttributes (org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes)13 Test (org.junit.jupiter.api.Test)13 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)2 PathWithAttributes (org.apache.logging.log4j.core.appender.rolling.action.PathWithAttributes)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)2 ScriptPlugin (org.apache.logging.log4j.script.ScriptPlugin)2 Tag (org.junit.jupiter.api.Tag)1