MetricCalculator implements Runnable { @Timed("sla_stats_computation") @Override public void run() { FluentIterable<IScheduledTask> tasks = FluentIterable.from(Storage.Util.fetchTasks(storage, Query.unscoped())); List<IScheduledTask> prodTasks = tasks.filter(Predicates.compose( Predicates.and(ITaskConfig::isProduction, IS_SERVICE), Tasks::getConfig)).toList(); List<IScheduledTask> nonProdTasks = tasks.filter(Predicates.compose( Predicates.and(Predicates.not(ITaskConfig::isProduction), IS_SERVICE), Tasks::getConfig)).toList(); long nowMs = clock.nowMillis(); Range<Long> timeRange = Range.closedOpen(nowMs - settings.refreshRateMs, nowMs); runAlgorithms(prodTasks, settings.prodMetrics, timeRange, NAME_QUALIFIER_PROD); runAlgorithms(nonProdTasks, settings.nonProdMetrics, timeRange, NAME_QUALIFIER_NON_PROD); } @Inject  MetricCalculator(
      Storage storage,
      Clock clock,
      MetricCalculatorSettings settings,
      final StatsProvider statsProvider); @Timed("sla_stats_computation") @Override void run();  }
@Test public void testRun() { FakeClock clock = new FakeClock(); StatsProvider statsProvider = createMock(StatsProvider.class); StatsProvider untracked = createMock(StatsProvider.class); MetricCalculatorSettings settings = new MetricCalculatorSettings( 10000, ImmutableSet.of(JOB_UPTIMES, MEDIANS, PLATFORM_UPTIME), ImmutableSet.of(JOB_UPTIMES, MEDIANS, PLATFORM_UPTIME)); StorageTestUtil storageUtil = new StorageTestUtil(this); MetricCalculator calculator = new MetricCalculator( storageUtil.storage, clock, settings, statsProvider); expect(statsProvider.untracked()).andReturn(untracked).anyTimes(); Capture<String> names = new Capture<>(CaptureType.ALL); expect(untracked.makeGauge(EasyMock.capture(names), EasyMock.anyObject())) .andReturn(EasyMock.anyObject()) .anyTimes(); IScheduledTask task1 = makeTask(ImmutableMap.of(clock.nowMillis() - 1000, PENDING), 0); IScheduledTask task2 = makeTask(ImmutableMap.of(clock.nowMillis() - 2000, PENDING), 1); IScheduledTask task3 = makeTask(ImmutableMap.of(clock.nowMillis() - 3000, PENDING), 2); IScheduledTask task4 = makeTask(ImmutableMap.of(clock.nowMillis() - 4000, PENDING), 3, false); clock.advance(Amount.of(10L, Time.SECONDS)); storageUtil.expectTaskFetch(Query.unscoped(), task1, task2, task3, task4); storageUtil.expectOperations(); control.replay(); calculator.run(); Set<String> metricNames = generateMetricNames( ImmutableSet.of(task1, task2, task3, task4), ImmutableSet.of(PROD_METRICS, NON_PROD_METRICS)); assertEquals(metricNames, ImmutableSet.copyOf(names.getValues())); }