@Test
  public void testMonthlyAggregatedStats() throws Exception {
    String monthValue = "2020-01";
    AggregatedAccountStorageStats currentAggregatedStats = mySqlStore.queryAggregatedAccountStorageStats();
    if (currentAggregatedStats.getStorageStats().size() == 0) {
      AggregatedAccountStorageStats aggregatedAccountStorageStats = new AggregatedAccountStorageStats(
          StorageStatsUtilTest.generateRandomAggregatedAccountStorageStats((short) 0, 10, 10, 10000L, 2, 10));
      mySqlStore.storeAggregatedAccountStorageStats(aggregatedAccountStorageStats);
      currentAggregatedStats = mySqlStore.queryAggregatedAccountStorageStats();
    }

    // fetch the month and it should return empty string
    Assert.assertEquals("", mySqlStore.queryRecordedMonth());
    mySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(monthValue);
    AggregatedAccountStorageStats monthlyAggregatedAccountStorageStats =
        mySqlStore.queryMonthlyAggregatedAccountStorageStats();
    assertEquals(currentAggregatedStats.getStorageStats(), monthlyAggregatedAccountStorageStats.getStorageStats());
    String obtainedMonthValue = mySqlStore.queryRecordedMonth();
    assertTrue(obtainedMonthValue.equals(monthValue));

    // Change the value and store it back to mysql database
    monthValue = "2020-02";
    currentAggregatedStats = new AggregatedAccountStorageStats(
        StorageStatsUtilTest.generateRandomAggregatedAccountStorageStats((short) 0, 10, 10, 10000L, 2, 10));
    mySqlStore.storeAggregatedAccountStorageStats(currentAggregatedStats);
    mySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(monthValue);
    monthlyAggregatedAccountStorageStats = mySqlStore.queryMonthlyAggregatedAccountStorageStats();
    assertEquals(currentAggregatedStats.getStorageStats(), monthlyAggregatedAccountStorageStats.getStorageStats());
    obtainedMonthValue = mySqlStore.queryRecordedMonth();
    assertTrue(obtainedMonthValue.equals(monthValue));

    // Delete the snapshots
    mySqlStore.deleteSnapshotOfAggregatedAccountStats();
    assertEquals(0, mySqlStore.queryMonthlyAggregatedAccountStorageStats().getStorageStats().size());
  }
Test methods to store, delete and fetch monthly aggregated stats
@throws Exception
ambry-mysql/src/integration-test/java/com/github/ambry/accountstats/AccountStatsMySqlStoreIntegrationTest.java