Author: thomasm Date: Fri Sep 16 09:58:23 2016 New Revision: 1761018 URL: http://svn.apache.org/viewvc?rev=1761018&view=rev Log: OAK-4815 ReferenceIndex slowdown due to OAK-3403
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexLookupTest.java jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexLookupTest.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java Fri Sep 16 09:58:23 2016 @@ -111,8 +111,20 @@ public class FilterImpl implements Filte private boolean preparing; // TODO support "order by" + + /** + * Create a new filter instance that is used for unit testing. This method + * is relatively slow, because it creates a new query engine setting object. + * Therefore, it is only to be used for testing. At runtime, the + * public constructor should be used instead. + * + * @return the filter + */ + public static FilterImpl newTestInstance() { + return new FilterImpl(); + } - public FilterImpl() { + private FilterImpl() { this(null, null, new QueryEngineSettings()); } Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java Fri Sep 16 09:58:23 2016 @@ -87,7 +87,7 @@ public class AsyncIndexUpdateTest { private static Set<String> find(PropertyIndexLookup lookup, String name, String value) { - return Sets.newHashSet(lookup.query(new FilterImpl(), name, + return Sets.newHashSet(lookup.query(FilterImpl.newTestInstance(), name, PropertyValues.newString(value))); } Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java Fri Sep 16 09:58:23 2016 @@ -45,7 +45,7 @@ public class DiffCollectorTest { UUIDDiffCollector collector = new UUIDDiffCollector(root, after); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues.newString("abc")); @@ -71,7 +71,7 @@ public class DiffCollectorTest { UUIDDiffCollector collector = new UUIDDiffCollector(before, after); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues.newString("xyz")); @@ -111,7 +111,7 @@ public class DiffCollectorTest { UUIDDiffCollector collector = new UUIDDiffCollector(before, after); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues .newString("ee59b554-76b7-3e27-9fc6-15bda1388894")); Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java Fri Sep 16 09:58:23 2016 @@ -211,7 +211,7 @@ public class ContentMirrorStoreStrategyT final long repoTreeApproxNodeCount = 50000; final long repoSubPathApproxNodeCount = repoTreeApproxNodeCount / filteredNodeFactor; - final FilterImpl filter = new FilterImpl(); + final FilterImpl filter = FilterImpl.newTestInstance(); filter.restrictPath("/" + subPathName, Filter.PathRestriction.ALL_CHILDREN); Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java Fri Sep 16 09:58:23 2016 @@ -42,7 +42,7 @@ public class FilterTest { PropertyValue one = PropertyValues.newString("1"); PropertyValue two = PropertyValues.newString("2"); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); assertTrue(null == f.getPropertyRestriction("x")); f.restrictProperty("x", Operator.LESS_OR_EQUAL, two); assertEquals( @@ -79,7 +79,7 @@ public class FilterTest { "Filter(, path=*, property=[x=[..2], [1.., (1.., ..2), 2]])", f.toString()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictProperty("x", Operator.EQUAL, one); assertEquals( "Filter(, path=*, property=[x=[1]])", @@ -107,7 +107,7 @@ public class FilterTest { "Filter(, path=*, property=[x=[1, [1.., ..1], (1..]])", f.toString()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictProperty("x", Operator.EQUAL, one); assertEquals( "Filter(, path=*, property=[x=[1]])", @@ -120,7 +120,7 @@ public class FilterTest { "Filter(, path=*, property=[x=[1, ..1)]])", f.toString()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictProperty("x", Operator.NOT_EQUAL, null); assertEquals( "Filter(, path=*, property=[x=[is not null]])", @@ -164,11 +164,11 @@ public class FilterTest { .nextInt(Filter.PathRestriction.values().length)]; Filter.PathRestriction r2 = Filter.PathRestriction.values()[r .nextInt(Filter.PathRestriction.values().length)]; - FilterImpl f1 = new FilterImpl(); + FilterImpl f1 = FilterImpl.newTestInstance(); f1.restrictPath(p1, r1); - FilterImpl f2 = new FilterImpl(); + FilterImpl f2 = FilterImpl.newTestInstance(); f2.restrictPath(p2, r2); - FilterImpl fc = new FilterImpl(); + FilterImpl fc = FilterImpl.newTestInstance(); fc.restrictPath(p1, r1); fc.restrictPath(p2, r2); int tooMany = 0; @@ -178,7 +178,7 @@ public class FilterTest { if (expected == got) { // good } else if (expected && !got) { - fc = new FilterImpl(); + fc = FilterImpl.newTestInstance(); fc.restrictPath(p1, r1); fc.restrictPath(p2, r2); fail("not matched: " + p1 + "/" + r1.name() + " && " + p2 @@ -197,7 +197,7 @@ public class FilterTest { @Test public void pathRestrictions() throws Exception { - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); assertEquals("/", f.getPath()); assertEquals(Filter.PathRestriction.NO_RESTRICTION, f.getPathRestriction()); @@ -206,7 +206,7 @@ public class FilterTest { f.restrictPath("/test2", Filter.PathRestriction.ALL_CHILDREN); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN); assertEquals("/test", f.getPath()); assertEquals(Filter.PathRestriction.ALL_CHILDREN, @@ -219,7 +219,7 @@ public class FilterTest { assertEquals("/test/x/y", f.getPath()); assertEquals(Filter.PathRestriction.PARENT, f.getPathRestriction()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.DIRECT_CHILDREN); f.restrictPath("/test/x/y", Filter.PathRestriction.PARENT); assertEquals("/test/x/y", f.getPath()); @@ -227,7 +227,7 @@ public class FilterTest { f.restrictPath("/test/y", Filter.PathRestriction.DIRECT_CHILDREN); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test/x/y", Filter.PathRestriction.PARENT); f.restrictPath("/test/x", Filter.PathRestriction.EXACT); assertEquals("/test/x", f.getPath()); @@ -235,12 +235,12 @@ public class FilterTest { f.restrictPath("/test/y", Filter.PathRestriction.EXACT); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN); f.restrictPath("/test", Filter.PathRestriction.PARENT); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test/x", Filter.PathRestriction.PARENT); f.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN); assertEquals("/test/x", f.getPath()); @@ -248,23 +248,23 @@ public class FilterTest { f.restrictPath("/test/x", Filter.PathRestriction.ALL_CHILDREN); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN); f.restrictPath("/test", Filter.PathRestriction.EXACT); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.DIRECT_CHILDREN); f.restrictPath("/test/x", Filter.PathRestriction.EXACT); assertEquals("/test/x", f.getPath()); assertEquals(Filter.PathRestriction.EXACT, f.getPathRestriction()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.DIRECT_CHILDREN); f.restrictPath("/test/x/y", Filter.PathRestriction.EXACT); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test/x", Filter.PathRestriction.PARENT); f.restrictPath("/", Filter.PathRestriction.ALL_CHILDREN); assertEquals("/test/x", f.getPath()); @@ -272,7 +272,7 @@ public class FilterTest { f.restrictPath("/test/y", Filter.PathRestriction.EXACT); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test", Filter.PathRestriction.DIRECT_CHILDREN); assertEquals("/test", f.getPath()); assertEquals(Filter.PathRestriction.DIRECT_CHILDREN, @@ -291,7 +291,7 @@ public class FilterTest { f.restrictPath("/test2", Filter.PathRestriction.ALL_CHILDREN); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test/x", Filter.PathRestriction.EXACT); assertEquals("/test/x", f.getPath()); assertEquals(Filter.PathRestriction.EXACT, f.getPathRestriction()); @@ -301,7 +301,7 @@ public class FilterTest { f.restrictPath("/test/y", Filter.PathRestriction.DIRECT_CHILDREN); assertTrue(f.isAlwaysFalse()); - f = new FilterImpl(); + f = FilterImpl.newTestInstance(); f.restrictPath("/test/x/y", Filter.PathRestriction.PARENT); assertEquals("/test/x/y", f.getPath()); assertEquals(Filter.PathRestriction.PARENT, f.getPathRestriction()); Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java (original) +++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java Fri Sep 16 09:58:23 2016 @@ -53,7 +53,7 @@ public class TraversingIndexTest { TraversingIndex t = new TraversingIndex(); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.setPath("/"); Cursor c = t.query(f, root); Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexLookupTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexLookupTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexLookupTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexLookupTest.java Fri Sep 16 09:58:23 2016 @@ -44,7 +44,7 @@ public class LuceneIndexLookupTest { newLuceneIndexDefinition(index, "l2", of(TYPENAME_STRING)); LuceneIndexLookup lookup = new LuceneIndexLookup(builder.getNodeState()); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictPath("/", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/oak:index/l2"), lookup.collectIndexNodePaths(f)); @@ -62,7 +62,7 @@ public class LuceneIndexLookupTest { newLuceneIndexDefinition(index, "l3", of(TYPENAME_STRING)); LuceneIndexLookup lookup = new LuceneIndexLookup(builder.getNodeState()); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictPath("/a", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/a/oak:index/l2"), lookup.collectIndexNodePaths(f)); Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexLookupTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexLookupTest.java?rev=1761018&r1=1761017&r2=1761018&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexLookupTest.java (original) +++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexLookupTest.java Fri Sep 16 09:58:23 2016 @@ -53,7 +53,7 @@ public class SolrIndexLookupTest { newSolrIndexDefinition(index, "l2", of("foo")); SolrIndexLookup lookup = new SolrIndexLookup(builder.getNodeState()); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictPath("/", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/oak:index/l2"), lookup.collectIndexNodePaths(f)); @@ -71,7 +71,7 @@ public class SolrIndexLookupTest { newSolrIndexDefinition(index, "l3", of("foo")); SolrIndexLookup lookup = new SolrIndexLookup(builder.getNodeState()); - FilterImpl f = new FilterImpl(); + FilterImpl f = FilterImpl.newTestInstance(); f.restrictPath("/a", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/a/oak:index/l2"), lookup.collectIndexNodePaths(f));