Skip to content

Commit 1cf6beb

Browse files
committed
fix some nits
1 parent e284065 commit 1cf6beb

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCpOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ private void validate() {
577577
}
578578

579579
if (deleteUseTrash && !deleteMissing) {
580-
throw new IllegalArgumentException("Delete useTrash is applicable "
581-
+ "only with delete option");
580+
throw new IllegalArgumentException("Option -useTrash must be " +
581+
"accompanied by -delete");
582582
}
583583

584584
if (overwrite && syncFolder) {

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyCommitter.java

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,11 @@
1818

1919
package org.apache.hadoop.tools.mapred;
2020

21-
<<<<<<< HEAD
2221
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
23-
<<<<<<< HEAD
2422
import org.apache.hadoop.fs.contract.ContractTestUtils;
25-
=======
26-
>>>>>>> 0c05975... fix failed unit test and checkstyles
27-
=======
28-
>>>>>>> 82de1c4... Fix some typo and checksytes.
2923
import org.slf4j.Logger;
3024
import org.slf4j.LoggerFactory;
3125
import org.apache.hadoop.conf.Configuration;
32-
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
33-
import org.apache.hadoop.fs.contract.ContractTestUtils;
3426
import org.apache.hadoop.fs.FileStatus;
3527
import org.apache.hadoop.fs.FileSystem;
3628
import org.apache.hadoop.fs.Path;
@@ -345,6 +337,62 @@ public void testPreserveTimeWithDeleteMiss() throws IOException {
345337
}
346338
}
347339

340+
@Test
341+
public void testDeleteUseTrash() throws IOException {
342+
TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config);
343+
JobContext jobContext = new JobContextImpl(
344+
taskAttemptContext.getConfiguration(),
345+
taskAttemptContext.getTaskAttemptID().getJobID());
346+
Configuration conf = jobContext.getConfiguration();
347+
348+
String sourceBase;
349+
String targetBase;
350+
FileSystem fs = null;
351+
try {
352+
OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
353+
fs = FileSystem.get(conf);
354+
sourceBase = TestDistCpUtils.createTestSetup(fs);
355+
targetBase = TestDistCpUtils.createTestSetup(fs);
356+
String targetBaseAdd = TestDistCpUtils.createTestSetup(fs);
357+
ContractTestUtils.assertRenameOutcome(fs, new Path(targetBaseAdd),
358+
new Path(targetBase),true);
359+
360+
DistCpOptions.Builder builder = new DistCpOptions.Builder(
361+
Arrays.asList(new Path(sourceBase)), new Path("/out"));
362+
builder.withSyncFolder(true);
363+
builder.withDeleteMissing(true);
364+
builder.withDeleteUseTrash(true);
365+
builder.build().appendToConf(conf);
366+
DistCpContext cpContext = new DistCpContext(builder.build());
367+
368+
CopyListing listing = new GlobbedCopyListing(conf, CREDENTIALS);
369+
Path listingFile = new Path("/tmp1/" + String.valueOf(rand.nextLong()));
370+
listing.buildListing(listingFile, cpContext);
371+
372+
conf.set(DistCpConstants.CONF_LABEL_TARGET_WORK_PATH, targetBase);
373+
conf.set(DistCpConstants.CONF_LABEL_TARGET_FINAL_PATH, targetBase);
374+
375+
Path trashRootDir = fs.getTrashRoot(null);
376+
if (fs.exists(trashRootDir)) {
377+
fs.delete(trashRootDir, true);
378+
}
379+
committer.commitJob(jobContext);
380+
381+
verifyFoldersAreInSync(fs, targetBase, sourceBase);
382+
verifyFoldersAreInSync(fs, sourceBase, targetBase);
383+
384+
Assert.assertTrue("Path delete does not use trash",
385+
fs.exists(trashRootDir));
386+
Path trashDir = new Path(trashRootDir, "Current" + targetBaseAdd);
387+
verifyFoldersAreInSync(fs, trashDir.toString(), sourceBase);
388+
} finally {
389+
TestDistCpUtils.delete(fs, "/tmp1");
390+
fs.close();
391+
conf.set(DistCpConstants.CONF_LABEL_DELETE_MISSING, "false");
392+
conf.set(DistCpConstants.CONF_LABEL_DELETE_MISSING_USETRASH, "false");
393+
}
394+
}
395+
348396
@Test
349397
public void testDeleteMissingFlatInterleavedFiles() throws IOException {
350398
TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config);

0 commit comments

Comments
 (0)