@@ -130,10 +130,12 @@ public void testUnrecognizedIndexMetricDidYouMean() {
130
130
);
131
131
}
132
132
133
- public void testIndexMetricsRequestWithoutIndicesMetric () throws IOException {
133
+ public void testIndexMetricsRequestWithoutIndicesAndCachesMetrics () throws IOException {
134
134
final HashMap <String , String > params = new HashMap <>();
135
135
final Set <String > metrics = new HashSet <>(RestNodesStatsAction .METRICS .keySet ());
136
136
metrics .remove ("indices" );
137
+ // caches stats is handled separately
138
+ metrics .remove ("caches" );
137
139
params .put ("metric" , randomSubsetOf (1 , metrics ).get (0 ));
138
140
final String indexMetric = randomSubsetOf (1 , RestNodesStatsAction .FLAGS .keySet ()).get (0 );
139
141
params .put ("index_metric" , indexMetric );
@@ -150,6 +152,19 @@ public void testIndexMetricsRequestWithoutIndicesMetric() throws IOException {
150
152
);
151
153
}
152
154
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
+
153
168
public void testIndexMetricsRequestOnAllRequest () throws IOException {
154
169
final HashMap <String , String > params = new HashMap <>();
155
170
params .put ("metric" , "_all" );
0 commit comments