NodeCounterMBeanEstimator implements NodeCountEstimator { @Override public long getEstimatedNodeCount(String basePath, Set<String> indexPaths) { PathPerimeter pp = new PathPerimeter(); pp.compute(basePath, indexPaths); if (pp.includeAll) { return counter.getEstimatedNodeCount(basePath); } else { long totalCount = 0; for (String path : pp.includes) { long estimate = counter.getEstimatedNodeCount(path); if (estimate > 0) { totalCount += estimate; } } for (String path : pp.excludes) { long estimate = counter.getEstimatedNodeCount(path); if (estimate > 0) { totalCount -= estimate; } } log.info("Paths to be traversed {}", pp); return totalCount; } } NodeCounterMBeanEstimator(NodeStore nodeStore);   NodeCounterMBeanEstimator(NodeStore nodeStore, NodeCounter nodeCounter); @Override long getEstimatedNodeCount(String basePath, Set<String> indexPaths);  }
@Test public void estimateCount() throws Exception { NodeBuilder builder = store.getRoot().builder(); builder.child("idx-a"); builder.child("idx-b").setProperty(PROP_INCLUDED_PATHS, asList("/content"), Type.STRINGS); builder.child("idx-b").setProperty(PROP_EXCLUDED_PATHS, asList("/content/old"), Type.STRINGS); builder.child("idx-c").setProperty(PROP_INCLUDED_PATHS, asList("/libs"), Type.STRINGS); builder.child("idx-d").setProperty(PROP_EXCLUDED_PATHS, asList("/libs"), Type.STRINGS); builder.child("content").child("idx-e").setProperty(PROP_EXCLUDED_PATHS, asList("/content/old"), Type.STRINGS); builder.child("content").child("idx-f"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); Map<String, Integer> counts = ImmutableMap.of( "/", 100, "/content", 50, "/content/old", 10, "/libs", 30 ); when(counter.getEstimatedNodeCount(anyString())).then((invocation -> { String path = (String) invocation.getArguments()[0]; if (counts.containsKey(path)) { return (long)counts.get(path); } return -1; })); NodeCountEstimator estimator = new NodeCounterMBeanEstimator(store, counter); assertEquals(100, estimator.getEstimatedNodeCount("/", of("/idx-a"))); assertEquals(100, estimator.getEstimatedNodeCount("/", of("/idx-a", "/idx-b"))); assertEquals(40, estimator.getEstimatedNodeCount("/", of("/idx-b"))); assertEquals(70, estimator.getEstimatedNodeCount("/", of("/idx-b", "/idx-c"))); assertEquals(50, estimator.getEstimatedNodeCount("/content", of("/content/idx-f"))); assertEquals(40, estimator.getEstimatedNodeCount("/content", of("/content/idx-e"))); }