ResourceMeterMaintainer extends ControllerMaintainer { @Override protected boolean maintain() { try { collectResourceSnapshots(); return true; } catch (Exception e) { log.log(Level.WARNING, "Failed to collect resource snapshots. Retrying in " + interval() + ". Error: " + Exceptions.toMessageString(e)); } return false; } @SuppressWarnings("WeakerAccess")  ResourceMeterMaintainer(Controller controller,
                                   Duration interval,
                                   Metric metric,
                                   MeteringClient meteringClient);   }
@Test public void testMaintainer() { setUpZones(); ResourceMeterMaintainer resourceMeterMaintainer = new ResourceMeterMaintainer(tester.controller(), Duration.ofMinutes(5), metrics, snapshotConsumer); resourceMeterMaintainer.maintain(); Collection<ResourceSnapshot> consumedResources = snapshotConsumer.consumedResources(); assertEquals(4, consumedResources.size()); ResourceSnapshot app1 = consumedResources.stream().filter(snapshot -> snapshot.getApplicationId().equals(ApplicationId.from("tenant1", "app1", "default"))).findFirst().orElseThrow(); ResourceSnapshot app2 = consumedResources.stream().filter(snapshot -> snapshot.getApplicationId().equals(ApplicationId.from("tenant2", "app2", "default"))).findFirst().orElseThrow(); assertEquals(24, app1.getCpuCores(), Double.MIN_VALUE); assertEquals(24, app1.getMemoryGb(), Double.MIN_VALUE); assertEquals(500, app1.getDiskGb(), Double.MIN_VALUE); assertEquals(40, app2.getCpuCores(), Double.MIN_VALUE); assertEquals(24, app2.getMemoryGb(), Double.MIN_VALUE); assertEquals(500, app2.getDiskGb(), Double.MIN_VALUE); assertEquals(tester.clock().millis()/1000, metrics.getMetric("metering_last_reported")); assertEquals(2224.0d, (Double) metrics.getMetric("metering_total_reported"), Double.MIN_VALUE); }