@Test public void keepFromName() throws IOException { TreeMapState state = new TreeMapState(new ListBundle()); DataTreeNode parent = mockParent(); PathPrune pathPrune = Configs.decodeObject(PathPrune.class, "ttl = 20 days, nameFormat = YYMMDD"); long now = DateTimeFormat.forPattern("YYMMDD").parseMillis("140105"); pathPrune.pruneChildren(state, parent, now); verify(parent, never()).deleteNode("140101"); }
public void pruneChildren(final TreeMapState state, final DataTreeNode root, long now) { ClosableIterator<DataTreeNode> keyNodeItr = root.getIterator(); int deleted = 0; int kept = 0; int total = 0; boolean skip = false; try { while (keyNodeItr.hasNext() && !(preempt && state.processorClosing())) { long nodeTime = 0; DataTreeNode treeNode = keyNodeItr.next(); boolean delete; if (allLeaves) { delete = true; } else { nodeTime = getNodeTime(treeNode); delete = ((nodeTime > 0) && ((now - nodeTime) > ttl)); } if (delete) { root.deleteNode(treeNode.getName()); deleted++; } else if (sortedNames && (nodeTime > 0) && (nameFormat != null)) { skip = true; break; } else { kept++; } total++; if ((total % 100000) == 0) { logger.info("Iterating through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } } } finally { if (skip) { logger.info("Iterated through children of {}, deleted: {} and skipped remaining nodes", root.getName(), deleted); } else { logger.info("Iterated through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } keyNodeItr.close(); } }
PathPrune extends PathElement { public void pruneChildren(final TreeMapState state, final DataTreeNode root, long now) { ClosableIterator<DataTreeNode> keyNodeItr = root.getIterator(); int deleted = 0; int kept = 0; int total = 0; boolean skip = false; try { while (keyNodeItr.hasNext() && !(preempt && state.processorClosing())) { long nodeTime = 0; DataTreeNode treeNode = keyNodeItr.next(); boolean delete; if (allLeaves) { delete = true; } else { nodeTime = getNodeTime(treeNode); delete = ((nodeTime > 0) && ((now - nodeTime) > ttl)); } if (delete) { root.deleteNode(treeNode.getName()); deleted++; } else if (sortedNames && (nodeTime > 0) && (nameFormat != null)) { skip = true; break; } else { kept++; } total++; if ((total % 100000) == 0) { logger.info("Iterating through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } } } finally { if (skip) { logger.info("Iterated through children of {}, deleted: {} and skipped remaining nodes", root.getName(), deleted); } else { logger.info("Iterated through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } keyNodeItr.close(); } } }
PathPrune extends PathElement { public void pruneChildren(final TreeMapState state, final DataTreeNode root, long now) { ClosableIterator<DataTreeNode> keyNodeItr = root.getIterator(); int deleted = 0; int kept = 0; int total = 0; boolean skip = false; try { while (keyNodeItr.hasNext() && !(preempt && state.processorClosing())) { long nodeTime = 0; DataTreeNode treeNode = keyNodeItr.next(); boolean delete; if (allLeaves) { delete = true; } else { nodeTime = getNodeTime(treeNode); delete = ((nodeTime > 0) && ((now - nodeTime) > ttl)); } if (delete) { root.deleteNode(treeNode.getName()); deleted++; } else if (sortedNames && (nodeTime > 0) && (nameFormat != null)) { skip = true; break; } else { kept++; } total++; if ((total % 100000) == 0) { logger.info("Iterating through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } } } finally { if (skip) { logger.info("Iterated through children of {}, deleted: {} and skipped remaining nodes", root.getName(), deleted); } else { logger.info("Iterated through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } keyNodeItr.close(); } } @JsonCreator  PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
                     @Nullable @JsonProperty("nameFormat") String nameFormat,
                     @Nullable @JsonProperty("timezone") String timezone,
                     @Nullable @JsonProperty("treePath") String treePath,
                     @JsonProperty("timePropKey") String timePropKey,
                     @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
                     @JsonProperty("allLeaves") boolean allLeaves,
                     @JsonProperty("relativeDown") int relativeDown,
                     @JsonProperty("preempt") boolean preempt,
                     @JsonProperty("excludes") ImmutableSet<String> excludes,
                     @JsonProperty("sortedNames") boolean sortedNames); }
PathPrune extends PathElement { public void pruneChildren(final TreeMapState state, final DataTreeNode root, long now) { ClosableIterator<DataTreeNode> keyNodeItr = root.getIterator(); int deleted = 0; int kept = 0; int total = 0; boolean skip = false; try { while (keyNodeItr.hasNext() && !(preempt && state.processorClosing())) { long nodeTime = 0; DataTreeNode treeNode = keyNodeItr.next(); boolean delete; if (allLeaves) { delete = true; } else { nodeTime = getNodeTime(treeNode); delete = ((nodeTime > 0) && ((now - nodeTime) > ttl)); } if (delete) { root.deleteNode(treeNode.getName()); deleted++; } else if (sortedNames && (nodeTime > 0) && (nameFormat != null)) { skip = true; break; } else { kept++; } total++; if ((total % 100000) == 0) { logger.info("Iterating through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } } } finally { if (skip) { logger.info("Iterated through children of {}, deleted: {} and skipped remaining nodes", root.getName(), deleted); } else { logger.info("Iterated through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } keyNodeItr.close(); } } @JsonCreator  PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
                     @Nullable @JsonProperty("nameFormat") String nameFormat,
                     @Nullable @JsonProperty("timezone") String timezone,
                     @Nullable @JsonProperty("treePath") String treePath,
                     @JsonProperty("timePropKey") String timePropKey,
                     @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
                     @JsonProperty("allLeaves") boolean allLeaves,
                     @JsonProperty("relativeDown") int relativeDown,
                     @JsonProperty("preempt") boolean preempt,
                     @JsonProperty("excludes") ImmutableSet<String> excludes,
                     @JsonProperty("sortedNames") boolean sortedNames); @Override List<DataTreeNode> getNextNodeList(final TreeMapState state); void findAndPruneChildren(final TreeMapState state,
                                     final DataTreeNode root,
                                     long now,
                                     int depth,
                                     List<String> treePaths); void pruneChildren(final TreeMapState state, final DataTreeNode root, long now); }
PathPrune extends PathElement { public void pruneChildren(final TreeMapState state, final DataTreeNode root, long now) { ClosableIterator<DataTreeNode> keyNodeItr = root.getIterator(); int deleted = 0; int kept = 0; int total = 0; boolean skip = false; try { while (keyNodeItr.hasNext() && !(preempt && state.processorClosing())) { long nodeTime = 0; DataTreeNode treeNode = keyNodeItr.next(); boolean delete; if (allLeaves) { delete = true; } else { nodeTime = getNodeTime(treeNode); delete = ((nodeTime > 0) && ((now - nodeTime) > ttl)); } if (delete) { root.deleteNode(treeNode.getName()); deleted++; } else if (sortedNames && (nodeTime > 0) && (nameFormat != null)) { skip = true; break; } else { kept++; } total++; if ((total % 100000) == 0) { logger.info("Iterating through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } } } finally { if (skip) { logger.info("Iterated through children of {}, deleted: {} and skipped remaining nodes", root.getName(), deleted); } else { logger.info("Iterated through children of {}, deleted: {} kept: {}", root.getName(), deleted, kept); } keyNodeItr.close(); } } @JsonCreator  PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
                     @Nullable @JsonProperty("nameFormat") String nameFormat,
                     @Nullable @JsonProperty("timezone") String timezone,
                     @Nullable @JsonProperty("treePath") String treePath,
                     @JsonProperty("timePropKey") String timePropKey,
                     @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
                     @JsonProperty("allLeaves") boolean allLeaves,
                     @JsonProperty("relativeDown") int relativeDown,
                     @JsonProperty("preempt") boolean preempt,
                     @JsonProperty("excludes") ImmutableSet<String> excludes,
                     @JsonProperty("sortedNames") boolean sortedNames); @Override List<DataTreeNode> getNextNodeList(final TreeMapState state); void findAndPruneChildren(final TreeMapState state,
                                     final DataTreeNode root,
                                     long now,
                                     int depth,
                                     List<String> treePaths); void pruneChildren(final TreeMapState state, final DataTreeNode root, long now);  }