SOLR-11123: Randomize PointFields in test classes that had usage of Trie field classes/names hardcoded

This commit is contained in:
Chris Hostetter 2017-07-19 17:51:49 -07:00
parent e7d0063dc1
commit 9e5eaca217
14 changed files with 117 additions and 124 deletions

View File

@ -521,6 +521,7 @@ Other Changes
- SOLR-11074: Randomize PointFields in cloud-dynamic configset and all related tests (Anshum Gupta)
- SOLR-11121: Randomize PointFields in schema-trie.xml and TestTrie (hossman)
- SOLR-11120: Remove trie fieldTypes from schema-points.xml (hossman)
- SOLR-11123: Randomize PointFields in test classes that had usage of Trie field classes/names hardcoded (hossman)
* SOLR-6807: Changed requestDispatcher's handleSelect to default to false, thus ignoring "qt".
Simplified configs to not refer to handleSelect or "qt". Switch all tests that assumed true to assume false

View File

@ -17,7 +17,6 @@
-->
<schema name="test-custom-comparator" version="1.6">
<fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="${solr.tests.numeric.dv}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="long" class="${solr.tests.LongFieldType}" docValues="${solr.tests.numeric.dv}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
<fieldType name="text" class="solr.TextField">
@ -25,11 +24,12 @@
<tokenizer class="solr.StandardTokenizerFactory"/>
</analyzer>
</fieldType>
<fieldType class="org.apache.solr.schema.WrappedIntField" name="wrapped_int"/>
<fieldType class="org.apache.solr.schema.WrappedTrieIntField" name="wrapped_trie_int" docValues="${solr.tests.numeric.dv}" />
<fieldType class="org.apache.solr.schema.WrappedIntPointField" name="wrapped_point_int" docValues="${solr.tests.numeric.dv}" />
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>
<field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
<field name="text" type="text" indexed="true" stored="false"/>
<field name="payload" type="wrapped_int" indexed="false"
<field name="payload" type="${solr.tests.payload.fieldtype}" indexed="false"
stored="true" multiValued="false" docValues="true" required="true"/>
<uniqueKey>id</uniqueKey>

View File

