Use plain random values for generating *SortBuilders
This commit is contained in:
parent
cf1d0d5935
commit
4cf5385e4d
|
@ -53,27 +53,23 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
|
|||
}
|
||||
|
||||
if (randomBoolean()) {
|
||||
builder.missing(ESTestCase.randomValueOtherThan(builder.missing(), () -> randomFrom(missingContent)));
|
||||
builder.missing(randomFrom(missingContent));
|
||||
}
|
||||
|
||||
if (randomBoolean()) {
|
||||
builder.unmappedType(ESTestCase.randomValueOtherThan(
|
||||
builder.unmappedType(),
|
||||
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
|
||||
builder.unmappedType(ESTestCase.randomAsciiOfLengthBetween(1, 10));
|
||||
}
|
||||
|
||||
if (randomBoolean()) {
|
||||
builder.sortMode(ESTestCase.randomValueOtherThan(builder.sortMode(), () -> randomFrom(SortMode.values())));
|
||||
builder.sortMode(randomFrom(SortMode.values()));
|
||||
}
|
||||
|
||||
if (randomBoolean()) {
|
||||
builder.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(builder.getNestedFilter()));
|
||||
builder.setNestedFilter(NestedQueryBuilderGenerator.randomNestedFilter());
|
||||
}
|
||||
|
||||
if (randomBoolean()) {
|
||||
builder.setNestedPath(ESTestCase.randomValueOtherThan(
|
||||
builder.getNestedPath(),
|
||||
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
|
||||
builder.setNestedPath(ESTestCase.randomAsciiOfLengthBetween(1, 10));
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
@ -86,25 +82,27 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
|
|||
switch (parameter) {
|
||||
case 0:
|
||||
mutated.setNestedPath(ESTestCase.randomValueOtherThan(
|
||||
mutated.getNestedPath(),
|
||||
original.getNestedPath(),
|
||||
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
|
||||
break;
|
||||
case 1:
|
||||
mutated.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(mutated.getNestedFilter()));
|
||||
mutated.setNestedFilter(ESTestCase.randomValueOtherThan(
|
||||
original.getNestedFilter(),
|
||||
() -> NestedQueryBuilderGenerator.randomNestedFilter()));
|
||||
break;
|
||||
case 2:
|
||||
mutated.sortMode(ESTestCase.randomValueOtherThan(mutated.sortMode(), () -> randomFrom(SortMode.values())));
|
||||
mutated.sortMode(ESTestCase.randomValueOtherThan(original.sortMode(), () -> randomFrom(SortMode.values())));
|
||||
break;
|
||||
case 3:
|
||||
mutated.unmappedType(ESTestCase.randomValueOtherThan(
|
||||
mutated.unmappedType(),
|
||||
original.unmappedType(),
|
||||
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
|
||||
break;
|
||||
case 4:
|
||||
mutated.missing(ESTestCase.randomValueOtherThan(mutated.missing(), () -> randomFrom(missingContent)));
|
||||
mutated.missing(ESTestCase.randomValueOtherThan(original.missing(), () -> randomFrom(missingContent)));
|
||||
break;
|
||||
case 5:
|
||||
mutated.order(ESTestCase.randomValueOtherThan(mutated.order(), () -> randomFrom(SortOrder.values())));
|
||||
mutated.order(ESTestCase.randomValueOtherThan(original.order(), () -> randomFrom(SortOrder.values())));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported mutation.");
|
||||
|
|
|
@ -89,7 +89,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
result.sortMode(mode(result.sortMode()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
result.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(result.getNestedFilter()));
|
||||
result.setNestedFilter(NestedQueryBuilderGenerator.randomNestedFilter());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
result.setNestedPath(
|
||||
|
@ -177,7 +177,9 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
result.sortMode(mode(original.sortMode()));
|
||||
break;
|
||||
case 6:
|
||||
result.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(original.getNestedFilter()));
|
||||
result.setNestedFilter(ESTestCase.randomValueOtherThan(
|
||||
original.getNestedFilter(),
|
||||
() -> NestedQueryBuilderGenerator.randomNestedFilter()));
|
||||
break;
|
||||
case 7:
|
||||
result.setNestedPath(ESTestCase.randomValueOtherThan(
|
||||
|
|
|
@ -38,10 +38,7 @@ public class NestedQueryBuilderGenerator {
|
|||
new IdsQueryBuilder(),
|
||||
new TermQueryBuilder(ESTestCase.randomAsciiOfLengthBetween(1, 10), ESTestCase.randomDouble()));
|
||||
|
||||
public static QueryBuilder<?> nestedFilter(QueryBuilder<?> original) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
QueryBuilder nested = ESTestCase.randomValueOtherThan(original, () -> ESTestCase.randomFrom(builders));
|
||||
nested.boost((float) ESTestCase.randomDoubleBetween(0, 10, false));
|
||||
return nested;
|
||||
public static QueryBuilder<?> randomNestedFilter() {
|
||||
return ESTestCase.randomFrom(builders).boost(ESTestCase.randomFloat());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
|||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
|
@ -63,12 +64,10 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
}
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
builder.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(builder.getNestedFilter()));
|
||||
builder.setNestedFilter(NestedQueryBuilderGenerator.randomNestedFilter());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
builder.setNestedPath(ESTestCase.randomValueOtherThan(
|
||||
builder.getNestedPath(),
|
||||
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
|
||||
builder.setNestedPath(ESTestCase.randomAsciiOfLengthBetween(1, 10));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
@ -115,7 +114,9 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
}
|
||||
break;
|
||||
case 2:
|
||||
result.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(original.getNestedFilter()));
|
||||
result.setNestedFilter(ESTestCase.randomValueOtherThan(
|
||||
original.getNestedFilter(),
|
||||
() -> NestedQueryBuilderGenerator.randomNestedFilter()));
|
||||
break;
|
||||
case 3:
|
||||
result.setNestedPath(original.getNestedPath() + "_some_suffix");
|
||||
|
|
Loading…
Reference in New Issue