[TEST] Beef up test and replace deprecated API

This commit is contained in:
Simon Willnauer 2014-10-27 13:05:12 +01:00
parent 7ea490dfd1
commit a12b34c36c
1 changed files with 12 additions and 6 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.search.sort;
import com.carrotsearch.randomizedtesting.annotations.Repeat;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
@ -69,8 +70,13 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest {
public void testIssue8226() {
int numIndices = between(5, 10);
final boolean useMapping = randomBoolean();
for (int i = 0; i < numIndices; i++) {
if (useMapping) {
assertAcked(prepareCreate("test_" + i).addAlias(new Alias("test")).addMapping("foo", "entry", "type=long"));
} else {
assertAcked(prepareCreate("test_" + i).addAlias(new Alias("test")));
}
if (i > 0) {
client().prepareIndex("test_" + i, "foo", "" + i).setSource("{\"entry\": " + i + "}").get();
}
@ -79,7 +85,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest {
refresh();
// sort DESC
SearchResponse searchResponse = client().prepareSearch()
.addSort(new FieldSortBuilder("entry").order(SortOrder.DESC).ignoreUnmapped(true))
.addSort(new FieldSortBuilder("entry").order(SortOrder.DESC).unmappedType(useMapping ? null : "long"))
.setSize(10).get();
assertSearchResponse(searchResponse);
@ -91,7 +97,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest {
// sort ASC
searchResponse = client().prepareSearch()
.addSort(new FieldSortBuilder("entry").order(SortOrder.ASC).ignoreUnmapped(true))
.addSort(new FieldSortBuilder("entry").order(SortOrder.ASC).unmappedType(useMapping ? null : "long"))
.setSize(10).get();
assertSearchResponse(searchResponse);
@ -123,7 +129,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest {
SearchResponse allDocsResponse = client().prepareSearch().setQuery(QueryBuilders.filteredQuery(matchAllQuery(),
FilterBuilders.boolFilter().must(FilterBuilders.termFilter("foo", "bar"),
FilterBuilders.rangeFilter("timeUpdated").gte("2014/0" + randomIntBetween(1, 7) + "/01").cache(randomBoolean()))))
.addSort(new FieldSortBuilder("timeUpdated").order(SortOrder.ASC).ignoreUnmapped(true))
.addSort(new FieldSortBuilder("timeUpdated").order(SortOrder.ASC).unmappedType("date"))
.setSize(docs).get();
assertSearchResponse(allDocsResponse);
@ -132,7 +138,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest {
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.filteredQuery(matchAllQuery(),
FilterBuilders.boolFilter().must(FilterBuilders.termFilter("foo", "bar"),
FilterBuilders.rangeFilter("timeUpdated").gte("2014/" + String.format(Locale.ROOT, "%02d", randomIntBetween(1, 7)) + "/01").cache(randomBoolean()))))
.addSort(new FieldSortBuilder("timeUpdated").order(SortOrder.ASC).ignoreUnmapped(true))
.addSort(new FieldSortBuilder("timeUpdated").order(SortOrder.ASC).unmappedType("date"))
.setSize(scaledRandomIntBetween(1, docs)).get();
assertSearchResponse(searchResponse);
for (int j = 0; j < searchResponse.getHits().hits().length; j++) {
@ -1124,7 +1130,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest {
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.addSort(SortBuilders.fieldSort("kkk").ignoreUnmapped(true))
.addSort(SortBuilders.fieldSort("kkk").unmappedType("string"))
.execute().actionGet();
assertNoFailures(searchResponse);
}