@ -29,7 +29,8 @@ import org.junit.BeforeClass;
import org.junit.Test;
/**
* Tests for TrieField functionality
* Tests for numeric field functionality. The name originated from {@link TrieField}, but all tests
* done in this class are also valid for any numeric field types.
*
*
* @since solr 1.4

View File

@ -23,6 +23,7 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@ -132,11 +133,11 @@ public class DocValuesNotIndexedTest extends SolrCloudTestCase {
fieldsToTestMulti.size() + fieldsToTestGroupSortFirst.size() + fieldsToTestGroupSortLast.size() +
4);
updateList.add(getType("name", "float", "class", "solr.TrieFloatField", "precisionStep", "0"));
updateList.add(getType("name", "float", "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Float.class)));
updateList.add(getType("name", "double", "class", "solr.TrieDoubleField", "precisionStep", "0"));
updateList.add(getType("name", "double", "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Double.class)));
updateList.add(getType("name", "date", "class", "solr.TrieDateField", "precisionStep", "0"));
updateList.add(getType("name", "date", "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Date.class)));
updateList.add(getType("name", "boolean", "class", "solr.BoolField"));

View File

@ -141,7 +141,7 @@ public class TestStressCloudBlindAtomicUpdates extends SolrCloudTestCase {
// sanity check no one broke the assumptions we make about our schema
checkExpectedSchemaType( map("name","long",
"class", usingPoints ? "solr.LongPointField" : "solr.TrieLongField",
"class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Long.class),
"multiValued",Boolean.FALSE,
"indexed",Boolean.FALSE,
"stored",Boolean.FALSE,

View File

@ -163,7 +163,7 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
assertNotNull(actual.getSimilarity());
}
private static String withWhich = "<schema name=\"tiny\" version=\"1.1\">\n" +
private String withWhich = "<schema name=\"tiny\" version=\"1.1\">\n" +
" <field name=\"id\" type=\"string\" indexed=\"true\" stored=\"true\" required=\"true\"/>\n" +
" <field name=\"text\" type=\"text\" indexed=\"true\" stored=\"true\"/>\n" +
" <field name=\"which\" type=\"int\" indexed=\"true\" stored=\"true\"/>\n" +
@ -177,11 +177,11 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
" </fieldtype>\n" +
" <fieldType name=\"string\" class=\"solr.StrField\"/>\n" +
" <fieldType name=\"int\" class=\"solr.TrieIntField\" precisionStep=\"0\" positionIncrementGap=\"0\"/>" +
" <fieldType name=\"int\" class=\""+RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class)+"\" precisionStep=\"0\" positionIncrementGap=\"0\"/>" +
" <similarity class=\"${solr.test.simfac1}\"/> " +
"</schema>";
private static String withoutWhich = "<schema name=\"tiny\" version=\"1.1\">\n" +
private String withoutWhich = "<schema name=\"tiny\" version=\"1.1\">\n" +
" <field name=\"id\" type=\"string\" indexed=\"true\" stored=\"true\" required=\"true\"/>\n" +
" <field name=\"text\" type=\"text\" indexed=\"true\" stored=\"true\"/>\n" +
" <uniqueKey>id</uniqueKey>\n" +
@ -193,7 +193,7 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
" </analyzer>\n" +
" </fieldtype>\n" +
" <fieldType name=\"string\" class=\"solr.StrField\"/>\n" +
" <fieldType name=\"int\" class=\"solr.TrieIntField\" precisionStep=\"0\" positionIncrementGap=\"0\"/>" +
" <fieldType name=\"int\" class=\""+RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class)+"\" precisionStep=\"0\" positionIncrementGap=\"0\"/>" +
" <similarity class=\"${solr.test.simfac2}\"/> " +
"</schema>";

View File

@ -40,7 +40,8 @@ public class DateFieldTest extends SolrTestCaseJ4 {
SolrConfig config = new SolrConfig
(new SolrResourceLoader(Paths.get(testInstanceDir)), testConfHome + "solrconfig.xml", null);
IndexSchema schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema.xml", config);
f = random().nextBoolean()? new TrieDateField() : new DatePointField();
f = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)
? new DatePointField() : new TrieDateField();
f.init(schema, Collections.<String,String>emptyMap());
}

View File

@ -17,7 +17,9 @@
package org.apache.solr.schema;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
@ -56,117 +58,74 @@ public class PrimitiveFieldTypeTest extends SolrTestCaseJ4 {
@SuppressWarnings("deprecation")
@Test
public void testDefaultOmitNorms() throws Exception {
BinaryField bin;
TextField t;
TrieDateField dt;
StrField s;
TrieIntField ti;
TrieLongField tl;
TrieFloatField tf;
TrieDoubleField td;
BoolField b;
final List<Class<? extends FieldType>> types
= Arrays.asList(TrieDateField.class, DatePointField.class,
TrieIntField.class, IntPointField.class,
TrieLongField.class, IntPointField.class,
TrieFloatField.class, FloatPointField.class,
TrieDoubleField.class, DoublePointField.class,
StrField.class, BoolField.class,
// Non-prims, omitNorms always defaults to false regardless of schema version...
TextField.class, BinaryField.class);
// ***********************
// With schema version 1.4:
// ***********************
schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema12.xml", config);
for (Class<? extends FieldType> clazz : types) {
FieldType ft = clazz.newInstance();
ft.init(schema, initMap);
assertFalse(ft.getClass().getName(), ft.hasProperty(FieldType.OMIT_NORMS));
}
dt = new TrieDateField();
dt.init(schema, initMap);
assertFalse(dt.hasProperty(FieldType.OMIT_NORMS));
s = new StrField();
s.init(schema, initMap);
assertFalse(s.hasProperty(FieldType.OMIT_NORMS));
ti = new TrieIntField();
ti.init(schema, initMap);
assertFalse(ti.hasProperty(FieldType.OMIT_NORMS));
tl = new TrieLongField();
tl.init(schema, initMap);
assertFalse(tl.hasProperty(FieldType.OMIT_NORMS));
tf = new TrieFloatField();
tf.init(schema, initMap);
assertFalse(tf.hasProperty(FieldType.OMIT_NORMS));
td = new TrieDoubleField();
td.init(schema, initMap);
assertFalse(td.hasProperty(FieldType.OMIT_NORMS));
b = new BoolField();
b.init(schema, initMap);
assertFalse(b.hasProperty(FieldType.OMIT_NORMS));
// Non-primitive fields
t = new TextField();
t.init(schema, initMap);
assertFalse(t.hasProperty(FieldType.OMIT_NORMS));
bin = new BinaryField();
bin.init(schema, initMap);
assertFalse(bin.hasProperty(FieldType.OMIT_NORMS));
// ***********************
// With schema version 1.5
// ***********************
schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema15.xml", config);
dt = new TrieDateField();
dt.init(schema, initMap);
assertTrue(dt.hasProperty(FieldType.OMIT_NORMS));
s = new StrField();
s.init(schema, initMap);
assertTrue(s.hasProperty(FieldType.OMIT_NORMS));
ti = new TrieIntField();
ti.init(schema, initMap);
assertTrue(ti.hasProperty(FieldType.OMIT_NORMS));
tl = new TrieLongField();
tl.init(schema, initMap);
assertTrue(tl.hasProperty(FieldType.OMIT_NORMS));
tf = new TrieFloatField();
tf.init(schema, initMap);
assertTrue(tf.hasProperty(FieldType.OMIT_NORMS));
td = new TrieDoubleField();
td.init(schema, initMap);
assertTrue(td.hasProperty(FieldType.OMIT_NORMS));
b = new BoolField();
b.init(schema, initMap);
assertTrue(b.hasProperty(FieldType.OMIT_NORMS));
// Non-primitive fields
t = new TextField();
t.init(schema, initMap);
assertFalse(t.hasProperty(FieldType.OMIT_NORMS));
bin = new BinaryField();
bin.init(schema, initMap);
assertFalse(bin.hasProperty(FieldType.OMIT_NORMS));
for (Class<? extends FieldType> clazz : types) {
FieldType ft = clazz.newInstance();
ft.init(schema, initMap);
assertEquals(ft.getClass().getName(),
ft instanceof PrimitiveFieldType,
ft.hasProperty(FieldType.OMIT_NORMS));
}
}
public void testTrieDateField() {
public void testDateField() {
schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema15.xml", config);
TrieDateField tdt = new TrieDateField();
Map<String, String> args = new HashMap<>();
args.put("sortMissingLast", "true");
args.put("indexed", "true");
args.put("stored", "false");
args.put("docValues", "true");
args.put("precisionStep", "16");
tdt.setArgs(schema, args);
assertTrue(tdt.hasProperty(FieldType.OMIT_NORMS));
assertTrue(tdt.hasProperty(FieldType.SORT_MISSING_LAST));
assertTrue(tdt.hasProperty(FieldType.INDEXED));
assertFalse(tdt.hasProperty(FieldType.STORED));
assertTrue(tdt.hasProperty(FieldType.DOC_VALUES));
assertEquals(16, tdt.getPrecisionStep());
final TrieDateField tdt = new TrieDateField();
{
final Map<String, String> args = new HashMap<>();
args.put("sortMissingLast", "true");
args.put("indexed", "true");
args.put("stored", "false");
args.put("docValues", "true");
args.put("precisionStep", "16");
tdt.setArgs(schema, args);
assertEquals(16, tdt.getPrecisionStep());
}
final DatePointField pdt = new DatePointField();
{
final Map<String, String> args = new HashMap<>();
args.put("sortMissingLast", "true");
args.put("indexed", "true");
args.put("stored", "false");
args.put("docValues", "true");
pdt.setArgs(schema, args);
}
for (FieldType ft : Arrays.asList(tdt, pdt)) {
assertTrue(ft.getClass().getName(), ft.hasProperty(FieldType.OMIT_NORMS));
assertTrue(ft.getClass().getName(), ft.hasProperty(FieldType.SORT_MISSING_LAST));
assertTrue(ft.getClass().getName(), ft.hasProperty(FieldType.INDEXED));
assertFalse(ft.getClass().getName(), ft.hasProperty(FieldType.STORED));
assertTrue(ft.getClass().getName(), ft.hasProperty(FieldType.DOC_VALUES));
}
}
}

View File

@ -149,7 +149,7 @@ public class TestCloudManagedSchemaConcurrent extends AbstractFullDistribZkTestB
}
private static void addFieldTypePut(RestTestHarness publisher, String typeName, int updateTimeoutSecs) throws Exception {
final String content = "{\"class\":\"solr.TrieIntField\"}";
final String content = "{\"class\":\""+RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class)+"\"}";
String request = "/schema/fieldtypes/" + typeName + "?wt=xml";
if (updateTimeoutSecs > 0)
request += "&updateTimeoutSecs="+updateTimeoutSecs;
@ -158,7 +158,7 @@ public class TestCloudManagedSchemaConcurrent extends AbstractFullDistribZkTestB
}
private static void addFieldTypePost(RestTestHarness publisher, String typeName, int updateTimeoutSecs) throws Exception {
final String content = "[{\"name\":\""+typeName+"\",\"class\":\"solr.TrieIntField\"}]";
final String content = "[{\"name\":\""+typeName+"\",\"class\":\""+RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class)+"\"}]";
String request = "/schema/fieldtypes/?wt=xml";
if (updateTimeoutSecs > 0)
request += "&updateTimeoutSecs="+updateTimeoutSecs;

View File

@ -102,7 +102,6 @@ public class TestSchemalessBufferedUpdates extends SolrTestCaseJ4 {
// WARN [...] o.a.s.u.UpdateLog REYPLAY_ERR: IOException reading log
// org.apache.solr.common.SolrException: Invalid Date String:'2017-01-05'
// at org.apache.solr.util.DateMathParser.parseMath(DateMathParser.java:234)
// at org.apache.solr.schema.TrieField.createField(TrieField.java:725) [...]
updateJ(jsonAdd(processAdd(sdoc("id","2", "f_dt","2017-01-05"))), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
Future<UpdateLog.RecoveryInfo> rinfoFuture = ulog.applyBufferedUpdates();

View File

@ -24,22 +24,23 @@ import org.apache.lucene.search.SortField;
/**
* Custom field wrapping an int, to test sorting via a custom comparator.
*/
public class WrappedIntField extends TrieIntField {
Expression expr;
public WrappedIntField() {
public class WrappedIntPointField extends IntPointField {
/** static helper for re-use in sibling trie class */
public static SortField getSortField(final SortField superSort, final SchemaField field) {
field.checkSortability();
Expression expr = null;
try {
expr = JavascriptCompiler.compile("payload % 3");
expr = JavascriptCompiler.compile(field.getName() + " % 3");
} catch (Exception e) {
throw new RuntimeException("impossible?", e);
}
SimpleBindings bindings = new SimpleBindings();
bindings.add(superSort);
return expr.getSortField(bindings, superSort.getReverse());
}
@Override
public SortField getSortField(final SchemaField field, final boolean reverse) {
field.checkSortability();
SimpleBindings bindings = new SimpleBindings();
bindings.add(super.getSortField(field, reverse));
return expr.getSortField(bindings, reverse);
return getSortField(super.getSortField(field, reverse), field);
}
}

View File

@ -0,0 +1,29 @@
/*
* 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.search.SortField;
/**
* Custom field wrapping an int, to test sorting via a custom comparator.
*/
public class WrappedTrieIntField extends TrieIntField {
@Override
public SortField getSortField(final SchemaField field, final boolean reverse) {
return WrappedIntPointField.getSortField(super.getSortField(field, reverse), field);
}
}

View File

@ -27,6 +27,9 @@ public class TestFieldSortValues extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("solr.tests.payload.fieldtype",
Boolean.getBoolean(NUMERIC_POINTS_SYSPROP) ?
"wrapped_point_int" : "wrapped_trie_int");
initCore("solrconfig-minimal.xml", "schema-field-sort-values.xml");
}

View File

@ -24,7 +24,6 @@ import java.util.List;
import com.google.common.collect.ImmutableMap;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.schema.TrieDateField;
import org.apache.solr.util.DateMathParser;
import org.junit.Before;
import org.junit.BeforeClass;
@ -615,7 +614,6 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
doc = new SolrInputDocument();
doc.setField("id", "10001");
TrieDateField trieDF = new TrieDateField();
Date tempDate = DateMathParser.parseMath(null, "2014-02-01T12:00:00Z");
doc.setField("dateRemove", new Date[]{DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"),
DateMathParser.parseMath(null, "2014-07-02T12:00:00Z"),