@Test
public void testMoveToDoneAlreadyMovedSucceeds() throws Exception {

  HistoryFileManagerTest historyFileManager = new HistoryFileManagerTest();
  long jobTimestamp = 1535436603000L;
  String job = "job_" + jobTimestamp + "_123456789";
  String intermediateDirectory = "/" + UUID.randomUUID();
  String doneDirectory = "/" + UUID.randomUUID();
  Configuration conf = dfsCluster.getConfiguration(0);
  conf.set(JHAdminConfig.MR_HISTORY_INTERMEDIATE_DONE_DIR,
      intermediateDirectory);
  conf.set(JHAdminConfig.MR_HISTORY_DONE_DIR, doneDirectory);
  Path intermediateHistoryFilePath = new Path(intermediateDirectory + "/"
      + job + ".jhist");
  Path intermediateConfFilePath = new Path(intermediateDirectory + "/"
      + job + "_conf.xml");
  Path doneHistoryFilePath = new Path(doneDirectory + "/"
      + JobHistoryUtils.timestampDirectoryComponent(jobTimestamp) + "/123456/"
      + job + ".jhist");
  Path doneConfFilePath = new Path(doneDirectory + "/"
      + JobHistoryUtils.timestampDirectoryComponent(jobTimestamp)
      + "/123456/" + job + "_conf.xml");
  dfsCluster.getFileSystem().createNewFile(doneHistoryFilePath);
  dfsCluster.getFileSystem().createNewFile(doneConfFilePath);
  historyFileManager.serviceInit(conf);
  JobIndexInfo jobIndexInfo = new JobIndexInfo();
  jobIndexInfo.setJobId(TypeConverter.toYarn(JobID.forName(job)));
  jobIndexInfo.setFinishTime(jobTimestamp);
  HistoryFileInfo info = historyFileManager.getHistoryFileInfo(
      intermediateHistoryFilePath, intermediateConfFilePath, null,
      jobIndexInfo, false);
  info.moveToDone();
  Assert.assertFalse(info.isMovePending());
  Assert.assertEquals(doneHistoryFilePath.toString(),
      info.getHistoryFile().toUri().getPath());
  Assert.assertEquals(doneConfFilePath.toString(),
      info.getConfFile().toUri().getPath());
}