Skip to content

Commit f30e0e0

Browse files
authored
Fix org.opensearch.rest.action.admin.cluster.RestNodesStatsActionTests.testIndexMetricsRequestWithoutIndicesMetric is flaky (opensearch-project#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>
1 parent f217270 commit f30e0e0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

server/src/test/java/org/opensearch/rest/action/admin/cluster/RestNodesStatsActionTests.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ public void testUnrecognizedIndexMetricDidYouMean() {
130130
);
131131
}
132132

133-
public void testIndexMetricsRequestWithoutIndicesMetric() throws IOException {
133+
public void testIndexMetricsRequestWithoutIndicesAndCachesMetrics() throws IOException {
134134
final HashMap<String, String> params = new HashMap<>();
135135
final Set<String> metrics = new HashSet<>(RestNodesStatsAction.METRICS.keySet());
136136
metrics.remove("indices");
137+
// caches stats is handled separately
138+
metrics.remove("caches");
137139
params.put("metric", randomSubsetOf(1, metrics).get(0));
138140
final String indexMetric = randomSubsetOf(1, RestNodesStatsAction.FLAGS.keySet()).get(0);
139141
params.put("index_metric", indexMetric);
@@ -150,6 +152,19 @@ public void testIndexMetricsRequestWithoutIndicesMetric() throws IOException {
150152
);
151153
}
152154

155+
public void testCacheStatsRequestWithInvalidCacheType() throws IOException {
156+
final HashMap<String, String> params = new HashMap<>();
157+
params.put("metric", "caches");
158+
final String cacheType = randomAlphaOfLength(64);
159+
params.put("index_metric", cacheType);
160+
final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_nodes/stats").withParams(params).build();
161+
final IllegalArgumentException e = expectThrows(
162+
IllegalArgumentException.class,
163+
() -> action.prepareRequest(request, mock(NodeClient.class))
164+
);
165+
assertThat(e, hasToString(containsString("request [/_nodes/stats] contains unrecognized cache type: [" + cacheType + "]")));
166+
}
167+
153168
public void testIndexMetricsRequestOnAllRequest() throws IOException {
154169
final HashMap<String, String> params = new HashMap<>();
155170
params.put("metric", "_all");

0 commit comments

Comments
 (0)