|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.tools.mapred; |
20 | 20 |
|
21 | | -<<<<<<< HEAD |
22 | 21 | import org.apache.hadoop.fs.CommonConfigurationKeysPublic; |
23 | | -<<<<<<< HEAD |
24 | 22 | import org.apache.hadoop.fs.contract.ContractTestUtils; |
25 | | -======= |
26 | | ->>>>>>> 0c05975... fix failed unit test and checkstyles |
27 | | -======= |
28 | | ->>>>>>> 82de1c4... Fix some typo and checksytes. |
29 | 23 | import org.slf4j.Logger; |
30 | 24 | import org.slf4j.LoggerFactory; |
31 | 25 | import org.apache.hadoop.conf.Configuration; |
32 | | -import org.apache.hadoop.fs.CommonConfigurationKeysPublic; |
33 | | -import org.apache.hadoop.fs.contract.ContractTestUtils; |
34 | 26 | import org.apache.hadoop.fs.FileStatus; |
35 | 27 | import org.apache.hadoop.fs.FileSystem; |
36 | 28 | import org.apache.hadoop.fs.Path; |
@@ -345,6 +337,62 @@ public void testPreserveTimeWithDeleteMiss() throws IOException { |
345 | 337 | } |
346 | 338 | } |
347 | 339 |
|
| 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 | + |
348 | 396 | @Test |
349 | 397 | public void testDeleteMissingFlatInterleavedFiles() throws IOException { |
350 | 398 | TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config); |
|
0 commit comments