@Test public void testRecentLast() throws Exception { final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(false)); final Set<FileVisitOption> options = Collections.emptySet(); Files.walkFileTree(base, options, 1, visitor); final List<PathWithAttributes> found = visitor.getSortedPaths(); assertNotNull(found); assertEquals("file count", 3, found.size()); assertEquals("1st: oldest first; sorted=" + found, aaa, found.get(0).getPath()); assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); assertEquals("3rd: most recent sorted; list=" + found, ccc, found.get(2).getPath()); } }
/** * Test method for * {@link org.apache.logging.log4j.core.appender.rolling.action.PathSortByModificationTime#isRecentFirst()}. */ @Test public void testIsRecentFirstReturnsConstructorValue() { assertTrue(((PathSortByModificationTime) PathSortByModificationTime.createSorter(true)).isRecentFirst()); assertFalse(((PathSortByModificationTime) PathSortByModificationTime.createSorter(false)).isRecentFirst()); }
@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("same path, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p1, a2))); assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p2, a2))); assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p2, a1), path(p1, a2))); assertEquals("same path, 1st more recent", -1, sorter.compare(path(p1, a2), path(p1, a1))); assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p1, a2), path(p2, a1))); assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p2, a2), path(p1, a1))); assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1))); assertEquals("p2 < p1, same time", 1, sorter.compare(path(p1, a1), path(p2, a1))); assertEquals("p2 < p1, same time", -1, sorter.compare(path(p2, a1), path(p1, a1))); }
@Test public void testCompareRecentLast() { final PathSorter sorter = PathSortByModificationTime.createSorter(false); 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("same path, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p1, a2))); assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p2, a2))); assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p2, a1), path(p1, a2))); assertEquals("same path, 1st more recent", 1, sorter.compare(path(p1, a2), path(p1, a1))); assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p1, a2), path(p2, a1))); assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p2, a2), path(p1, a1))); assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1))); assertEquals("p1 < p2, same time", -1, sorter.compare(path(p1, a1), path(p2, a1))); assertEquals("p1 < p2, same time", 1, sorter.compare(path(p2, a1), path(p1, a1))); }
@Test public void testRecentFirst() throws Exception { final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(true)); final Set<FileVisitOption> options = Collections.emptySet(); Files.walkFileTree(base, options, 1, visitor); final List<PathWithAttributes> found = visitor.getSortedPaths(); assertNotNull(found); assertEquals("file count", 3, found.size()); assertEquals("1st: most recent; sorted=" + found, ccc, found.get(0).getPath()); assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); assertEquals("3rd: oldest; sorted=" + found, aaa, found.get(2).getPath()); }
/** * Create a PathSorter that sorts by lastModified time. * * @param recentFirst if true, most recently modified paths should come first. * @return A PathSorter. */ @PluginFactory public static PathSorter createSorter( @PluginAttribute(value = "recentFirst", defaultBoolean = true) final boolean recentFirst) { return new PathSortByModificationTime(recentFirst); }
@PluginConfiguration final Configuration config) { final PathSorter sorter = sorterParameter == null ? new PathSortByModificationTime(true) : sorterParameter; return new DeleteAction(basePath, followLinks, maxDepth, testMode, sorter, pathConditions, scriptCondition, config.getStrSubstitutor());