Skip to content

Commit

Permalink
Fix org.opensearch.rest.action.admin.cluster.RestNodesStatsActionTest…
Browse files Browse the repository at this point in the history
…s.testIndexMetricsRequestWithoutIndicesMetric is flaky (#13658) (#13716)

* Fix org.opensearch.rest.action.admin.cluster.RestNodesStatsActionTests.testIndexMetricsRequestWithoutIndicesMetric is flaky



* Change test method name



---------


(cherry picked from commit f30e0e0)

Signed-off-by: Gao Binlong <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 90265f3 commit ef6acea
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ public void testUnrecognizedIndexMetricDidYouMean() {
);
}

public void testIndexMetricsRequestWithoutIndicesMetric() throws IOException {
public void testIndexMetricsRequestWithoutIndicesAndCachesMetrics() throws IOException {
final HashMap<String, String> params = new HashMap<>();
final Set<String> metrics = new HashSet<>(RestNodesStatsAction.METRICS.keySet());
metrics.remove("indices");
// caches stats is handled separately
metrics.remove("caches");
params.put("metric", randomSubsetOf(1, metrics).get(0));
final String indexMetric = randomSubsetOf(1, RestNodesStatsAction.FLAGS.keySet()).get(0);
params.put("index_metric", indexMetric);
Expand All @@ -150,6 +152,19 @@ public void testIndexMetricsRequestWithoutIndicesMetric() throws IOException {
);
}

public void testCacheStatsRequestWithInvalidCacheType() throws IOException {
final HashMap<String, String> params = new HashMap<>();
params.put("metric", "caches");
final String cacheType = randomAlphaOfLength(64);
params.put("index_metric", cacheType);
final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_nodes/stats").withParams(params).build();
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> action.prepareRequest(request, mock(NodeClient.class))
);
assertThat(e, hasToString(containsString("request [/_nodes/stats] contains unrecognized cache type: [" + cacheType + "]")));
}

public void testIndexMetricsRequestOnAllRequest() throws IOException {
final HashMap<String, String> params = new HashMap<>();
params.put("metric", "_all");
Expand Down

0 comments on commit ef6acea

Please sign in to comment.