OptionsParser { public static DistCpOptions parse(String[] args) throws IllegalArgumentException { CommandLineParser parser = new CustomParser(); CommandLine command; try { command = parser.parse(cliOptions, args, true); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parse arguments. " + Arrays.toString(args), e); } DistCpOptions.Builder builder = parseSourceAndTargetPaths(command); builder .withAtomicCommit( command.hasOption(DistCpOptionSwitch.ATOMIC_COMMIT.getSwitch())) .withSyncFolder( command.hasOption(DistCpOptionSwitch.SYNC_FOLDERS.getSwitch())) .withDeleteMissing( command.hasOption(DistCpOptionSwitch.DELETE_MISSING.getSwitch())) .withIgnoreFailures( command.hasOption(DistCpOptionSwitch.IGNORE_FAILURES.getSwitch())) .withOverwrite( command.hasOption(DistCpOptionSwitch.OVERWRITE.getSwitch())) .withAppend( command.hasOption(DistCpOptionSwitch.APPEND.getSwitch())) .withCRC( command.hasOption(DistCpOptionSwitch.SKIP_CRC.getSwitch())) .withBlocking( !command.hasOption(DistCpOptionSwitch.BLOCKING.getSwitch())) .withVerboseLog( command.hasOption(DistCpOptionSwitch.VERBOSE_LOG.getSwitch())) .withDirectWrite( command.hasOption(DistCpOptionSwitch.DIRECT_WRITE.getSwitch())); if (command.hasOption(DistCpOptionSwitch.DIFF.getSwitch())) { String[] snapshots = getVals(command, DistCpOptionSwitch.DIFF.getSwitch()); checkSnapshotsArgs(snapshots); builder.withUseDiff(snapshots[0], snapshots[1]); } if (command.hasOption(DistCpOptionSwitch.RDIFF.getSwitch())) { String[] snapshots = getVals(command, DistCpOptionSwitch.RDIFF.getSwitch()); checkSnapshotsArgs(snapshots); builder.withUseRdiff(snapshots[0], snapshots[1]); } if (command.hasOption(DistCpOptionSwitch.FILTERS.getSwitch())) { builder.withFiltersFile( getVal(command, DistCpOptionSwitch.FILTERS.getSwitch())); } if (command.hasOption(DistCpOptionSwitch.LOG_PATH.getSwitch())) { builder.withLogPath( new Path(getVal(command, DistCpOptionSwitch.LOG_PATH.getSwitch()))); } if (command.hasOption(DistCpOptionSwitch.WORK_PATH.getSwitch())) { final String workPath = getVal(command, DistCpOptionSwitch.WORK_PATH.getSwitch()); if (workPath != null && !workPath.isEmpty()) { builder.withAtomicWorkPath(new Path(workPath)); } } if (command.hasOption(DistCpOptionSwitch.TRACK_MISSING.getSwitch())) { builder.withTrackMissing( new Path(getVal( command, DistCpOptionSwitch.TRACK_MISSING.getSwitch()))); } if (command.hasOption(DistCpOptionSwitch.BANDWIDTH.getSwitch())) { try { final Float mapBandwidth = Float.parseFloat( getVal(command, DistCpOptionSwitch.BANDWIDTH.getSwitch())); builder.withMapBandwidth(mapBandwidth); } catch (NumberFormatException e) { throw new IllegalArgumentException("Bandwidth specified is invalid: " + getVal(command, DistCpOptionSwitch.BANDWIDTH.getSwitch()), e); } } if (command.hasOption( DistCpOptionSwitch.NUM_LISTSTATUS_THREADS.getSwitch())) { try { final Integer numThreads = Integer.parseInt(getVal(command, DistCpOptionSwitch.NUM_LISTSTATUS_THREADS.getSwitch())); builder.withNumListstatusThreads(numThreads); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Number of liststatus threads is invalid: " + getVal(command, DistCpOptionSwitch.NUM_LISTSTATUS_THREADS.getSwitch()), e); } } if (command.hasOption(DistCpOptionSwitch.MAX_MAPS.getSwitch())) { try { final Integer maps = Integer.parseInt( getVal(command, DistCpOptionSwitch.MAX_MAPS.getSwitch())); builder.maxMaps(maps); } catch (NumberFormatException e) { throw new IllegalArgumentException("Number of maps is invalid: " + getVal(command, DistCpOptionSwitch.MAX_MAPS.getSwitch()), e); } } if (command.hasOption(DistCpOptionSwitch.COPY_STRATEGY.getSwitch())) { builder.withCopyStrategy( getVal(command, DistCpOptionSwitch.COPY_STRATEGY.getSwitch())); } if (command.hasOption(DistCpOptionSwitch.PRESERVE_STATUS.getSwitch())) { builder.preserve( getVal(command, DistCpOptionSwitch.PRESERVE_STATUS.getSwitch())); } if (command.hasOption(DistCpOptionSwitch.FILE_LIMIT.getSwitch())) { LOG.warn(DistCpOptionSwitch.FILE_LIMIT.getSwitch() + " is a deprecated" + " option. Ignoring."); } if (command.hasOption(DistCpOptionSwitch.SIZE_LIMIT.getSwitch())) { LOG.warn(DistCpOptionSwitch.SIZE_LIMIT.getSwitch() + " is a deprecated" + " option. Ignoring."); } if (command.hasOption(DistCpOptionSwitch.BLOCKS_PER_CHUNK.getSwitch())) { final String chunkSizeStr = getVal(command, DistCpOptionSwitch.BLOCKS_PER_CHUNK.getSwitch().trim()); try { int csize = Integer.parseInt(chunkSizeStr); csize = csize > 0 ? csize : 0; LOG.info("Set distcp blocksPerChunk to " + csize); builder.withBlocksPerChunk(csize); } catch (NumberFormatException e) { throw new IllegalArgumentException("blocksPerChunk is invalid: " + chunkSizeStr, e); } } if (command.hasOption(DistCpOptionSwitch.COPY_BUFFER_SIZE.getSwitch())) { final String copyBufferSizeStr = getVal(command, DistCpOptionSwitch.COPY_BUFFER_SIZE.getSwitch().trim()); try { int copyBufferSize = Integer.parseInt(copyBufferSizeStr); builder.withCopyBufferSize(copyBufferSize); } catch (NumberFormatException e) { throw new IllegalArgumentException("copyBufferSize is invalid: " + copyBufferSizeStr, e); } } return builder.build(); }  static DistCpOptions parse(String[] args); static void usage();  }
@Test public void testParseIgnoreFailure() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertFalse(options.shouldIgnoreFailures()); options = OptionsParser.parse(new String[] { "-i", "hdfs: "hdfs: Assert.assertTrue(options.shouldIgnoreFailures()); }
@Test public void testParseOverwrite() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertFalse(options.shouldOverwrite()); options = OptionsParser.parse(new String[] { "-overwrite", "hdfs: "hdfs: Assert.assertTrue(options.shouldOverwrite()); try { OptionsParser.parse(new String[] { "-update", "-overwrite", "hdfs: "hdfs: Assert.fail("Update and overwrite aren't allowed together"); } catch (IllegalArgumentException ignore) { } }
@Test public void testLogPath() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertNull(options.getLogPath()); options = OptionsParser.parse(new String[] { "-log", "hdfs: "hdfs: "hdfs: Assert.assertEquals(options.getLogPath(), new Path("hdfs: }
@Test public void testParseBlokcing() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertTrue(options.shouldBlock()); options = OptionsParser.parse(new String[] { "-async", "hdfs: "hdfs: Assert.assertFalse(options.shouldBlock()); }
@Test public void testParsebandwidth() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: assertThat(options.getMapBandwidth()).isCloseTo(0f, within(DELTA)); options = OptionsParser.parse(new String[] { "-bandwidth", "11.2", "hdfs: "hdfs: assertThat(options.getMapBandwidth()).isCloseTo(11.2f, within(DELTA)); }
@Test(expected=IllegalArgumentException.class) public void testParseNonPositiveBandwidth() { OptionsParser.parse(new String[] { "-bandwidth", "-11", "hdfs: "hdfs: }
@Test(expected=IllegalArgumentException.class) public void testParseZeroBandwidth() { OptionsParser.parse(new String[] { "-bandwidth", "0", "hdfs: "hdfs: }
@Test public void testParseSkipCRC() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertFalse(options.shouldSkipCRC()); options = OptionsParser.parse(new String[] { "-update", "-skipcrccheck", "hdfs: "hdfs: Assert.assertTrue(options.shouldSyncFolder()); Assert.assertTrue(options.shouldSkipCRC()); }
@Test public void testParseAtomicCommit() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertFalse(options.shouldAtomicCommit()); options = OptionsParser.parse(new String[] { "-atomic", "hdfs: "hdfs: Assert.assertTrue(options.shouldAtomicCommit()); try { OptionsParser.parse(new String[] { "-atomic", "-update", "hdfs: "hdfs: Assert.fail("Atomic and sync folders were allowed"); } catch (IllegalArgumentException ignore) { } }
@Test public void testParseWorkPath() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertNull(options.getAtomicWorkPath()); options = OptionsParser.parse(new String[] { "-atomic", "hdfs: "hdfs: Assert.assertNull(options.getAtomicWorkPath()); options = OptionsParser.parse(new String[] { "-atomic", "-tmp", "hdfs: "hdfs: "hdfs: Assert.assertEquals(options.getAtomicWorkPath(), new Path("hdfs: try { OptionsParser.parse(new String[] { "-tmp", "hdfs: "hdfs: "hdfs: Assert.fail("work path was allowed without -atomic switch"); } catch (IllegalArgumentException ignore) {} }
@Test public void testParseSyncFolders() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertFalse(options.shouldSyncFolder()); options = OptionsParser.parse(new String[] { "-update", "hdfs: "hdfs: Assert.assertTrue(options.shouldSyncFolder()); }
@Test public void testParseDeleteMissing() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertFalse(options.shouldDeleteMissing()); options = OptionsParser.parse(new String[] { "-update", "-delete", "hdfs: "hdfs: Assert.assertTrue(options.shouldSyncFolder()); Assert.assertTrue(options.shouldDeleteMissing()); options = OptionsParser.parse(new String[] { "-overwrite", "-delete", "hdfs: "hdfs: Assert.assertTrue(options.shouldOverwrite()); Assert.assertTrue(options.shouldDeleteMissing()); try { OptionsParser.parse(new String[] { "-atomic", "-delete", "hdfs: "hdfs: Assert.fail("Atomic and delete folders were allowed"); } catch (IllegalArgumentException ignore) { } }
@Test public void testParseMaps() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: assertThat(options.getMaxMaps()).isEqualTo(DistCpConstants.DEFAULT_MAPS); options = OptionsParser.parse(new String[] { "-m", "1", "hdfs: "hdfs: assertThat(options.getMaxMaps()).isEqualTo(1); options = OptionsParser.parse(new String[] { "-m", "0", "hdfs: "hdfs: assertThat(options.getMaxMaps()).isEqualTo(1); try { OptionsParser.parse(new String[] { "-m", "hello", "hdfs: "hdfs: Assert.fail("Non numberic map parsed"); } catch (IllegalArgumentException ignore) { } try { OptionsParser.parse(new String[] { "-mapredXslConf", "hdfs: "hdfs: Assert.fail("Non numberic map parsed"); } catch (IllegalArgumentException ignore) { } }
@Test public void testParseNumListstatusThreads() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertEquals(0, options.getNumListstatusThreads()); options = OptionsParser.parse(new String[] { "--numListstatusThreads", "12", "hdfs: "hdfs: Assert.assertEquals(12, options.getNumListstatusThreads()); options = OptionsParser.parse(new String[] { "--numListstatusThreads", "0", "hdfs: "hdfs: Assert.assertEquals(0, options.getNumListstatusThreads()); try { OptionsParser.parse(new String[] { "--numListstatusThreads", "hello", "hdfs: "hdfs: Assert.fail("Non numberic numListstatusThreads parsed"); } catch (IllegalArgumentException ignore) { } options = OptionsParser.parse(new String[] { "--numListstatusThreads", "100", "hdfs: "hdfs: Assert.assertEquals(DistCpOptions.MAX_NUM_LISTSTATUS_THREADS, options.getNumListstatusThreads()); }
@Test public void testSourceListing() { DistCpOptions options = OptionsParser.parse(new String[] { "-f", "hdfs: "hdfs: Assert.assertEquals(options.getSourceFileListing(), new Path("hdfs: }
@Test public void testSourceListingAndSourcePath() { try { OptionsParser.parse(new String[] { "-f", "hdfs: "hdfs: "hdfs: Assert.fail("Both source listing & source paths allowed"); } catch (IllegalArgumentException ignore) {} }
@Test public void testMissingSourceInfo() { try { OptionsParser.parse(new String[] { "hdfs: Assert.fail("Neither source listing not source paths present"); } catch (IllegalArgumentException ignore) {} }
@Test public void testMissingTarget() { try { OptionsParser.parse(new String[] { "-f", "hdfs: Assert.fail("Missing target allowed"); } catch (IllegalArgumentException ignore) {} }
@Test public void testInvalidArgs() { try { OptionsParser.parse(new String[] { "-m", "-f", "hdfs: Assert.fail("Missing map value"); } catch (IllegalArgumentException ignore) {} }
@Test public void testCopyStrategy() { DistCpOptions options = OptionsParser.parse(new String[] { "-strategy", "dynamic", "-f", "hdfs: "hdfs: assertThat(options.getCopyStrategy()).isEqualTo("dynamic"); options = OptionsParser.parse(new String[] { "-f", "hdfs: "hdfs: assertThat(options.getCopyStrategy()).isEqualTo(DistCpConstants.UNIFORMSIZE); }
@Test public void testTargetPath() { DistCpOptions options = OptionsParser.parse(new String[] { "-f", "hdfs: "hdfs: Assert.assertEquals(options.getTargetPath(), new Path("hdfs: }
@Test public void testPreserve() { DistCpOptions options = OptionsParser.parse(new String[] { "-f", "hdfs: "hdfs: Assert.assertFalse(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertFalse(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertFalse(options.shouldPreserve(FileAttribute.USER)); Assert.assertFalse(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertFalse(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); options = OptionsParser.parse(new String[] { "-p", "-f", "hdfs: "hdfs: Assert.assertTrue(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertTrue(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.USER)); Assert.assertTrue(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertTrue(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.ACL)); Assert.assertFalse(options.shouldPreserve(FileAttribute.XATTR)); options = OptionsParser.parse(new String[] { "-p", "hdfs: "hdfs: Assert.assertTrue(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertTrue(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.USER)); Assert.assertTrue(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertTrue(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.ACL)); Assert.assertFalse(options.shouldPreserve(FileAttribute.XATTR)); options = OptionsParser.parse(new String[] { "-pbr", "-f", "hdfs: "hdfs: Assert.assertTrue(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertTrue(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertFalse(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertFalse(options.shouldPreserve(FileAttribute.USER)); Assert.assertFalse(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertFalse(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.ACL)); Assert.assertFalse(options.shouldPreserve(FileAttribute.XATTR)); options = OptionsParser.parse(new String[] { "-pbrgup", "-f", "hdfs: "hdfs: Assert.assertTrue(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertTrue(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.USER)); Assert.assertTrue(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertFalse(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.ACL)); Assert.assertFalse(options.shouldPreserve(FileAttribute.XATTR)); options = OptionsParser.parse(new String[] { "-pbrgupcaxt", "-f", "hdfs: "hdfs: Assert.assertTrue(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertTrue(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertTrue(options.shouldPreserve(FileAttribute.USER)); Assert.assertTrue(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertTrue(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); Assert.assertTrue(options.shouldPreserve(FileAttribute.ACL)); Assert.assertTrue(options.shouldPreserve(FileAttribute.XATTR)); Assert.assertTrue(options.shouldPreserve(FileAttribute.TIMES)); options = OptionsParser.parse(new String[] { "-pc", "-f", "hdfs: "hdfs: Assert.assertFalse(options.shouldPreserve(FileAttribute.BLOCKSIZE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.REPLICATION)); Assert.assertFalse(options.shouldPreserve(FileAttribute.PERMISSION)); Assert.assertFalse(options.shouldPreserve(FileAttribute.USER)); Assert.assertFalse(options.shouldPreserve(FileAttribute.GROUP)); Assert.assertTrue(options.shouldPreserve(FileAttribute.CHECKSUMTYPE)); Assert.assertFalse(options.shouldPreserve(FileAttribute.ACL)); Assert.assertFalse(options.shouldPreserve(FileAttribute.XATTR)); options = OptionsParser.parse(new String[] { "-p", "-f", "hdfs: "hdfs: Assert.assertEquals(DistCpOptionSwitch.PRESERVE_STATUS_DEFAULT.length() - 2, options.getPreserveAttributes().size()); try { OptionsParser.parse(new String[] { "-pabcd", "-f", "hdfs: "hdfs: Assert.fail("Invalid preserve attribute"); } catch (NoSuchElementException ignore) {} Builder builder = new DistCpOptions.Builder( new Path("hdfs: new Path("hdfs: Assert.assertFalse( builder.build().shouldPreserve(FileAttribute.PERMISSION)); builder.preserve(FileAttribute.PERMISSION); Assert.assertTrue(builder.build().shouldPreserve(FileAttribute.PERMISSION)); builder.preserve(FileAttribute.PERMISSION); Assert.assertTrue(builder.build().shouldPreserve(FileAttribute.PERMISSION)); }
@Test public void testOptionsAppendToConf() { Configuration conf = new Configuration(); Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.IGNORE_FAILURES.getConfigLabel(), false)); Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.ATOMIC_COMMIT.getConfigLabel(), false)); Assert.assertEquals( conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), null); DistCpOptions options = OptionsParser.parse(new String[] { "-atomic", "-i", "hdfs: "hdfs: options.appendToConf(conf); Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.IGNORE_FAILURES.getConfigLabel(), false)); Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.ATOMIC_COMMIT.getConfigLabel(), false)); Assert.assertEquals(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), -1.0, DELTA); conf = new Configuration(); Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false)); Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false)); assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isNull(); options = OptionsParser.parse(new String[] { "-update", "-delete", "-pu", "-bandwidth", "11.2", "hdfs: "hdfs: options.appendToConf(conf); Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false)); Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false)); assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isEqualTo("U"); assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1)) .isCloseTo(11.2f, within(DELTA)); }
@Test public void testOptionsAppendToConfDoesntOverwriteBandwidth() { Configuration conf = new Configuration(); Assert.assertEquals( conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), null); DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: options.appendToConf(conf); assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1)) .isCloseTo(-1.0f,within(DELTA)); conf = new Configuration(); Assert.assertEquals( conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), null); options = OptionsParser.parse(new String[] { "-update", "-delete", "-pu", "-bandwidth", "77", "hdfs: "hdfs: options.appendToConf(conf); Assert.assertEquals( conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 77.0, DELTA); conf = new Configuration(); conf.set(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), "88"); Assert.assertEquals( conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), "88"); options = OptionsParser.parse(new String[] { "hdfs: "hdfs: options.appendToConf(conf); Assert.assertEquals( conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 88.0, DELTA); conf = new Configuration(); conf.set(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), "88.0"); Assert.assertEquals( conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), "88.0"); options = OptionsParser.parse(new String[] { "-bandwidth", "99", "hdfs: "hdfs: options.appendToConf(conf); Assert.assertEquals( conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 99.0, DELTA); }
@Test public void testAppendOption() { Configuration conf = new Configuration(); Assert.assertFalse(conf.getBoolean( DistCpOptionSwitch.APPEND.getConfigLabel(), false)); Assert.assertFalse(conf.getBoolean( DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false)); DistCpOptions options = OptionsParser.parse(new String[] { "-update", "-append", "hdfs: "hdfs: options.appendToConf(conf); Assert.assertTrue(conf.getBoolean( DistCpOptionSwitch.APPEND.getConfigLabel(), false)); Assert.assertTrue(conf.getBoolean( DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false)); try { OptionsParser.parse(new String[] { "-append", "hdfs: "hdfs: fail("Append should fail if update option is not specified"); } catch (IllegalArgumentException e) { GenericTestUtils.assertExceptionContains( "Append is valid only with update options", e); } try { OptionsParser.parse(new String[] { "-append", "-update", "-skipcrccheck", "hdfs: "hdfs: fail("Append should fail if skipCrc option is specified"); } catch (IllegalArgumentException e) { GenericTestUtils.assertExceptionContains( "Append is disallowed when skipping CRC", e); } }
@Test public void testExclusionsOption() { DistCpOptions options = OptionsParser.parse(new String[] { "hdfs: "hdfs: Assert.assertNull(options.getFiltersFile()); options = OptionsParser.parse(new String[] { "-filters", "/tmp/filters.txt", "hdfs: "hdfs: assertThat(options.getFiltersFile()).isEqualTo("/tmp/filters.txt"); }