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