UniqueIndexCleaner { public int clean(NodeBuilder builder, long lastIndexedTo) { int removalCount = 0; NodeState baseState = builder.getBaseState(); for (ChildNodeEntry e : baseState.getChildNodeEntries()) { long entryCreationTime = e.getNodeState().getLong(PROP_CREATED); if (entryCovered(entryCreationTime, lastIndexedTo)) { builder.child(e.getName()).remove(); removalCount++; } } return removalCount; } UniqueIndexCleaner(TimeUnit timeUnit, long createTimeMargin); int clean(NodeBuilder builder, long lastIndexedTo);  }
@Test public void nothingCleaned() throws Exception{ builder.child("a").setProperty(PROP_CREATED, 100); builder.child("b").setProperty(PROP_CREATED, 100); refresh(); UniqueIndexCleaner cleaner = new UniqueIndexCleaner(MILLISECONDS, 1); cleaner.clean(builder, 10); assertThat(copyOf(builder.getChildNodeNames()), containsInAnyOrder("a", "b")); }
@Test public void cleanWithMargin() throws Exception{ builder.child("a").setProperty(PROP_CREATED, 100); builder.child("b").setProperty(PROP_CREATED, 200); refresh(); UniqueIndexCleaner cleaner = new UniqueIndexCleaner(MILLISECONDS, 100); cleaner.clean(builder, 200); assertThat(copyOf(builder.getChildNodeNames()), containsInAnyOrder("b")); }