@VisibleForTesting
  File untarAndMoveSegment(String segmentName, File segmentTarFile, File tempRootDir)
      throws IOException {
    return moveSegment(segmentName, untarSegment(segmentName, segmentTarFile, tempRootDir));
  }
@Test
  public void testUntarAndMoveSegment()
      throws IOException {
    BaseTableDataManager tableDataManager = createTableManager();
    File tempRootDir = tableDataManager.getTmpSegmentDataDir("test-untar-move");

    // All input and intermediate files are put in the tempRootDir.
    File tempTar = new File(tempRootDir, SEGMENT_NAME + TarCompressionUtils.TAR_GZ_FILE_EXTENSION);
    File tempInputDir = new File(tempRootDir, "input");
    FileUtils.write(new File(tempInputDir, "tmp.txt"), "this is in segment dir");
    TarCompressionUtils.createCompressedTarFile(tempInputDir, tempTar);
    FileUtils.deleteQuietly(tempInputDir);

    // The destination is the segment directory at the same level of tempRootDir.
    File untarredFile = tableDataManager.untarAndMoveSegment(SEGMENT_NAME, tempTar, tempRootDir);
    assertEquals(untarredFile, tableDataManager.getSegmentDataDir(SEGMENT_NAME));
    assertEquals(FileUtils.readFileToString(new File(untarredFile, "tmp.txt")), "this is in segment dir");

    try {
      tableDataManager.untarAndMoveSegment(SEGMENT_NAME, new File(tempRootDir, "unknown.txt"), TEMP_DIR);
      fail();
    } catch (Exception e) {
      // expected.
    }
  }