Skip to content

Commit

Permalink
Add indexRandomForConcurrentSearch for tests: (#11181)
Browse files Browse the repository at this point in the history
* MultiSearchIT.java
* SimpleNestedIT.java
* SearchPreferenceIT.java
* SimpleQueryStringIT.java
* ScriptQuerySearchIT.java

Signed-off-by: Jay Deng <[email protected]>
  • Loading branch information
jed326 authored and Jay Deng committed Nov 14, 2023
1 parent 0539713 commit 8bac796
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ protected Settings featureFlagSettings() {
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.CONCURRENT_SEGMENT_SEARCH, "true").build();
}

public void testSimpleMultiSearch() {
public void testSimpleMultiSearch() throws InterruptedException {
createIndex("test");
ensureGreen();
client().prepareIndex("test").setId("1").setSource("field", "xxx").get();
client().prepareIndex("test").setId("2").setSource("field", "yyy").get();
refresh();
indexRandomForConcurrentSearch("test");
MultiSearchResponse response = client().prepareMultiSearch()
.add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "xxx")))
.add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "yyy")))
Expand All @@ -94,13 +95,14 @@ public void testSimpleMultiSearch() {
assertFirstHit(response.getResponses()[1].getResponse(), hasId("2"));
}

public void testSimpleMultiSearchMoreRequests() {
public void testSimpleMultiSearchMoreRequests() throws InterruptedException {
createIndex("test");
int numDocs = randomIntBetween(0, 16);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test").setId(Integer.toString(i)).setSource("{}", MediaTypeRegistry.JSON).get();
}
refresh();
indexRandomForConcurrentSearch("test");

int numSearchRequests = randomIntBetween(1, 64);
MultiSearchRequest request = new MultiSearchRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void testSimpleNested() throws Exception {
.get();

waitForRelocation(ClusterHealthStatus.GREEN);
indexRandomForConcurrentSearch("test");
GetResponse getResponse = client().prepareGet("test", "1").get();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getSourceAsBytes(), notNullValue());
Expand Down Expand Up @@ -500,6 +501,10 @@ public void testExplain() throws Exception {
}

public void testSimpleNestedSorting() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11187",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
assertAcked(
prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1))
.setMapping(
Expand Down Expand Up @@ -569,6 +574,7 @@ public void testSimpleNestedSorting() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.matchAllQuery())
Expand Down Expand Up @@ -598,6 +604,10 @@ public void testSimpleNestedSorting() throws Exception {
}

