You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/04/25 13:59:37 UTC
[10/17] lucene-solr:jira/solr-8668: SOLR-10047: Move test into its
own test class and force use of NoMergePolicy to fix test failures
SOLR-10047: Move test into its own test class and force use of NoMergePolicy to fix test failures
This closes #195
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/56e1ad48
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/56e1ad48
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/56e1ad48
Branch: refs/heads/jira/solr-8668
Commit: 56e1ad484a2c7431932a95e442bc1a584f60698e
Parents: c09d82e
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Tue Apr 25 00:26:21 2017 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Tue Apr 25 00:26:21 2017 +0530
----------------------------------------------------------------------
.../org/apache/solr/schema/DocValuesTest.java | 72 ----------
.../solr/schema/TestHalfAndHalfDocValues.java | 136 +++++++++++++++++++
2 files changed, 136 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/56e1ad48/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java b/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
index 2d8afee..cf43a68 100644
--- a/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java
@@ -25,14 +25,10 @@ import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReader;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.queries.function.FunctionValues;
@@ -155,74 +151,6 @@ public class DocValuesTest extends SolrTestCaseJ4 {
}
}
-
- public void testHalfAndHalfDocValues() throws Exception {
- // Insert two docs without docvalues
- String fieldname = "string_add_dv_later";
- assertU(adoc("id", "3", fieldname, "c"));
- assertU(commit());
- assertU(adoc("id", "1", fieldname, "a"));
- assertU(commit());
-
-
- try (SolrCore core = h.getCoreInc()) {
- assertFalse(core.getLatestSchema().getField(fieldname).hasDocValues());
- // Add docvalues to the field type
- IndexSchema schema = core.getLatestSchema();
- SchemaField oldField = schema.getField(fieldname);
- int newProperties = oldField.getProperties() | SchemaField.DOC_VALUES;
-
- SchemaField sf = new SchemaField( fieldname, oldField.getType(), newProperties, null);
- schema.getFields().put( fieldname, sf );
-
- // Insert a new doc with docvalues
- assertU(adoc("id", "2", fieldname, "b"));
- assertU(commit());
-
-
- // Check there are a mix of segments with and without docvalues
- final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
- final SolrIndexSearcher searcher = searcherRef.get();
- try {
- final DirectoryReader topReader = searcher.getRawReader();
-
- //Assert no merges
-
- assertEquals(3, topReader.numDocs());
- assertEquals(3, topReader.leaves().size());
-
- final FieldInfos infos = MultiFields.getMergedFieldInfos(topReader);
- //The global field type should have docValues because a document with dvs was added
- assertEquals(DocValuesType.SORTED, infos.fieldInfo(fieldname).getDocValuesType());
-
- for(LeafReaderContext ctx: topReader.leaves()) {
- LeafReader r = ctx.reader();
- //Make sure there were no merges
- assertEquals(1, r.numDocs());
- Document doc = r.document(0);
- String id = doc.getField("id").stringValue();
-
- if(id.equals("1") || id.equals("3")) {
- assertEquals(DocValuesType.NONE, r.getFieldInfos().fieldInfo(fieldname).getDocValuesType());
- } else {
- assertEquals(DocValuesType.SORTED, r.getFieldInfos().fieldInfo(fieldname).getDocValuesType());
- }
-
- }
- } finally {
- searcherRef.decref();
- }
- }
-
- // Assert sort order is correct
- assertQ(req("q", "string_add_dv_later:*", "sort", "string_add_dv_later asc"),
- "//*[@numFound='3']",
- "//result/doc[1]/int[@name='id'][.=1]",
- "//result/doc[2]/int[@name='id'][.=2]",
- "//result/doc[3]/int[@name='id'][.=3]"
- );
- }
-
private void tstToObj(SchemaField sf, Object o) {
List<IndexableField> fields = sf.createFields(o);
for (IndexableField field : fields) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/56e1ad48/solr/core/src/test/org/apache/solr/schema/TestHalfAndHalfDocValues.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TestHalfAndHalfDocValues.java b/solr/core/src/test/org/apache/solr/schema/TestHalfAndHalfDocValues.java
new file mode 100644
index 0000000..b0c3956
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/schema/TestHalfAndHalfDocValues.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.schema;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.DocValuesType;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.LeafReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.MultiFields;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.index.NoMergePolicyFactory;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RefCounted;
+import org.junit.BeforeClass;
+
+/**
+ * Added in SOLR-10047
+ */
+public class TestHalfAndHalfDocValues extends SolrTestCaseJ4 {
+
+ @BeforeClass
+ public static void beforeTests() throws Exception {
+ // we need consistent segments that aren't merged because we want to have
+ // segments with and without docvalues
+ systemSetPropertySolrTestsMergePolicyFactory(NoMergePolicyFactory.class.getName());
+
+ // HACK: Don't use a RandomMergePolicy, but only use the mergePolicyFactory that we've just set
+ System.setProperty(SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY, "true");
+ System.setProperty(SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICY, "false");
+
+ initCore("solrconfig-basic.xml", "schema-docValues.xml");
+
+ // sanity check our schema meets our expectations
+ final IndexSchema schema = h.getCore().getLatestSchema();
+ for (String f : new String[]{"floatdv", "intdv", "doubledv", "longdv", "datedv", "stringdv", "booldv"}) {
+ final SchemaField sf = schema.getField(f);
+ assertFalse(f + " is multiValued, test is useless, who changed the schema?",
+ sf.multiValued());
+ assertFalse(f + " is indexed, test is useless, who changed the schema?",
+ sf.indexed());
+ assertTrue(f + " has no docValues, test is useless, who changed the schema?",
+ sf.hasDocValues());
+ }
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ assertU(delQ("*:*"));
+ }
+
+ public void testHalfAndHalfDocValues() throws Exception {
+ // Insert two docs without docvalues
+ String fieldname = "string_add_dv_later";
+ assertU(adoc("id", "3", fieldname, "c"));
+ assertU(commit());
+ assertU(adoc("id", "1", fieldname, "a"));
+ assertU(commit());
+
+
+ try (SolrCore core = h.getCoreInc()) {
+ assertFalse(core.getLatestSchema().getField(fieldname).hasDocValues());
+ // Add docvalues to the field type
+ IndexSchema schema = core.getLatestSchema();
+ SchemaField oldField = schema.getField(fieldname);
+ int newProperties = oldField.getProperties() | SchemaField.DOC_VALUES;
+
+ SchemaField sf = new SchemaField(fieldname, oldField.getType(), newProperties, null);
+ schema.getFields().put(fieldname, sf);
+
+ // Insert a new doc with docvalues
+ assertU(adoc("id", "2", fieldname, "b"));
+ assertU(commit());
+
+
+ // Check there are a mix of segments with and without docvalues
+ final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
+ final SolrIndexSearcher searcher = searcherRef.get();
+ try {
+ final DirectoryReader topReader = searcher.getRawReader();
+
+ //Assert no merges
+
+ assertEquals(3, topReader.numDocs());
+ assertEquals(3, topReader.leaves().size());
+
+ final FieldInfos infos = MultiFields.getMergedFieldInfos(topReader);
+ //The global field type should have docValues because a document with dvs was added
+ assertEquals(DocValuesType.SORTED, infos.fieldInfo(fieldname).getDocValuesType());
+
+ for (LeafReaderContext ctx : topReader.leaves()) {
+ LeafReader r = ctx.reader();
+ //Make sure there were no merges
+ assertEquals(1, r.numDocs());
+ Document doc = r.document(0);
+ String id = doc.getField("id").stringValue();
+
+ if (id.equals("1") || id.equals("3")) {
+ assertEquals(DocValuesType.NONE, r.getFieldInfos().fieldInfo(fieldname).getDocValuesType());
+ } else {
+ assertEquals(DocValuesType.SORTED, r.getFieldInfos().fieldInfo(fieldname).getDocValuesType());
+ }
+
+ }
+ } finally {
+ searcherRef.decref();
+ }
+ }
+
+ // Assert sort order is correct
+ assertQ(req("q", "string_add_dv_later:*", "sort", "string_add_dv_later asc"),
+ "//*[@numFound='3']",
+ "//result/doc[1]/int[@name='id'][.=1]",
+ "//result/doc[2]/int[@name='id'][.=2]",
+ "//result/doc[3]/int[@name='id'][.=3]"
+ );
+ }
+
+}