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 (opensearch-project#13658)

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

Signed-off-by: Gao Binlong <[email protected]>

* Change test method name

Signed-off-by: Gao Binlong <[email protected]>

---------

Signed-off-by: Gao Binlong <[email protected]>
  • Loading branch information
gaobinlong authored and deshsidd committed May 17, 2024
1 parent b65f5e4 commit efc685d
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 efc685d

Please sign in to comment.