Add tests for remaining IntervalsSourceProvider implementations (#50326)

This PR adds unit tests for wire and xContent serialization of remaining IntervalsSourceProvider
implementations.

Closes #50150
This commit is contained in:
Nikita Glashenko 2020-01-06 15:46:08 +04:00 committed by Christoph Büscher
parent 66c690922c
commit 5533e1172c
9 changed files with 595 additions and 39 deletions

View File

@ -246,6 +246,30 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
public static Match fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
String getQuery() {
return query;
}
int getMaxGaps() {
return maxGaps;
}
boolean isOrdered() {
return ordered;
}
String getAnalyzer() {
return analyzer;
}
IntervalFilter getFilter() {
return filter;
}
String getUseField() {
return useField;
}
}
public static class Disjunction extends IntervalsSourceProvider {
@ -290,12 +314,13 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Disjunction that = (Disjunction) o;
return Objects.equals(subSources, that.subSources);
return Objects.equals(subSources, that.subSources) &&
Objects.equals(filter, that.filter);
}
@Override
public int hashCode() {
return Objects.hash(subSources);
return Objects.hash(subSources, filter);
}
@Override
@ -342,6 +367,14 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
public static Disjunction fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
List<IntervalsSourceProvider> getSubSources() {
return subSources;
}
IntervalFilter getFilter() {
return filter;
}
}
public static class Combine extends IntervalsSourceProvider {
@ -393,12 +426,14 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
if (o == null || getClass() != o.getClass()) return false;
Combine combine = (Combine) o;
return Objects.equals(subSources, combine.subSources) &&
ordered == combine.ordered && maxGaps == combine.maxGaps;
ordered == combine.ordered &&
maxGaps == combine.maxGaps &&
Objects.equals(filter, combine.filter);
}
@Override
public int hashCode() {
return Objects.hash(subSources, ordered, maxGaps);
return Objects.hash(subSources, ordered, maxGaps, filter);
}
@Override
@ -452,6 +487,22 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
public static Combine fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
List<IntervalsSourceProvider> getSubSources() {
return subSources;
}
boolean isOrdered() {
return ordered;
}
int getMaxGaps() {
return maxGaps;
}
IntervalFilter getFilter() {
return filter;
}
}
public static class Prefix extends IntervalsSourceProvider {
@ -838,6 +889,30 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
public static Fuzzy fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
String getTerm() {
return term;
}
int getPrefixLength() {
return prefixLength;
}
boolean isTranspositions() {
return transpositions;
}
Fuzziness getFuzziness() {
return fuzziness;
}
String getAnalyzer() {
return analyzer;
}
String getUseField() {
return useField;
}
}
static class ScriptFilterSource extends FilteredIntervalsSource {
@ -985,6 +1060,18 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
}
return new IntervalFilter(intervals, type);
}
String getType() {
return type;
}
IntervalsSourceProvider getFilter() {
return filter;
}
Script getScript() {
return script;
}
}

View File

