use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.
the class PathSortByModificationTimeTest method testCompareRecentFirst.
@Test
public void testCompareRecentFirst() {
final PathSorter sorter = PathSortByModificationTime.createSorter(true);
final Path p1 = Paths.get("aaa");
final Path p2 = Paths.get("bbb");
final DummyFileAttributes a1 = new DummyFileAttributes();
final DummyFileAttributes a2 = new DummyFileAttributes();
a1.lastModified = FileTime.fromMillis(100);
a2.lastModified = FileTime.fromMillis(222);
assertEquals(1, sorter.compare(path(p1, a1), path(p1, a2)), "same path, 2nd more recent");
assertEquals(1, sorter.compare(path(p1, a1), path(p2, a2)), "path ignored, 2nd more recent");
assertEquals(1, sorter.compare(path(p2, a1), path(p1, a2)), "path ignored, 2nd more recent");
assertEquals(-1, sorter.compare(path(p1, a2), path(p1, a1)), "same path, 1st more recent");
assertEquals(-1, sorter.compare(path(p1, a2), path(p2, a1)), "path ignored, 1st more recent");
assertEquals(-1, sorter.compare(path(p2, a2), path(p1, a1)), "path ignored, 1st more recent");
assertEquals(0, sorter.compare(path(p1, a1), path(p1, a1)), "same path, same time");
assertEquals(1, sorter.compare(path(p1, a1), path(p2, a1)), "p2 < p1, same time");
assertEquals(-1, sorter.compare(path(p2, a1), path(p1, a1)), "p2 < p1, same time");
}
use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.
the class IfLastModifiedTest method testAcceptCallsNestedConditionsOnlyIfPathAccepted.
@Test
public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() {
final CountingCondition counter = new CountingCondition(true);
final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter);
final DummyFileAttributes attrs = new DummyFileAttributes();
final long oldEnough = 33 * 1000 + 5;
attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - oldEnough);
assertTrue(filter.accept(null, null, attrs));
assertEquals(1, counter.getAcceptCount());
assertTrue(filter.accept(null, null, attrs));
assertEquals(2, counter.getAcceptCount());
assertTrue(filter.accept(null, null, attrs));
assertEquals(3, counter.getAcceptCount());
final long tooYoung = 33 * 1000 - 5;
attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - tooYoung);
assertFalse(filter.accept(null, null, attrs));
// no increase
assertEquals(3, counter.getAcceptCount());
assertFalse(filter.accept(null, null, attrs));
assertEquals(3, counter.getAcceptCount());
assertFalse(filter.accept(null, null, attrs));
assertEquals(3, counter.getAcceptCount());
}
use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.
the class IfLastModifiedTest method testAcceptsIfFileAgeEqualToDuration.
@Test
public void testAcceptsIfFileAgeEqualToDuration() {
final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"));
final DummyFileAttributes attrs = new DummyFileAttributes();
final long age = 33 * 1000;
attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age);
assertTrue(filter.accept(null, null, attrs));
}
use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.
the class IfAccumulatedFileSizeTest method testAcceptIfExceedThreshold.
@Test
public void testAcceptIfExceedThreshold() {
final String[] sizes = { "2KB", "3MB", "4GB", "5TB" };
for (final String size : sizes) {
final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size);
final DummyFileAttributes attribs = new DummyFileAttributes();
attribs.size = condition.getThresholdBytes() + 1;
assertTrue(condition.accept(null, null, attribs));
}
}
use of org.apache.logging.log4j.core.test.appender.rolling.action.DummyFileAttributes in project logging-log4j2 by apache.
the class IfAccumulatedFileSizeTest method testAcceptCallsNestedConditionsOnlyIfPathAccepted.
@Test
public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() {
final CountingCondition counter = new CountingCondition(true);
final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition("2KB", counter);
final DummyFileAttributes attribs = new DummyFileAttributes();
final long quarter = condition.getThresholdBytes() / 4;
attribs.size = quarter;
assertFalse(condition.accept(null, null, attribs));
assertEquals(0, counter.getAcceptCount());
assertFalse(condition.accept(null, null, attribs));
assertEquals(0, counter.getAcceptCount());
assertFalse(condition.accept(null, null, attribs));
assertEquals(0, counter.getAcceptCount());
assertFalse(condition.accept(null, null, attribs));
assertEquals(0, counter.getAcceptCount());
assertTrue(condition.accept(null, null, attribs));
assertEquals(1, counter.getAcceptCount());
assertTrue(condition.accept(null, null, attribs));
assertEquals(2, counter.getAcceptCount());
}
Aggregations