Skip to content

Commit

Permalink
Refactors CrossClusterSearchTests to fix flaky behavior (opensearch-p…
Browse files Browse the repository at this point in the history
…roject#3526)

* Category: Test fix
* The changes include refactoring so as to fix the warning "Type safety:
A generic array of Pair<String,String> is created for a varargs
parameter" and verify testing is not flaky.
* Testing was conducted through `CI_ENVIRONMENT=normal ./gradlew
integrationTest --tests org.opensearch.security.CrossClusterSearchTests`
due to a temporary change.

Signed-off-by: Eduardo Corazon <[email protected]>
  • Loading branch information
EduardoCorazon authored Oct 16, 2023
1 parent 1166c1f commit ece5e55
Showing 1 changed file with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Arrays;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
Expand Down Expand Up @@ -245,18 +246,17 @@ public void shouldSearchForDocumentOnBothClustersWhenIndexOnBothClusterArePointe
SearchRequest searchRequest = SearchRequestFactory.searchAll(REMOTE_SONG_INDEX, SONG_INDEX_NAME);
searchRequest.setCcsMinimizeRoundtrips(ccsMinimizeRoundtrips);

List<Pair<String, String>> documentIdsList = Arrays.asList(
Pair.of(SONG_INDEX_NAME, SONG_ID_1R),
Pair.of(SONG_INDEX_NAME, SONG_ID_2L),
Pair.of(SONG_INDEX_NAME, SONG_ID_6R)
);

SearchResponse response = restHighLevelClient.search(searchRequest, DEFAULT);

assertThat(response, isSuccessfulSearchResponse());
assertThat(response, numberOfTotalHitsIsEqualTo(3));
assertThat(
response,
searchHitsContainDocumentsInAnyOrder(
Pair.of(SONG_INDEX_NAME, SONG_ID_1R),
Pair.of(SONG_INDEX_NAME, SONG_ID_2L),
Pair.of(SONG_INDEX_NAME, SONG_ID_6R)
)
);
assertThat(response, searchHitsContainDocumentsInAnyOrder(documentIdsList));
}
}

Expand Down Expand Up @@ -286,19 +286,18 @@ public void shouldSearchViaAllAliasOnRemoteCluster_positive() throws IOException
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(ADMIN_USER)) {
SearchRequest searchRequest = searchAll(REMOTE_CLUSTER_NAME + ":_all");

List<Pair<String, String>> documentIdsList = Arrays.asList(
Pair.of(SONG_INDEX_NAME, SONG_ID_1R),
Pair.of(SONG_INDEX_NAME, SONG_ID_6R),
Pair.of(PROHIBITED_SONG_INDEX_NAME, SONG_ID_3R),
Pair.of(LIMITED_USER_INDEX_NAME, SONG_ID_5R)
);

SearchResponse response = restHighLevelClient.search(searchRequest, DEFAULT);

assertThat(response, isSuccessfulSearchResponse());
assertThat(response, numberOfTotalHitsIsEqualTo(4));
assertThat(
response,
searchHitsContainDocumentsInAnyOrder(
Pair.of(SONG_INDEX_NAME, SONG_ID_1R),
Pair.of(SONG_INDEX_NAME, SONG_ID_6R),
Pair.of(PROHIBITED_SONG_INDEX_NAME, SONG_ID_3R),
Pair.of(LIMITED_USER_INDEX_NAME, SONG_ID_5R)
)
);
assertThat(response, searchHitsContainDocumentsInAnyOrder(documentIdsList));
}
}

Expand All @@ -316,19 +315,18 @@ public void shouldSearchAllIndexOnRemoteClusterWhenStarIsUsedAsIndexName_positiv
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(ADMIN_USER)) {
SearchRequest searchRequest = searchAll(REMOTE_CLUSTER_NAME + ":*");

List<Pair<String, String>> documentIdsList = Arrays.asList(
Pair.of(SONG_INDEX_NAME, SONG_ID_1R),
Pair.of(SONG_INDEX_NAME, SONG_ID_6R),
Pair.of(PROHIBITED_SONG_INDEX_NAME, SONG_ID_3R),
Pair.of(LIMITED_USER_INDEX_NAME, SONG_ID_5R)
);

SearchResponse response = restHighLevelClient.search(searchRequest, DEFAULT);

assertThat(response, isSuccessfulSearchResponse());
assertThat(response, numberOfTotalHitsIsEqualTo(4));
assertThat(
response,
searchHitsContainDocumentsInAnyOrder(
Pair.of(SONG_INDEX_NAME, SONG_ID_1R),
Pair.of(SONG_INDEX_NAME, SONG_ID_6R),
Pair.of(PROHIBITED_SONG_INDEX_NAME, SONG_ID_3R),
Pair.of(LIMITED_USER_INDEX_NAME, SONG_ID_5R)
)
);
assertThat(response, searchHitsContainDocumentsInAnyOrder(documentIdsList));
}
}

Expand Down

0 comments on commit ece5e55

Please sign in to comment.