@Test
  public void testAggregateHostAccountStorageStats() throws Exception {
    int nodeCount = 3;
    // Partition id to account id to container id to container storage stats.
    Map<Long, Map<Short, Map<Short, ContainerStorageStats>>> storageStatsMap = new HashMap<>();
    // Create storage stats for 3 partitions, each has 3, 4 and 5 accounts.
    for (int i = 0; i < 3; i++) {
      storageStatsMap.put((long) i,
          StorageStatsUtilTest.generateRandomAggregatedAccountStorageStats((short) 0, i + 3, 3, 10000L, 2, 10));
    }
    StatsHeader header = new StatsHeader(StatsHeader.StatsDescription.STORED_DATA_SIZE, DEFAULT_TIMESTAMP, 3, 3,
        Collections.emptyList());
    HostAccountStorageStatsWrapper nodeStats =
        new HostAccountStorageStatsWrapper(header, new HostAccountStorageStats(storageStatsMap));

    header = new StatsHeader(StatsHeader.StatsDescription.STORED_DATA_SIZE, DEFAULT_TIMESTAMP, 0, 0,
        Collections.emptyList());
    HostAccountStorageStatsWrapper emptyStats =
        new HostAccountStorageStatsWrapper(header, new HostAccountStorageStats());

    Map<String, HostAccountStorageStatsWrapper> instanceToStatsMap = new HashMap<>();

    // For each node, use the same HostAccountStorageStats data.
    // So the combined raw data would be three times of the aggregated data (we have 3 nodes).
    for (int i = 0; i < nodeCount; i++) {
      instanceToStatsMap.put("Instance_" + i, new HostAccountStorageStatsWrapper(new StatsHeader(nodeStats.getHeader()),
          new HostAccountStorageStats(nodeStats.getStats())));
    }
    instanceToStatsMap.put("Instance_" + nodeCount, emptyStats);

    Map<Short, Map<Short, ContainerStorageStats>> expectedAggregatedStorageStatsMap =
        clusterAggregator.aggregateHostAccountStorageStats(storageStatsMap);
    ClusterMapConfig clusterMapConfig = getClusterMapConfig();
    InmemoryAccountStatsStore accountStatsStore = new InmemoryAccountStatsStore(
        "unused_clustername", "unused_hostname", instanceToStatsMap, null);
    Pair<AggregatedAccountStorageStats, AggregatedAccountStorageStats> aggregatedRawAndValidStats =
        clusterAggregator.aggregateHostAccountStorageStatsWrappers(new AccountStorageStatsIterator(
            instanceToStatsMap.keySet().stream().collect(Collectors.toList()), accountStatsStore, clusterMapConfig));
    Assert.assertEquals(expectedAggregatedStorageStatsMap, aggregatedRawAndValidStats.getSecond().getStorageStats());
    assertAggregatedRawStatsForAccountStorageStats(aggregatedRawAndValidStats.getFirst().getStorageStats(),
        expectedAggregatedStorageStatsMap, nodeCount);
  }
Test basic functionality of {@link MySqlClusterAggregator#aggregateHostAccountStorageStats}.
@throws Exception
ambry-clustermap/src/test/java/com/github/ambry/clustermap/MySqlClusterAggregatorTest.java