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)

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

Signed-off-by: Gao Binlong <gbinlong@amazon.com>

* Change test method name

Signed-off-by: Gao Binlong <gbinlong@amazon.com>

---------

Signed-off-by: Gao Binlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed May 16, 2024
1 parent f217270 commit f30e0e0
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 f30e0e0

Please sign in to comment.