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