@ -277,6 +277,7 @@ import org.elasticsearch.search.suggest.term.TermSuggestion;
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@ -286,6 +287,7 @@ import static java.util.Collections.unmodifiableMap;
import static java.util.Objects.requireNonNull;
import static org.elasticsearch.index.query.CommonTermsQueryBuilder.COMMON_TERMS_QUERY_DEPRECATION_MSG;
import static org.elasticsearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder;
import static java.util.Collections.unmodifiableList;
/**
* Sets up things that can be done at search time like queries, aggregations, and suggesters.
@ -851,18 +853,23 @@ public class SearchModule {
}
private void registerIntervalsSourceProviders() {
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Match.NAME, IntervalsSourceProvider.Match::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Combine.NAME, IntervalsSourceProvider.Combine::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Disjunction.NAME, IntervalsSourceProvider.Disjunction::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Prefix.NAME, IntervalsSourceProvider.Prefix::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Wildcard.NAME, IntervalsSourceProvider.Wildcard::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Fuzzy.NAME, IntervalsSourceProvider.Fuzzy::new));
namedWriteables.addAll(getIntervalsSourceProviderNamedWritables());
}
public static List<NamedWriteableRegistry.Entry> getIntervalsSourceProviderNamedWritables() {
return unmodifiableList(Arrays.asList(
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class, IntervalsSourceProvider.Match.NAME,
IntervalsSourceProvider.Match::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class, IntervalsSourceProvider.Combine.NAME,
IntervalsSourceProvider.Combine::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class, IntervalsSourceProvider.Disjunction.NAME,
IntervalsSourceProvider.Disjunction::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class, IntervalsSourceProvider.Prefix.NAME,
IntervalsSourceProvider.Prefix::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class, IntervalsSourceProvider.Wildcard.NAME,
IntervalsSourceProvider.Wildcard::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class, IntervalsSourceProvider.Fuzzy.NAME,
IntervalsSourceProvider.Fuzzy::new)));
}
private void registerQuery(QuerySpec<?> spec) {

View File

@ -0,0 +1,88 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.index.query;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
import java.util.List;
import static org.elasticsearch.index.query.IntervalsSourceProvider.Combine;
public class CombineIntervalsSourceProviderTests extends AbstractSerializingTestCase<Combine> {
@Override
protected Combine createTestInstance() {
return IntervalQueryBuilderTests.createRandomCombine(0, randomBoolean());
}
@Override
protected Combine mutateInstance(Combine instance) throws IOException {
List<IntervalsSourceProvider> subSources = instance.getSubSources();
boolean ordered = instance.isOrdered();
int maxGaps = instance.getMaxGaps();
IntervalsSourceProvider.IntervalFilter filter = instance.getFilter();
switch (between(0, 3)) {
case 0:
subSources = subSources == null ?
IntervalQueryBuilderTests.createRandomSourceList(0, randomBoolean(), randomInt(5) + 1) :
null;
break;
case 1:
ordered = !ordered;
break;
case 2:
maxGaps++;
break;
case 3:
filter = filter == null ?
IntervalQueryBuilderTests.createRandomNonNullFilter(0, randomBoolean()) :
FilterIntervalsSourceProviderTests.mutateFilter(filter);
break;
default:
throw new AssertionError("Illegal randomisation branch");
}
return new Combine(subSources, ordered, maxGaps, filter);
}
@Override
protected Writeable.Reader<Combine> instanceReader() {
return Combine::new;
}
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(SearchModule.getIntervalsSourceProviderNamedWritables());
}
@Override
protected Combine doParseInstance(XContentParser parser) throws IOException {
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
Combine combine = (Combine) IntervalsSourceProvider.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
return combine;
}
}

View File

@ -0,0 +1,75 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.index.query;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
import java.util.List;
import static org.elasticsearch.index.query.IntervalsSourceProvider.Disjunction;
public class DisjunctionIntervalsSourceProviderTests extends AbstractSerializingTestCase<Disjunction> {
@Override
protected Disjunction createTestInstance() {
return IntervalQueryBuilderTests.createRandomDisjunction(0, randomBoolean());
}
@Override
protected Disjunction mutateInstance(Disjunction instance) throws IOException {
List<IntervalsSourceProvider> subSources = instance.getSubSources();
IntervalsSourceProvider.IntervalFilter filter = instance.getFilter();
if (randomBoolean()) {
subSources = subSources == null ?
IntervalQueryBuilderTests.createRandomSourceList(0, randomBoolean(), randomInt(5) + 1) :
null;
} else {
filter = filter == null ?
IntervalQueryBuilderTests.createRandomNonNullFilter(0, randomBoolean()) :
FilterIntervalsSourceProviderTests.mutateFilter(filter);
}
return new Disjunction(subSources, filter);
}
@Override
protected Writeable.Reader<Disjunction> instanceReader() {
return Disjunction::new;
}
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(SearchModule.getIntervalsSourceProviderNamedWritables());
}
@Override
protected Disjunction doParseInstance(XContentParser parser) throws IOException {
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
Disjunction disjunction = (Disjunction) IntervalsSourceProvider.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
return disjunction;
}
}

View File

@ -0,0 +1,87 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.index.query;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
import java.util.Collections;
import static org.elasticsearch.index.query.IntervalsSourceProvider.IntervalFilter;
public class FilterIntervalsSourceProviderTests extends AbstractSerializingTestCase<IntervalFilter> {
@Override
protected IntervalFilter createTestInstance() {
return IntervalQueryBuilderTests.createRandomNonNullFilter(0, randomBoolean());
}
@Override
protected IntervalFilter mutateInstance(IntervalFilter instance) throws IOException {
return mutateFilter(instance);
}
static IntervalFilter mutateFilter(IntervalFilter instance) {
IntervalsSourceProvider filter = instance.getFilter();
String type = instance.getType();
Script script = instance.getScript();
if (filter != null) {
if (randomBoolean()) {
if (filter instanceof IntervalsSourceProvider.Match) {
filter = WildcardIntervalsSourceProviderTests.createRandomWildcard();
} else {
filter = IntervalQueryBuilderTests.createRandomMatch(0, randomBoolean());
}
} else {
if (type.equals("containing")) {
type = "overlapping";
} else {
type = "containing";
}
}
return new IntervalFilter(filter, type);
} else {
return new IntervalFilter(new Script(ScriptType.INLINE, "mockscript", script.getIdOrCode() + "foo", Collections.emptyMap()));
}
}
@Override
protected Writeable.Reader<IntervalFilter> instanceReader() {
return IntervalFilter::new;
}
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(SearchModule.getIntervalsSourceProviderNamedWritables());
}
@Override
protected IntervalFilter doParseInstance(XContentParser parser) throws IOException {
parser.nextToken();
return IntervalFilter.fromXContent(parser);
}
}

View File

@ -0,0 +1,101 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.index.query;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.IntervalsSourceProvider.Fuzzy;
import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
public class FuzzyIntervalsSourceProviderTests extends AbstractSerializingTestCase<Fuzzy> {
@Override
protected Fuzzy createTestInstance() {
return new Fuzzy(
randomAlphaOfLength(10),
randomInt(5),
randomBoolean(),
Fuzziness.fromEdits(randomInt(2)),
randomBoolean() ? null : randomAlphaOfLength(10),
randomBoolean() ? null : randomAlphaOfLength(10)
);
}
@Override
protected Fuzzy mutateInstance(Fuzzy instance) throws IOException {
String term = instance.getTerm();
int prefixLength = instance.getPrefixLength();
boolean isTranspositions = instance.isTranspositions();
Fuzziness fuzziness = instance.getFuzziness();
String analyzer = instance.getAnalyzer();
String useField = instance.getUseField();
switch (between(0, 5)) {
case 0:
term = randomAlphaOfLength(5);
break;
case 1:
prefixLength++;
break;
case 2:
isTranspositions = !isTranspositions;
break;
case 3:
if (fuzziness.equals(Fuzziness.ZERO)) {
fuzziness = Fuzziness.ONE;
} else {
fuzziness = Fuzziness.ZERO;
}
break;
case 4:
analyzer = analyzer == null ? randomAlphaOfLength(5) : null;
break;
case 5:
useField = useField == null ? randomAlphaOfLength(5) : null;
break;
default:
throw new AssertionError("Illegal randomisation branch");
}
return new Fuzzy(
term,
prefixLength,
isTranspositions,
fuzziness,
analyzer,
useField
);
}
@Override
protected Writeable.Reader<Fuzzy> instanceReader() {
return Fuzzy::new;
}
@Override
protected Fuzzy doParseInstance(XContentParser parser) throws IOException {
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
Fuzzy Fuzzy = (Fuzzy) IntervalsSourceProvider.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
return Fuzzy;
}
}

View File

@ -89,47 +89,61 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
new CompressedXContent(Strings.toString(mapping)), MapperService.MergeReason.MAPPING_UPDATE);
}
private IntervalsSourceProvider createRandomSource(int depth, boolean useScripts) {
private static IntervalsSourceProvider createRandomSource(int depth, boolean useScripts) {
if (depth > 2) {
return createRandomMatch(depth + 1, useScripts);
}
switch (randomInt(20)) {
case 0:
case 1:
int orCount = randomInt(4) + 1;
List<IntervalsSourceProvider> orSources = new ArrayList<>();
for (int i = 0; i < orCount; i++) {
orSources.add(createRandomSource(depth + 1, useScripts));
}
return new IntervalsSourceProvider.Disjunction(orSources, createRandomFilter(depth + 1, useScripts));
return createRandomDisjunction(depth, useScripts);
case 2:
case 3:
int count = randomInt(5) + 1;
List<IntervalsSourceProvider> subSources = new ArrayList<>();
for (int i = 0; i < count; i++) {
subSources.add(createRandomSource(depth + 1, useScripts));
}
boolean ordered = randomBoolean();
int maxGaps = randomInt(5) - 1;
IntervalsSourceProvider.IntervalFilter filter = createRandomFilter(depth + 1, useScripts);
return new IntervalsSourceProvider.Combine(subSources, ordered, maxGaps, filter);
return createRandomCombine(depth, useScripts);
default:
return createRandomMatch(depth + 1, useScripts);
}
}
private IntervalsSourceProvider.IntervalFilter createRandomFilter(int depth, boolean useScripts) {
static IntervalsSourceProvider.Disjunction createRandomDisjunction(int depth, boolean useScripts) {
int orCount = randomInt(4) + 1;
List<IntervalsSourceProvider> orSources = createRandomSourceList(depth, useScripts, orCount);
return new IntervalsSourceProvider.Disjunction(orSources, createRandomFilter(depth + 1, useScripts));
}
static IntervalsSourceProvider.Combine createRandomCombine(int depth, boolean useScripts) {
int count = randomInt(5) + 1;
List<IntervalsSourceProvider> subSources = createRandomSourceList(depth, useScripts, count);
boolean ordered = randomBoolean();
int maxGaps = randomInt(5) - 1;
IntervalsSourceProvider.IntervalFilter filter = createRandomFilter(depth + 1, useScripts);
return new IntervalsSourceProvider.Combine(subSources, ordered, maxGaps, filter);
}
static List<IntervalsSourceProvider> createRandomSourceList(int depth, boolean useScripts, int count) {
List<IntervalsSourceProvider> subSources = new ArrayList<>();
for (int i = 0; i < count; i++) {
subSources.add(createRandomSource(depth + 1, useScripts));
}
return subSources;
}
private static IntervalsSourceProvider.IntervalFilter createRandomFilter(int depth, boolean useScripts) {
if (depth < 3 && randomInt(20) > 18) {
return createRandomNonNullFilter(depth, useScripts);
}
return null;
}
static IntervalsSourceProvider.IntervalFilter createRandomNonNullFilter(int depth, boolean useScripts) {
if (useScripts == false || randomBoolean()) {
return new IntervalsSourceProvider.IntervalFilter(createRandomSource(depth + 1, false), randomFrom(filters));
}
return new IntervalsSourceProvider.IntervalFilter(
new Script(ScriptType.INLINE, "mockscript", "1", Collections.emptyMap()));
}
return null;
}
private IntervalsSourceProvider createRandomMatch(int depth, boolean useScripts) {
static IntervalsSourceProvider.Match createRandomMatch(int depth, boolean useScripts) {
String useField = rarely() ? MASKED_FIELD : null;
int wordCount = randomInt(4) + 1;
List<String> words = new ArrayList<>();

View File

@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.index.query;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
import static org.elasticsearch.index.query.IntervalsSourceProvider.Match;
public class MatchIntervalsSourceProviderTests extends AbstractSerializingTestCase<Match> {
@Override
protected Match createTestInstance() {
return IntervalQueryBuilderTests.createRandomMatch(0, randomBoolean());
}
@Override
protected Match mutateInstance(Match instance) throws IOException {
String query = instance.getQuery();
int maxGaps = instance.getMaxGaps();
boolean isOrdered = instance.isOrdered();
String analyzer = instance.getAnalyzer();
IntervalsSourceProvider.IntervalFilter filter = instance.getFilter();
String useField = instance.getUseField();
switch (between(0, 5)) {
case 0:
query = randomAlphaOfLength(query.length() + 3);
break;
case 1:
maxGaps++;
break;
case 2:
isOrdered = !isOrdered;
break;
case 3:
analyzer = analyzer == null ? randomAlphaOfLength(5) : null;
break;
case 4:
filter = filter == null ?
IntervalQueryBuilderTests.createRandomNonNullFilter(0, randomBoolean()) :
FilterIntervalsSourceProviderTests.mutateFilter(filter);
break;
case 5:
useField = useField == null ? randomAlphaOfLength(5) : (useField + "foo");
break;
default:
throw new AssertionError("Illegal randomisation branch");
}
return new Match(query, maxGaps, isOrdered, analyzer, filter, useField);
}
@Override
protected Writeable.Reader<Match> instanceReader() {
return Match::new;
}
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(SearchModule.getIntervalsSourceProviderNamedWritables());
}
@Override
protected Match doParseInstance(XContentParser parser) throws IOException {
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
Match Match = (Match) IntervalsSourceProvider.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
return Match;
}
}

View File

@ -31,6 +31,10 @@ public class WildcardIntervalsSourceProviderTests extends AbstractSerializingTes
@Override
protected Wildcard createTestInstance() {
return createRandomWildcard();
}
static Wildcard createRandomWildcard() {
return new Wildcard(
randomAlphaOfLength(10),
randomBoolean() ? randomAlphaOfLength(10) : null,