public void testSimpleNestedSortingWithNestedFilterMissing() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11187",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
assertAcked(
prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1))
.setMapping(
Expand Down Expand Up @@ -677,6 +687,7 @@ public void testSimpleNestedSortingWithNestedFilterMissing() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("test");

SearchRequestBuilder searchRequestBuilder = client().prepareSearch("test")
.setQuery(QueryBuilders.matchAllQuery())
Expand Down Expand Up @@ -729,6 +740,10 @@ public void testSimpleNestedSortingWithNestedFilterMissing() throws Exception {
}

public void testNestedSortWithMultiLevelFiltering() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11187",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
assertAcked(
prepareCreate("test").setMapping(
"{\n"
Expand Down Expand Up @@ -865,6 +880,7 @@ public void testNestedSortWithMultiLevelFiltering() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("test");

// access id = 1, read, max value, asc, should use grault and quxx
SearchResponse searchResponse = client().prepareSearch()
Expand Down Expand Up @@ -971,7 +987,7 @@ public void testNestedSortWithMultiLevelFiltering() throws Exception {
// https://github.com/elastic/elasticsearch/issues/31554
public void testLeakingSortValues() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11065",
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11187",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
assertAcked(
Expand Down Expand Up @@ -1063,6 +1079,10 @@ public void testLeakingSortValues() throws Exception {
}

public void testSortNestedWithNestedFilter() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11187",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
assertAcked(
prepareCreate("test").setMapping(
XContentFactory.jsonBuilder()
Expand Down Expand Up @@ -1222,6 +1242,7 @@ public void testSortNestedWithNestedFilter() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("test");

// Without nested filter
SearchResponse searchResponse = client().prepareSearch()
Expand Down Expand Up @@ -1460,6 +1481,10 @@ public void testSortNestedWithNestedFilter() throws Exception {

// Issue #9305
public void testNestedSortingWithNestedFilterAsFilter() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11187",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
assertAcked(
prepareCreate("test").setMapping(
jsonBuilder().startObject()
Expand Down Expand Up @@ -1602,6 +1627,7 @@ public void testNestedSortingWithNestedFilterAsFilter() throws Exception {
.get();
assertTrue(indexResponse2.getShardInfo().getSuccessful() > 0);
refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch("test")
.addSort(SortBuilders.fieldSort("users.first").setNestedPath("users").order(SortOrder.ASC))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ public void testNoPreferenceRandom() throws Exception {
assertThat(firstNodeId, not(equalTo(secondNodeId)));
}

public void testSimplePreference() {
public void testSimplePreference() throws InterruptedException {
client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 1}", MediaTypeRegistry.JSON).get();
ensureGreen();

client().prepareIndex("test").setSource("field1", "value1").get();
refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
Expand Down Expand Up @@ -264,7 +265,7 @@ private void assertSearchOnRandomNodes(SearchRequestBuilder request) {
assertThat(hitNodes.size(), greaterThan(1));
}

public void testCustomPreferenceUnaffectedByOtherShardMovements() {
public void testCustomPreferenceUnaffectedByOtherShardMovements() throws InterruptedException {

/*
* Custom preferences can be used to encourage searches to go to a consistent set of shard copies, meaning that other copies' data
Expand All @@ -283,6 +284,7 @@ public void testCustomPreferenceUnaffectedByOtherShardMovements() {
ensureGreen();
client().prepareIndex("test").setSource("field1", "value1").get();
refresh();
indexRandomForConcurrentSearch("test");

final String customPreference = randomAlphaOfLength(10);

Expand All @@ -302,6 +304,7 @@ public void testCustomPreferenceUnaffectedByOtherShardMovements() {
prepareCreate("test2").setSettings(Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, replicasInNewIndex))
);
ensureGreen();
indexRandomForConcurrentSearch("test2");

assertSearchesSpecificNode("test", customPreference, nodeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public void testSimpleQueryStringOnIndexMetaField() throws Exception {
client().prepareIndex("test").setId("2").setSource("foo", 234, "bar", "bcd").get();

refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("test").field("_index")).get();
assertHitCount(searchResponse, 2L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void testCustomScriptBinaryField() throws Exception {
.get();
flush();
refresh();
indexRandomForConcurrentSearch("my-index");

SearchResponse response = client().prepareSearch()
.setQuery(
Expand Down Expand Up @@ -213,6 +214,7 @@ public void testCustomScriptBoost() throws Exception {
.setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject())
.get();
refresh();
indexRandomForConcurrentSearch("test");

logger.info("running doc['num1'].value > 1");
SearchResponse response = client().prepareSearch()
Expand Down Expand Up @@ -259,14 +261,15 @@ public void testCustomScriptBoost() throws Exception {
assertThat(response.getHits().getAt(2).getFields().get("sNum1").getValues().get(0), equalTo(3.0));
}

public void testDisallowExpensiveQueries() {
public void testDisallowExpensiveQueries() throws InterruptedException {
try {
assertAcked(prepareCreate("test-index").setMapping("num1", "type=double"));
int docCount = 10;
for (int i = 1; i <= docCount; i++) {
client().prepareIndex("test-index").setId("" + i).setSource("num1", i).get();
}
refresh();
indexRandomForConcurrentSearch("test-index");

// Execute with search.allow_expensive_queries = null => default value = false => success
Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > 1", Collections.emptyMap());
Expand Down

0 comments on commit 8bac796

Please sign in to comment.