@Test
  public void testCleanup_NotEnoughBackupFilesWithVersion() throws IOException {
    final int startVersion = 1;
    final int endVersion = startVersion + maxBackupFile / 2;
    final long baseModifiedTime = System.currentTimeMillis() / 1000 - 100;
    final long interval = 2;
    final int backupFileNoVersionCount = maxBackupFile;
    // Create backup files without version number
    createBackupFilesWithoutVersion(accountBackupDir, backupFileNoVersionCount, baseModifiedTime, interval, false);
    createBackupFilesWithoutVersion(accountBackupDir, backupFileNoVersionCount, baseModifiedTime, interval, true);
    // Create temporary backup files with version number
    createBackupFilesWithVersion(accountBackupDir, startVersion, endVersion,
        baseModifiedTime + 2 * backupFileNoVersionCount * interval, interval, true);
    // Create backup files with version number
    String[] filenames = createBackupFilesWithVersion(accountBackupDir, startVersion, endVersion,
        baseModifiedTime + 2 * backupFileNoVersionCount * interval, interval, false);
    saveAccountsToFile(Collections.singleton(refAccount), accountBackupDir.resolve(filenames[filenames.length - 1]));

    BackupFileManager backup =
        new BackupFileManager(accountServiceMetrics, config.backupDir, config.maxBackupFileCount);
    assertEquals("Number of backup files mismatch", backup.size(), maxBackupFile);

    File[] remainingFiles = accountBackupDir.toFile().listFiles();
    assertEquals("Number of backup files in storage mismatch", remainingFiles.length, maxBackupFile);
    int versionFileCount = 0;
    int nonVersionFileCount = 0;
    for (File file : remainingFiles) {
      if (BackupFileManager.versionFilenamePattern.matcher(file.getName()).find()) {
        versionFileCount++;
      } else {
        nonVersionFileCount++;
      }
    }
    assertEquals("Number of backup files with version mismatch", versionFileCount, endVersion - startVersion + 1);
    assertEquals("Number of backup files without version ", nonVersionFileCount,
        maxBackupFile - (endVersion - startVersion + 1));
  }
Test if BackupFileManager correctly cleans up the backup files, when there are less than {@link #maxBackupFile} backup
files with version number.
@throws IOException if I/O error occurs
ambry-account/src/test/java/com/github/ambry/account/BackupFileManagerTest.java