Aggregate logic should optimize for case where patterns do not include wildcard
Adding ignored testcase
@@ -23,8 +23,13 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Function;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import org.apache.jackrabbit.JcrConstants;
@@ -33,8 +38,10 @@ import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.index.lucene.Aggregate.NodeInclude;
import org.apache.jackrabbit.oak.plugins.index.lucene.Aggregate.NodeIncludeResult;
import org.apache.jackrabbit.oak.plugins.index.lucene.Aggregate.PropertyIncludeResult;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Ignore;
import org.junit.Test;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -46,12 +53,17 @@ import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_RULES;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
public class AggregateTest {
@@ -86,6 +98,34 @@ public class AggregateTest {
assertThat(col.getNodePaths(), hasItems("a"));
}
+ @Ignore("OAK-5448")
+ @Test
+ public void noOfChildNodeRead() throws Exception{
+ Aggregate ag = new Aggregate("nt:base", of(ni("a")));
+ NodeBuilder nb = newNode("nt:base");
+ nb.child("a");
+ for (int i = 0; i < 10; i++) {
+ nb.child("a"+i);
+ }
+
+ NodeState state = nb.getNodeState();
+ final AtomicInteger counter = new AtomicInteger();
+ Iterable<? extends ChildNodeEntry> countingIterator = Iterables.transform(state.getChildNodeEntries(),
+ new Function<ChildNodeEntry, ChildNodeEntry>() {
+ @Override
+ public ChildNodeEntry apply(ChildNodeEntry input) {
+ counter.incrementAndGet();
+ return input;
+ }
+ });
+ NodeState mocked = spy(state);
+ doReturn(countingIterator).when(mocked).getChildNodeEntries();
+ ag.collectAggregates(mocked, col);
+
+ //Here at max a single call should happen for reading child nodes
+ assertThat(counter.get(), is(lessThanOrEqualTo(1)));
+ }
+
@Test
public void oneLevelTyped() throws Exception{
Aggregate ag = new Aggregate("nt:base", of(ni("nt:resource","*", false)));
