Fix UnsignedLongTests test failure (#63056)
Test testSortDifferentFormatsShouldFail was occasionally failing for 2 reasons: 1) Documents on "idx2" were not available for search before a search request started 2) Running a test multiple times was causing occasional ResourceAlreadyExistsException for idx2, as idx2 was not deleted for a test. This patch makes the following fixes: 1) Sets up immediate refresh policy for docs in the index"idx2" 2) Creates an index idx2 only once per cluster Closes: #62997
This commit is contained in:
parent
e31bef4032
commit
f221349593
|
@ -6,10 +6,13 @@
|
|||
package org.elasticsearch.xpack.unsignedlong;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -21,7 +24,6 @@ import org.elasticsearch.search.aggregations.metrics.Sum;
|
|||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -69,6 +71,16 @@ public class UnsignedLongTests extends ESIntegTestCase {
|
|||
);
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
|
||||
prepareCreate("idx2").addMapping("_doc", "ul_field", "type=long").setSettings(settings).get();
|
||||
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
|
||||
bulkRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
IndexRequest indexRequest = new IndexRequest("idx2").source("ul_field", values[i]);
|
||||
bulkRequestBuilder.add(indexRequest);
|
||||
}
|
||||
bulkRequestBuilder.get();
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
|
@ -269,18 +281,7 @@ public class UnsignedLongTests extends ESIntegTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testSortDifferentFormatsShouldFail() throws IOException, InterruptedException {
|
||||
Settings.Builder settings = Settings.builder().put(indexSettings()).put("number_of_shards", 1);
|
||||
prepareCreate("idx2").addMapping("_doc", "ul_field", "type=long").setSettings(settings).get();
|
||||
List<IndexRequestBuilder> builders = new ArrayList<>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
builders.add(
|
||||
client().prepareIndex("idx2", "_doc").setSource(jsonBuilder().startObject().field("ul_field", values[i]).endObject())
|
||||
);
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
ensureSearchable();
|
||||
|
||||
public void testSortDifferentFormatsShouldFail() {
|
||||
Exception exception = expectThrows(
|
||||
SearchPhaseExecutionException.class,
|
||||
() -> client().prepareSearch()
|
||||
|
|
Loading…
Reference in New Issue