Get rid of duplicate random sort order generation
This commit is contained in:
parent
8dc0610eaa
commit
0c7e58de93
|
@ -40,7 +40,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
|
|||
String fieldName = rarely() ? FieldSortBuilder.DOC_FIELD_NAME : randomAsciiOfLengthBetween(1, 10);
|
||||
FieldSortBuilder builder = new FieldSortBuilder(fieldName);
|
||||
if (randomBoolean()) {
|
||||
builder.order(RandomSortDataGenerator.order(null));
|
||||
builder.order(randomFrom(SortOrder.values()));
|
||||
}
|
||||
|
||||
if (randomBoolean()) {
|
||||
|
@ -95,7 +95,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
|
|||
mutated.missing(RandomSortDataGenerator.missing(mutated.missing()));
|
||||
break;
|
||||
case 5:
|
||||
mutated.order(RandomSortDataGenerator.order(mutated.order()));
|
||||
mutated.order(ESTestCase.randomValueOtherThan(mutated.order(), () -> randomFrom(SortOrder.values())));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported mutation.");
|
||||
|
|
|
@ -83,7 +83,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
result.unit(unit(result.unit()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
result.order(RandomSortDataGenerator.order(null));
|
||||
result.order(randomFrom(SortOrder.values()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
result.sortMode(mode(result.sortMode()));
|
||||
|
@ -171,7 +171,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
|
|||
result.unit(unit(original.unit()));
|
||||
break;
|
||||
case 4:
|
||||
result.order(RandomSortDataGenerator.order(original.order()));
|
||||
result.order(ESTestCase.randomValueOtherThan(original.order(), () -> randomFrom(SortOrder.values())));
|
||||
break;
|
||||
case 5:
|
||||
result.sortMode(mode(original.sortMode()));
|
||||
|
|
|
@ -84,19 +84,4 @@ public class RandomSortDataGenerator {
|
|||
}
|
||||
return missing;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a random {@link SortOrder} settings, except the one provided by parameter if set
|
||||
*/
|
||||
public static SortOrder order(@Nullable SortOrder original) {
|
||||
if (original == null) {
|
||||
return ESTestCase.randomBoolean() ? SortOrder.ASC : SortOrder.DESC;
|
||||
}
|
||||
if (original.equals(SortOrder.ASC)) {
|
||||
return SortOrder.DESC;
|
||||
} else {
|
||||
return SortOrder.ASC;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.ParsingException;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
|
@ -45,7 +46,7 @@ public class ScoreSortBuilderTests extends AbstractSortTestCase<ScoreSortBuilder
|
|||
@Override
|
||||
protected ScoreSortBuilder mutate(ScoreSortBuilder original) throws IOException {
|
||||
ScoreSortBuilder result = new ScoreSortBuilder();
|
||||
result.order(RandomSortDataGenerator.order(original.order()));
|
||||
result.order(ESTestCase.randomValueOtherThan(original.order(), () -> randomFrom(SortOrder.values())));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
|||
ScriptSortBuilder builder = new ScriptSortBuilder(new Script(randomAsciiOfLengthBetween(5, 10)),
|
||||
type);
|
||||
if (randomBoolean()) {
|
||||
builder.order(RandomSortDataGenerator.order(null));
|
||||
builder.order(randomFrom(SortOrder.values()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
if (type == ScriptSortType.NUMBER) {
|
||||
|
|
Loading…
Reference in New Issue