@Test
  public void testNullMetrics() {
    Configuration conf = new Configuration(false);
    conf.set(TonyConfigurationKeys.getResourceKey(Constants.WORKER_JOB_NAME, Constants.MEMORY), "4g");
    conf.setInt(TonyConfigurationKeys.getInstancesKey(Constants.WORKER_JOB_NAME), 2);
    conf.set(TonyConfigurationKeys.getResourceKey(Constants.PS_JOB_NAME, Constants.MEMORY), "4g");
    conf.setInt(TonyConfigurationKeys.getInstancesKey(Constants.PS_JOB_NAME), 1);

    List<Event> events = new ArrayList<>();
    events.add(new Event(EventType.TASK_STARTED, new TaskStarted(Constants.WORKER_JOB_NAME, 0, null),0L));
    events.add(new Event(EventType.TASK_STARTED, new TaskStarted(Constants.WORKER_JOB_NAME, 1, null),0L));
    events.add(new Event(EventType.TASK_STARTED, new TaskStarted(Constants.PS_JOB_NAME, 0, null),0L));
    events.add(new Event(EventType.TASK_FINISHED,
        new TaskFinished(Constants.WORKER_JOB_NAME, 0, TaskStatus.SUCCEEDED.toString(), Collections.emptyList()),
        10L * Statistics.SECOND_IN_MS));
    events.add(new Event(EventType.TASK_FINISHED,
        new TaskFinished(Constants.WORKER_JOB_NAME, 1, TaskStatus.SUCCEEDED.toString(), Collections.emptyList()),
        20L * Statistics.SECOND_IN_MS));
    events.add(new Event(EventType.TASK_FINISHED,
        new TaskFinished(Constants.PS_JOB_NAME, 0, TaskStatus.SUCCEEDED.toString(), Collections.emptyList()),
        20L * Statistics.SECOND_IN_MS));

    long expectedResourcesUsed = 10 * 4 * 1024 + 20 * 4 * 1024 + 20 * 4 * 1024;
    long expectedResourcesWasted = 0;

    ApplicationType appType = new ApplicationType(Constants.APP_TYPE);
    TonyApplicationData data = new TonyApplicationData("application_123_456", appType, conf, events);
    TonyMetricsAggregator metricsAggregator = new TonyMetricsAggregator(null);
    metricsAggregator.aggregate(data);
    HadoopAggregatedData result = metricsAggregator.getResult();
    Assert.assertEquals(expectedResourcesUsed, result.getResourceUsed());
    Assert.assertEquals(expectedResourcesWasted, result.getResourceWasted());
  }
Verifies that wasted resources is 0 when there are no metrics.
test/com/linkedin/drelephant/tony/TonyMetricsAggregatorTest.java