Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Jan 29, 2025
1 parent 05f56a3 commit 64cc3bc
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,27 +246,21 @@ public void testCreateAnomalyDetector_withFlattenedResultIndex() throws Exceptio

Map<String, Object> searchResults = null;
for (int attempt = 0; attempt < maxRetries; attempt++) {
try {
Response searchAllResponse = TestHelpers
.makeRequest(
client(),
"POST",
TestHelpers.AD_BASE_RESULT_URI + "/_search/" + expectedFlattenedIndex,
ImmutableMap.of(),
new StringEntity("{\"query\":{\"match_all\":{}}}", ContentType.APPLICATION_JSON),
null
);
searchResults = entityAsMap(searchAllResponse);
List<Map<String, Object>> hitsList = (List<Map<String, Object>>) ((Map<String, Object>) searchResults.get("hits"))
.get("hits");

if (hitsList != null && !hitsList.isEmpty()) {
resultsAvailable = true;
break;
}
} catch (Exception e) {
// Log the retry attempt and continue retrying
System.out.println("Attempt " + (attempt + 1) + " failed, retrying...");
Response searchAllResponse = TestHelpers
.makeRequest(
client(),
"POST",
TestHelpers.AD_BASE_RESULT_URI + "/_search/" + expectedFlattenedIndex,
ImmutableMap.of(),
new StringEntity("{\"query\":{\"match_all\":{}}}", ContentType.APPLICATION_JSON),
null
);
searchResults = entityAsMap(searchAllResponse);
List<Map<String, Object>> hitsList = (List<Map<String, Object>>) ((Map<String, Object>) searchResults.get("hits")).get("hits");

if (hitsList != null && !hitsList.isEmpty()) {
resultsAvailable = true;
break;
}
Thread.sleep(retryIntervalMs);
}
Expand Down

0 comments on commit 64cc3bc

Please sign in to comment.