@Test
  public void testRefresherUpdateAndListener() throws Exception {
    Map<Short, Map<Short, ContainerStorageStats>> containerStorageUsages =
        StorageStatsUtilTest.generateRandomAggregatedAccountStorageStats((short) 0, 10, 10, 10000L, 2, 10);
    AggregatedAccountStorageStats aggregatedAccountStorageStats =
        new AggregatedAccountStorageStats(containerStorageUsages);
    accountStatsMySqlStore.storeAggregatedAccountStorageStats(aggregatedAccountStorageStats);
    accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(
        MySqlStorageUsageRefresher.getCurrentMonth());

    // Set polling interval to 2 seconds
    properties.setProperty(StorageQuotaConfig.REFRESHER_POLLING_INTERVAL_MS, "2000");
    StorageQuotaConfig storageQuotaConfig = new StorageQuotaConfig(new VerifiableProperties(properties));
    AccountStatsMySqlStore newAccountStatsMySqlStore = createAccountStatsMySqlStore();
    MySqlStorageUsageRefresher refresher =
        new MySqlStorageUsageRefresher(newAccountStatsMySqlStore, scheduler, storageQuotaConfig, metrics);

    AtomicReference<Map<String, Map<String, Long>>> containerUsageRef = new AtomicReference<>(null);
    AtomicReference<CountDownLatch> latchRef = new AtomicReference<>(null);
    refresher.registerListener(containerStorageUsage -> {
      containerUsageRef.set(containerStorageUsage);
      latchRef.get().countDown();
    });
    // Keep storage usage unchanged, listener should get an all-zero map
    accountStatsMySqlStore.storeAggregatedAccountStorageStats(aggregatedAccountStorageStats);
    CountDownLatch latch1 = new CountDownLatch(1);
    latchRef.set(latch1);
    latch1.await(10, TimeUnit.SECONDS);
    assertContainerUsageMapAllZero(containerUsageRef.get());

    // Change some usage, listener should get
    containerStorageUsages.get((short) 1)
        .compute((short) 1,
            (k, v) -> new ContainerStorageStats.Builder(v).logicalStorageUsage(v.getLogicalStorageUsage() + 1L)
                .build());
    accountStatsMySqlStore.storeAggregatedAccountStorageStats(
        new AggregatedAccountStorageStats(containerStorageUsages));
    CountDownLatch latch2 = new CountDownLatch(1);
    latchRef.set(latch2);
    latch2.await(10, TimeUnit.SECONDS);
    assertEquals((long) containerUsageRef.get().get("1").get("1"), 1L);
    Map<String, Map<String, Long>> clone = cloneMap(containerUsageRef.get());
    clone.get("1").put("1", 0L);
    assertContainerUsageMapAllZero(clone);
  }
Test when updating container total usage.
@throws Exception
ambry-quota/src/integration-test/java/com/github/ambry/quota/storage/MySqlStorageUsageRefresherTest.java