@@ -260,4 +260,64 @@ public void testDoCollect() throws Exception {
260
260
verify (clusterAdminClient ).prepareClusterStats ();
261
261
verify (client ).execute (same (XPackUsageAction .INSTANCE ), any (XPackUsageRequest .class ));
262
262
}
263
+
264
+ public void testDoCollectNoLicense () throws Exception {
265
+ final TimeValue timeout ;
266
+ {
267
+ final String clusterName = randomAlphaOfLength (10 );
268
+ whenClusterStateWithName (clusterName );
269
+ final String clusterUUID = UUID .randomUUID ().toString ();
270
+ whenClusterStateWithUUID (clusterUUID );
271
+ timeout = TimeValue .timeValueSeconds (randomIntBetween (1 , 120 ));
272
+ withCollectionTimeout (ClusterStatsCollector .CLUSTER_STATS_TIMEOUT , timeout );
273
+ }
274
+ final IndexNameExpressionResolver indexNameExpressionResolver ;
275
+ {
276
+ indexNameExpressionResolver = mock (IndexNameExpressionResolver .class );
277
+ when (indexNameExpressionResolver .concreteIndices (clusterState , IndicesOptions .lenientExpandOpen (), "apm-*" ))
278
+ .thenReturn (new Index [0 ]);
279
+ }
280
+
281
+ final Client client = mock (Client .class );
282
+ {
283
+ final ClusterStatsResponse mockClusterStatsResponse = mock (ClusterStatsResponse .class );
284
+ final ClusterHealthStatus clusterStatus = randomFrom (ClusterHealthStatus .values ());
285
+ when (mockClusterStatsResponse .getStatus ()).thenReturn (clusterStatus );
286
+ when (mockClusterStatsResponse .getNodesStats ()).thenReturn (mock (ClusterStatsNodes .class ));
287
+
288
+ final ClusterStatsIndices mockClusterStatsIndices = mock (ClusterStatsIndices .class );
289
+
290
+ when (mockClusterStatsIndices .getIndexCount ()).thenReturn (0 );
291
+ when (mockClusterStatsResponse .getIndicesStats ()).thenReturn (mockClusterStatsIndices );
292
+
293
+ final ClusterStatsRequestBuilder clusterStatsRequestBuilder = mock (ClusterStatsRequestBuilder .class );
294
+ when (clusterStatsRequestBuilder .get (eq (timeout ))).thenReturn (mockClusterStatsResponse );
295
+
296
+ final ClusterAdminClient clusterAdminClient = mock (ClusterAdminClient .class );
297
+ when (clusterAdminClient .prepareClusterStats ()).thenReturn (clusterStatsRequestBuilder );
298
+
299
+ final AdminClient adminClient = mock (AdminClient .class );
300
+ when (adminClient .cluster ()).thenReturn (clusterAdminClient );
301
+ when (client .admin ()).thenReturn (adminClient );
302
+
303
+ final XPackUsageResponse xPackUsageResponse = new XPackUsageResponse (
304
+ singletonList (new MonitoringFeatureSetUsage (true , true , false , null )));
305
+ @ SuppressWarnings ("unchecked" )
306
+ final ActionFuture <XPackUsageResponse > xPackUsageFuture = (ActionFuture <XPackUsageResponse >) mock (ActionFuture .class );
307
+ when (client .execute (same (XPackUsageAction .INSTANCE ), any (XPackUsageRequest .class ))).thenReturn (xPackUsageFuture );
308
+ when (xPackUsageFuture .actionGet ()).thenReturn (xPackUsageResponse );
309
+ }
310
+
311
+ final long interval = randomNonNegativeLong ();
312
+ final Settings .Builder settings = Settings .builder ();
313
+ final MonitoringDoc .Node node = MonitoringTestUtils .randomMonitoringNode (random ());
314
+
315
+ final ClusterStatsCollector collector =
316
+ new ClusterStatsCollector (settings .build (), clusterService , licenseState ,
317
+ client , licenseService , indexNameExpressionResolver );
318
+ final Collection <MonitoringDoc > results = collector .doCollect (node , interval , clusterState );
319
+ assertEquals (1 , results .size ());
320
+ final ClusterStatsMonitoringDoc doc = (ClusterStatsMonitoringDoc ) results .iterator ().next ();
321
+ assertThat (doc .getLicense (), nullValue ());
322
+ }
263
323
}
0 commit comments