@Test
public void testAppendOption() {

  final DistCpOptions.Builder builder = new DistCpOptions.Builder(
      Collections.singletonList(new Path("hdfs://localhost:8020/source")),
      new Path("hdfs://localhost:8020/target/"))
      .withSyncFolder(true)
      .withAppend(true);
  Assert.assertTrue(builder.build().shouldAppend());
  try {
    // make sure -append is only valid when -update is specified
    new DistCpOptions.Builder(
        Collections.singletonList(new Path("hdfs://localhost:8020/source")),
        new Path("hdfs://localhost:8020/target/"))
        .withAppend(true)
        .build();
    fail("Append should fail if update option is not specified");
  } catch (IllegalArgumentException e) {
    assertExceptionContains(
        "Append is valid only with update options", e);
  }
  try {
    // make sure -append is invalid when skipCrc is specified
    new DistCpOptions.Builder(
        Collections.singletonList(new Path("hdfs://localhost:8020/source")),
        new Path("hdfs://localhost:8020/target/"))
        .withSyncFolder(true)
        .withAppend(true)
        .withCRC(true)
        .build();
    fail("Append should fail if skipCrc option is specified");
  } catch (IllegalArgumentException e) {
    assertExceptionContains(
        "Append is disallowed when skipping CRC", e);
  }
}