@Test
  public void testBackupFileManager() throws Exception {
    Path tempDir = Files.createTempDirectory("MySqlStorageUsageRefresherTest");
    Path localBackupFilePath = tempDir.resolve("backupfilemanager");
    MySqlStorageUsageRefresher.BackupFileManager manager =
        new MySqlStorageUsageRefresher.BackupFileManager(localBackupFilePath.toString());

    // It shouldn't have any backup file now.
    assertTrue(manager.getBackupFiles().isEmpty());
    assertNull(manager.getBackupFileContent("2020-01"));

    // persist file
    Map<String, Map<String, Long>> containerStorageUsages = TestUtils.makeStorageMap(10, 10, 100000, 1000);
    manager.persistentBackupFile("2020-01", containerStorageUsages);
    assertEquals(manager.getBackupFiles().size(), 1);
    // persist same file again
    manager.persistentBackupFile("2020-01", containerStorageUsages);
    assertEquals(manager.getBackupFiles().size(), 1);
    try {
      manager.persistentBackupFile("badfilename", containerStorageUsages);
      fail("should fail due to bad filename");
    } catch (IllegalArgumentException e) {
    }
    try {
      manager.persistentBackupFile("2020-02", null);
      fail("should fail due to bad usage");
    } catch (IllegalArgumentException e) {
    }

    manager.persistentBackupFile("2020-02", containerStorageUsages);

    // Now we have two backup files
    // Create a temp file
    Path tmpFilePath =
        localBackupFilePath.resolve("2020-03" + MySqlStorageUsageRefresher.BackupFileManager.TEMP_FILE_SUFFIX);
    Files.createFile(tmpFilePath);
    manager = new MySqlStorageUsageRefresher.BackupFileManager(localBackupFilePath.toString());
    assertEquals(manager.getBackupFiles().size(), 2);
    assertEquals(containerStorageUsages, manager.getBackupFileContent("2020-01"));
    assertFalse(Files.exists(tmpFilePath));
  }
Test backup file manager.
@throws Exception
ambry-quota/src/integration-test/java/com/github/ambry/quota/storage/MySqlStorageUsageRefresherTest.java