@Test
public void testMergeMetrics() {

  ClusterMetricsInfo metrics = new ClusterMetricsInfo();
  ClusterMetricsInfo metricsResponse = new ClusterMetricsInfo();
  long seed = System.currentTimeMillis();
  setUpClusterMetrics(metrics, seed);
  // ensure that we don't reuse the same seed when setting up metricsResponse
  // or it might mask bugs
  seed += 1000000000;
  setUpClusterMetrics(metricsResponse, seed);
  ClusterMetricsInfo metricsClone = createClusterMetricsClone(metrics);
  RouterWebServiceUtil.mergeMetrics(metrics, metricsResponse);
  Assert.assertEquals(
      metricsResponse.getAppsSubmitted() + metricsClone.getAppsSubmitted(),
      metrics.getAppsSubmitted());
  Assert.assertEquals(
      metricsResponse.getAppsCompleted() + metricsClone.getAppsCompleted(),
      metrics.getAppsCompleted());
  Assert.assertEquals(
      metricsResponse.getAppsPending() + metricsClone.getAppsPending(),
      metrics.getAppsPending());
  Assert.assertEquals(
      metricsResponse.getAppsRunning() + metricsClone.getAppsRunning(),
      metrics.getAppsRunning());
  Assert.assertEquals(
      metricsResponse.getAppsFailed() + metricsClone.getAppsFailed(),
      metrics.getAppsFailed());
  Assert.assertEquals(
      metricsResponse.getAppsKilled() + metricsClone.getAppsKilled(),
      metrics.getAppsKilled());
  Assert.assertEquals(
      metricsResponse.getReservedMB() + metricsClone.getReservedMB(),
      metrics.getReservedMB());
  Assert.assertEquals(
      metricsResponse.getAvailableMB() + metricsClone.getAvailableMB(),
      metrics.getAvailableMB());
  Assert.assertEquals(
      metricsResponse.getAllocatedMB() + metricsClone.getAllocatedMB(),
      metrics.getAllocatedMB());
  Assert.assertEquals(
      metricsResponse.getReservedVirtualCores()
          + metricsClone.getReservedVirtualCores(),
      metrics.getReservedVirtualCores());
  Assert.assertEquals(
      metricsResponse.getAvailableVirtualCores()
          + metricsClone.getAvailableVirtualCores(),
      metrics.getAvailableVirtualCores());
  Assert.assertEquals(
      metricsResponse.getAllocatedVirtualCores()
          + metricsClone.getAllocatedVirtualCores(),
      metrics.getAllocatedVirtualCores());
  Assert.assertEquals(
      metricsResponse.getContainersAllocated()
          + metricsClone.getContainersAllocated(),
      metrics.getContainersAllocated());
  Assert.assertEquals(
      metricsResponse.getReservedContainers()
          + metricsClone.getReservedContainers(),
      metrics.getReservedContainers());
  Assert.assertEquals(
      metricsResponse.getPendingContainers()
          + metricsClone.getPendingContainers(),
      metrics.getPendingContainers());
  Assert.assertEquals(
      metricsResponse.getTotalMB() + metricsClone.getTotalMB(),
      metrics.getTotalMB());
  Assert.assertEquals(
      metricsResponse.getTotalVirtualCores()
          + metricsClone.getTotalVirtualCores(),
      metrics.getTotalVirtualCores());
  Assert.assertEquals(
      metricsResponse.getTotalNodes() + metricsClone.getTotalNodes(),
      metrics.getTotalNodes());
  Assert.assertEquals(
      metricsResponse.getLostNodes() + metricsClone.getLostNodes(),
      metrics.getLostNodes());
  Assert.assertEquals(
      metricsResponse.getUnhealthyNodes() + metricsClone.getUnhealthyNodes(),
      metrics.getUnhealthyNodes());
  Assert.assertEquals(
      metricsResponse.getDecommissioningNodes()
          + metricsClone.getDecommissioningNodes(),
      metrics.getDecommissioningNodes());
  Assert.assertEquals(
      metricsResponse.getDecommissionedNodes()
          + metricsClone.getDecommissionedNodes(),
      metrics.getDecommissionedNodes());
  Assert.assertEquals(
      metricsResponse.getRebootedNodes() + metricsClone.getRebootedNodes(),
      metrics.getRebootedNodes());
  Assert.assertEquals(
      metricsResponse.getActiveNodes() + metricsClone.getActiveNodes(),
      metrics.getActiveNodes());
  Assert.assertEquals(
      metricsResponse.getShutdownNodes() + metricsClone.getShutdownNodes(),
      metrics.getShutdownNodes());
}