ResourceCounter { public List<GlobalMetric> computeConsumptionTotals() throws StorageException { List<GlobalMetric> counts = FluentIterable.from(Arrays.asList(MetricType.values())) .transform(TO_GLOBAL_METRIC) .toList(); for (ITaskConfig task : getTasks(Query.unscoped().active())) { for (GlobalMetric count : counts) { count.accumulate(task); } } return counts; } @Inject  ResourceCounter(Storage storage); List<GlobalMetric> computeConsumptionTotals(); Metric computeQuotaAllocationTotals(); Map<K, Metric> computeAggregates(
      Query.Builder query,
      Predicate<ITaskConfig> filter,
      Function<ITaskConfig, K> keyFunction);  }
@Test public void testComputeConsumptionTotals() { insertTasks( task("bob", "jobA", "a", 1, GB, GB, PRODUCTION, RUNNING, NOT_DEDICATED), task("bob", "jobB", "b", 1, GB, GB, PRODUCTION, RUNNING, NOT_DEDICATED), task("tim", "jobC", "c", 1, GB, GB, PRODUCTION, PENDING, NOT_DEDICATED), task("tim", "jobD", "d", 1, GB, GB, PRODUCTION, KILLING, NOT_DEDICATED), task("bob", "jobE", "e", 1, GB, GB, NONPRODUCTION, ASSIGNED, NOT_DEDICATED), task("tom", "jobF", "f", 1, GB, GB, NONPRODUCTION, RUNNING, NOT_DEDICATED), task("tom", "jobG", "g", 1, GB, GB, NONPRODUCTION, RESTARTING, Optional.of("database")), task("lil", "jobH", "h", 1, GB, GB, PRODUCTION, RUNNING, Optional.of("queue")), task("lil", "jobI", "i", 1, GB, GB, PRODUCTION, FINISHED, NOT_DEDICATED) ); Set<GlobalMetric> expected = ImmutableSet.of( new GlobalMetric(TOTAL_CONSUMED, 8, 8 * GB, 8 * GB), new GlobalMetric(DEDICATED_CONSUMED, 2, 2 * GB, 2 * GB), new GlobalMetric(QUOTA_CONSUMED, 4, 4 * GB, 4 * GB), new GlobalMetric(FREE_POOL_CONSUMED, 2, 2 * GB, 2 * GB) ); assertEquals(expected, ImmutableSet.copyOf(resourceCounter.computeConsumptionTotals())); }