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 2015/10/20 11:26:16 UTC
svn commit: r1709552 - in
/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr:
SolrBaseTest.java index/SolrIndexEditorTest.java
query/SolrIndexQueryTestIT.java query/SolrQueryIndexTest.java
Author: tommaso
Date: Tue Oct 20 09:26:15 2015
New Revision: 1709552
URL: http://svn.apache.org/viewvc?rev=1709552&view=rev
Log:
OAK-3215 - added explicit shutdown to SolrServer in TestUtils
Modified:
jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/SolrBaseTest.java
jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java
jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java
jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/SolrBaseTest.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/SolrBaseTest.java?rev=1709552&r1=1709551&r2=1709552&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/SolrBaseTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/SolrBaseTest.java Tue Oct 20 09:26:15 2015
@@ -72,6 +72,7 @@ public abstract class SolrBaseTest {
if (server != null && server.ping() != null) {
server.deleteByQuery("*:*");
server.commit();
+ server.shutdown();
server = null;
}
}
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.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/index/SolrIndexEditorTest.java?rev=1709552&r1=1709551&r2=1709552&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java Tue Oct 20 09:26:15 2015
@@ -48,52 +48,61 @@ public class SolrIndexEditorTest {
public void testIndexedProperties() throws Exception {
NodeBuilder builder = mock(NodeBuilder.class);
SolrServer solrServer = TestUtils.createSolrServer();
- OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
- IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
- SolrIndexEditor solrIndexEditor = new SolrIndexEditor(builder, solrServer, configuration, callback);
- NodeState before = mock(NodeState.class);
- NodeState after = mock(NodeState.class);
- Iterable properties = new Iterable<PropertyState>() {
- @Override
- public Iterator<PropertyState> iterator() {
- return Arrays.asList(PropertyStates.createProperty("foo1", "bar")).iterator();
- }
- };
- when(after.getProperties()).thenReturn(properties);
- solrIndexEditor.leave(before, after);
- QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
- assertEquals(1, queryResponse.getResults().getNumFound());
+ try {
+ OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
+ IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
+ SolrIndexEditor solrIndexEditor = new SolrIndexEditor(builder, solrServer, configuration, callback);
+ NodeState before = mock(NodeState.class);
+ NodeState after = mock(NodeState.class);
+ Iterable properties = new Iterable<PropertyState>() {
+ @Override
+ public Iterator<PropertyState> iterator() {
+ return Arrays.asList(PropertyStates.createProperty("foo1", "bar")).iterator();
+ }
+ };
+ when(after.getProperties()).thenReturn(properties);
+ solrIndexEditor.leave(before, after);
+ QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
+ assertEquals(1, queryResponse.getResults().getNumFound());
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test
public void testIgnoredPropertiesNotIndexed() throws Exception {
NodeBuilder builder = mock(NodeBuilder.class);
SolrServer solrServer = TestUtils.createSolrServer();
- OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
- @Nonnull
- @Override
- public Collection<String> getIgnoredProperties() {
- return Arrays.asList("foo2");
- }
- @Nonnull
- @Override
- public CommitPolicy getCommitPolicy() {
- return CommitPolicy.HARD;
- }
- };
- IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
- SolrIndexEditor solrIndexEditor = new SolrIndexEditor(builder, solrServer, configuration, callback);
- NodeState before = mock(NodeState.class);
- NodeState after = mock(NodeState.class);
- Iterable properties = new Iterable<PropertyState>() {
- @Override
- public Iterator<PropertyState> iterator() {
- return Arrays.asList(PropertyStates.createProperty("foo2", "bar")).iterator();
- }
- };
- when(after.getProperties()).thenReturn(properties);
- solrIndexEditor.leave(before, after);
- QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
- assertEquals(0, queryResponse.getResults().getNumFound());
+ try {
+ OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+ @Nonnull
+ @Override
+ public Collection<String> getIgnoredProperties() {
+ return Arrays.asList("foo2");
+ }
+
+ @Nonnull
+ @Override
+ public CommitPolicy getCommitPolicy() {
+ return CommitPolicy.HARD;
+ }
+ };
+ IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
+ SolrIndexEditor solrIndexEditor = new SolrIndexEditor(builder, solrServer, configuration, callback);
+ NodeState before = mock(NodeState.class);
+ NodeState after = mock(NodeState.class);
+ Iterable properties = new Iterable<PropertyState>() {
+ @Override
+ public Iterator<PropertyState> iterator() {
+ return Arrays.asList(PropertyStates.createProperty("foo2", "bar")).iterator();
+ }
+ };
+ when(after.getProperties()).thenReturn(properties);
+ solrIndexEditor.leave(before, after);
+ QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
+ assertEquals(0, queryResponse.getResults().getNumFound());
+ } finally {
+ solrServer.shutdown();
+ }
}
}
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.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/SolrIndexQueryTestIT.java?rev=1709552&r1=1709551&r2=1709552&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java Tue Oct 20 09:26:15 2015
@@ -60,6 +60,7 @@ public class SolrIndexQueryTestIT extend
public void tearDown() throws Exception {
solrServer.deleteByQuery("*:*");
solrServer.commit();
+ solrServer.shutdown();
}
@Override
@@ -86,6 +87,7 @@ public class SolrIndexQueryTestIT extend
))
.createContentRepository();
} catch (Exception e) {
+ solrServer.shutdown();
throw new RuntimeException(e);
}
}
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=1709552&r1=1709551&r2=1709552&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 Oct 20 09:26:15 2015
@@ -16,12 +16,11 @@
*/
package org.apache.jackrabbit.oak.plugins.index.solr.query;
+import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import javax.annotation.Nonnull;
-
import org.apache.jackrabbit.oak.api.Result;
import org.apache.jackrabbit.oak.plugins.index.solr.TestUtils;
import org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration;
@@ -35,20 +34,15 @@ import org.apache.jackrabbit.oak.spi.que
import org.apache.jackrabbit.oak.spi.query.IndexRow;
import org.apache.jackrabbit.oak.spi.query.PropertyValues;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.NamedList;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -324,29 +318,33 @@ public class SolrQueryIndexTest {
SelectorImpl selector = new SelectorImpl(root, "a");
SolrServer solrServer = TestUtils.createSolrServer();
- SolrInputDocument document = new SolrInputDocument();
- document.addField("path_exact", "/a/b");
- document.addField("name", "hello");
- solrServer.add(document);
- solrServer.commit();
- OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
- @Override
- public boolean useForPropertyRestrictions() {
- return true;
- }
-
- @Override
- public Collection<String> getIgnoredProperties() {
- return Arrays.asList("name");
- }
- };
- 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"));
- String plan = solrQueryIndex.getPlan(filter, root);
- assertNotNull(plan);
- assertTrue(plan.contains("q=*%3A*")); // querying on property name is not possible, then falling back to a match all query
+ try {
+ SolrInputDocument document = new SolrInputDocument();
+ document.addField("path_exact", "/a/b");
+ document.addField("name", "hello");
+ solrServer.add(document);
+ solrServer.commit();
+ OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+ @Override
+ public boolean useForPropertyRestrictions() {
+ return true;
+ }
+
+ @Override
+ public Collection<String> getIgnoredProperties() {
+ return Arrays.asList("name");
+ }
+ };
+ 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"));
+ String plan = solrQueryIndex.getPlan(filter, root);
+ assertNotNull(plan);
+ assertTrue(plan.contains("q=*%3A*")); // querying on property name is not possible, then falling back to a match all query
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test
@@ -356,30 +354,34 @@ public class SolrQueryIndexTest {
SelectorImpl selector = new SelectorImpl(root, "a");
SolrServer solrServer = TestUtils.createSolrServer();
- SolrInputDocument document = new SolrInputDocument();
- document.addField("path_exact", "/a/b");
- document.addField("name", "hello");
- solrServer.add(document);
- solrServer.commit();
- OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
- @Override
- public boolean useForPropertyRestrictions() {
- return true;
- }
-
- @Nonnull
- @Override
- public Collection<String> getUsedProperties() {
- return Arrays.asList("name");
- }
- };
- 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"));
- String plan = solrQueryIndex.getPlan(filter, root);
- assertNotNull(plan);
- assertTrue(plan.contains("name%3Ahello")); // querying on property name is possible
+ try {
+ SolrInputDocument document = new SolrInputDocument();
+ document.addField("path_exact", "/a/b");
+ document.addField("name", "hello");
+ solrServer.add(document);
+ solrServer.commit();
+ OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+ @Override
+ public boolean useForPropertyRestrictions() {
+ return true;
+ }
+
+ @Nonnull
+ @Override
+ public Collection<String> getUsedProperties() {
+ return Arrays.asList("name");
+ }
+ };
+ 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"));
+ String plan = solrQueryIndex.getPlan(filter, root);
+ assertNotNull(plan);
+ assertTrue(plan.contains("name%3Ahello")); // querying on property name is possible
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test
@@ -389,30 +391,34 @@ public class SolrQueryIndexTest {
SelectorImpl selector = new SelectorImpl(root, "a");
SolrServer solrServer = TestUtils.createSolrServer();
- SolrInputDocument document = new SolrInputDocument();
- document.addField("path_exact", "/a/b");
- document.addField("name", "hello");
- solrServer.add(document);
- solrServer.commit();
- OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
- @Override
- public boolean useForPropertyRestrictions() {
- return true;
- }
-
- @Nonnull
- @Override
- public Collection<String> getUsedProperties() {
- return Arrays.asList("name");
- }
- };
- SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
-
- FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where foo = 'bar')", new QueryEngineSettings());
- filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
- String plan = solrQueryIndex.getPlan(filter, root);
- assertNotNull(plan);
- assertTrue(plan.contains("*%3A*")); // querying on property foo is not possible, as the only usable property is 'name'
+ try {
+ SolrInputDocument document = new SolrInputDocument();
+ document.addField("path_exact", "/a/b");
+ document.addField("name", "hello");
+ solrServer.add(document);
+ solrServer.commit();
+ OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+ @Override
+ public boolean useForPropertyRestrictions() {
+ return true;
+ }
+
+ @Nonnull
+ @Override
+ public Collection<String> getUsedProperties() {
+ return Arrays.asList("name");
+ }
+ };
+ SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+ FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where foo = 'bar')", new QueryEngineSettings());
+ filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
+ String plan = solrQueryIndex.getPlan(filter, root);
+ assertNotNull(plan);
+ assertTrue(plan.contains("*%3A*")); // querying on property foo is not possible, as the only usable property is 'name'
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test
@@ -422,24 +428,28 @@ public class SolrQueryIndexTest {
SelectorImpl selector = new SelectorImpl(root, "a");
SolrServer solrServer = TestUtils.createSolrServer();
- SolrInputDocument document = new SolrInputDocument();
- document.addField("path_exact", "/a/b");
- document.addField("name", "hello");
- solrServer.add(document);
- solrServer.commit();
- 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"));
- String plan = solrQueryIndex.getPlan(filter, root);
- assertNotNull(plan);
- assertTrue(plan.contains("q=name%3Ahello")); // query gets converted to a fielded query on name field
+ try {
+ SolrInputDocument document = new SolrInputDocument();
+ document.addField("path_exact", "/a/b");
+ document.addField("name", "hello");
+ solrServer.add(document);
+ solrServer.commit();
+ 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"));
+ String plan = solrQueryIndex.getPlan(filter, root);
+ assertNotNull(plan);
+ assertTrue(plan.contains("q=name%3Ahello")); // query gets converted to a fielded query on name field
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test
@@ -454,16 +464,20 @@ public class SolrQueryIndexTest {
" from [nt:hierarchyNode] as a where isdescendantnode(a, '/content') and " +
"contains([jcr:content/jcr:description], 'founded') order by [jcr:score] desc";
SolrServer solrServer = TestUtils.createSolrServer();
- OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
- @Override
- public boolean useForPropertyRestrictions() {
- return true;
- }
- };
- SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
- FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
- Cursor cursor = solrQueryIndex.query(filter, root);
- assertNotNull(cursor);
+ try {
+ OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+ @Override
+ public boolean useForPropertyRestrictions() {
+ return true;
+ }
+ };
+ SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+ FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
+ Cursor cursor = solrQueryIndex.query(filter, root);
+ assertNotNull(cursor);
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test
@@ -474,21 +488,25 @@ public class SolrQueryIndexTest {
String sqlQuery = "select [jcr:path], [jcr:score] from [nt:base] as a where" +
" contains([jcr:content/*], 'founded')";
SolrServer solrServer = TestUtils.createSolrServer();
- OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
- @Override
- public boolean useForPropertyRestrictions() {
- return true;
- }
- };
- SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
- FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
- Cursor cursor = solrQueryIndex.query(filter, root);
- assertNotNull(cursor);
- long sizeExact = cursor.getSize(Result.SizePrecision.EXACT, 100000);
- long sizeApprox = cursor.getSize(Result.SizePrecision.APPROXIMATION, 100000);
- long sizeFastApprox = cursor.getSize(Result.SizePrecision.FAST_APPROXIMATION, 100000);
- assertTrue(Math.abs(sizeExact - sizeApprox) < 10);
- assertTrue(Math.abs(sizeExact - sizeFastApprox) > 10000);
+ try {
+ OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+ @Override
+ public boolean useForPropertyRestrictions() {
+ return true;
+ }
+ };
+ SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+ FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
+ Cursor cursor = solrQueryIndex.query(filter, root);
+ assertNotNull(cursor);
+ long sizeExact = cursor.getSize(Result.SizePrecision.EXACT, 100000);
+ long sizeApprox = cursor.getSize(Result.SizePrecision.APPROXIMATION, 100000);
+ long sizeFastApprox = cursor.getSize(Result.SizePrecision.FAST_APPROXIMATION, 100000);
+ assertTrue(Math.abs(sizeExact - sizeApprox) < 10);
+ assertTrue(Math.abs(sizeExact - sizeFastApprox) > 10000);
+ } finally {
+ solrServer.shutdown();
+ }
}
@Test