private void testBackupDeleteWithFailuresAfter(int expected, Failure... failures)
    throws Exception {
    LOG.info("test repair backup delete on a single table with data and failures " + failures[0]);
    List<TableName> tableList = Lists.newArrayList(table1);
    String backupId = fullTableBackup(tableList);
    assertTrue(checkSucceeded(backupId));
    LOG.info("backup complete");
    String[] backupIds = new String[] { backupId };
    BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection());
    BackupInfo info = table.readBackupInfo(backupId);
    Path path = new Path(info.getBackupRootDir(), backupId);
    FileSystem fs = FileSystem.get(path.toUri(), conf1);
    assertTrue(fs.exists(path));

    Connection conn = TEST_UTIL.getConnection();
    Admin admin = conn.getAdmin();
    MasterSnapshotObserver observer = getMasterSnapshotObserver();

    observer.setFailures(failures);
    try {
      getBackupAdmin().deleteBackups(backupIds);
    } catch (IOException e) {
      if (expected != 1) {
        assertTrue(false);
      }
    }

    // Verify that history length == expected after delete failure
    assertTrue(table.getBackupHistory().size() == expected);

    String[] ids = table.getListOfBackupIdsFromDeleteOperation();

    // Verify that we still have delete record in backup system table
    if (expected == 1) {
      assertTrue(ids.length == 1);
      assertTrue(ids[0].equals(backupId));
    } else {
      assertNull(ids);
    }

    // Now run repair command to repair "failed" delete operation
    String[] args = new String[] { "repair" };

    observer.setFailures(Failure.NO_FAILURES);

    // Run repair
    int ret = ToolRunner.run(conf1, new BackupDriver(), args);
    assertTrue(ret == 0);
    // Verify that history length == 0
    assertTrue(table.getBackupHistory().size() == 0);
    ids = table.getListOfBackupIdsFromDeleteOperation();

    // Verify that we do not have delete record in backup system table
    assertNull(ids);

    table.close();
    admin.close();
  }
Setup Cluster with appropriate configurations before running tests.
@throws Exception if starting the mini cluster or setting up the tables fails
hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDeleteWithFailures.java