You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2014/07/22 16:21:57 UTC

svn commit: r1612577 - in /jackrabbit/oak/branches/1.0: ./ oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java

Author: tommaso
Date: Tue Jul 22 14:21:57 2014
New Revision: 1612577

URL: http://svn.apache.org/r1612577
Log:
OAK-1875 - provided broader test of cost and enabled filter restrictions, merged to branch 1.0

Modified:
    jackrabbit/oak/branches/1.0/   (props changed)
    jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java

Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
  Merged /jackrabbit/oak/trunk:r1612560

Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java?rev=1612577&r1=1612576&r2=1612577&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java Tue Jul 22 14:21:57 2014
@@ -16,17 +16,24 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.query;
 
+import java.util.Collections;
+
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.query.QueryEngineSettings;
+import org.apache.jackrabbit.oak.query.ast.Operator;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.Filter;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.solr.client.solrj.SolrServer;
 import org.junit.Test;
 
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  * Testcase for {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex}
@@ -34,7 +41,7 @@ import static org.mockito.Mockito.mock;
 public class SolrQueryIndexTest {
 
     @Test
-    public void testCostWithNoRestrictions() throws Exception {
+    public void testDefaultCostWithNoRestrictions() throws Exception {
         NodeState root = mock(NodeState.class);
         SelectorImpl selector = mock(SelectorImpl.class);
 
@@ -46,4 +53,115 @@ public class SolrQueryIndexTest {
         double cost = solrQueryIndex.getCost(filter, root);
         assertTrue(Double.POSITIVE_INFINITY == cost);
     }
+
+    @Test
+    public void testDefaultCostWithPathRestrictions() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration();
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where isdescendantnode(a, '/test')", new QueryEngineSettings());
+        filter.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN);
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(Double.POSITIVE_INFINITY == cost);
+    }
+
+    @Test
+    public void testCostWithPathRestrictionsEnabled() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration(){
+            @Override
+            public boolean useForPathRestrictions() {
+                return true;
+            }
+        };
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where isdescendantnode(a, '/test')", new QueryEngineSettings());
+        filter.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN);
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(10 == cost);
+    }
+
+    @Test
+    public void testDefaultCostWithPropertyRestrictions() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration();
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
+        filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(Double.POSITIVE_INFINITY == cost);
+    }
+
+    @Test
+    public void testCostWithPropertyRestrictionsEnabled() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration(){
+            @Override
+            public boolean useForPropertyRestrictions() {
+                return true;
+            }
+        };
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
+        filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(10 == cost);
+    }
+
+    @Test
+    public void testDefaultCostWithPrimaryTypeRestrictions() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration();
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where jcr:primaryType = 'nt:unstructured')", new QueryEngineSettings());
+        filter.restrictProperty("jcr:primaryType", Operator.EQUAL, PropertyValues.newString("nt:unstructured"));
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(Double.POSITIVE_INFINITY == cost);
+    }
+
+    @Test
+    public void testCostWithPrimaryTypeRestrictionsEnabled() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration(){
+            @Override
+            public boolean useForPrimaryTypes() {
+                return true;
+            }
+        };
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where jcr:primaryType = 'nt:unstructured')", new QueryEngineSettings());
+        filter.restrictProperty("jcr:primaryType", Operator.EQUAL, PropertyValues.newString("nt:unstructured"));
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(10 == cost);
+    }
 }