|
45 | 45 | import org.apache.hadoop.ipc.RemoteException; |
46 | 46 | import org.apache.hadoop.security.UserGroupInformation; |
47 | 47 | import org.apache.hadoop.test.GenericTestUtils; |
| 48 | +import org.apache.hadoop.test.LambdaTestUtils; |
48 | 49 | import org.junit.After; |
49 | 50 | import org.junit.Assert; |
50 | 51 | import org.junit.Before; |
@@ -525,4 +526,42 @@ public void testConcatReservedRelativePaths() throws IOException { |
525 | 526 | GenericTestUtils.assertExceptionContains(errMsg, e); |
526 | 527 | } |
527 | 528 | } |
| 529 | + |
| 530 | + /** |
| 531 | + * Test concat on same source and target file which is a inode reference. |
| 532 | + */ |
| 533 | + @Test |
| 534 | + public void testConcatOnSameFile() throws Exception { |
| 535 | + String dir = "/dir1"; |
| 536 | + Path trgDir = new Path(dir); |
| 537 | + dfs.mkdirs(new Path(dir)); |
| 538 | + |
| 539 | + // create a source file |
| 540 | + String dir2 = "/dir2"; |
| 541 | + Path srcDir = new Path(dir2); |
| 542 | + dfs.mkdirs(srcDir); |
| 543 | + dfs.allowSnapshot(srcDir); |
| 544 | + Path src = new Path(srcDir, "file1"); |
| 545 | + DFSTestUtil.createFile(dfs, src, 512, (short) 2, 0); |
| 546 | + |
| 547 | + // make the file as an Inode reference and delete the reference |
| 548 | + dfs.createSnapshot(srcDir, "s1"); |
| 549 | + dfs.rename(src, trgDir); |
| 550 | + dfs.deleteSnapshot(srcDir, "s1"); |
| 551 | + Path[] srcs = new Path[1]; |
| 552 | + srcs[0] = new Path(dir, "file1"); |
| 553 | + |
| 554 | + // perform concat |
| 555 | + LambdaTestUtils.intercept(RemoteException.class, |
| 556 | + "concat: the src file /dir1/file1 is the same with the target" |
| 557 | + + " file /dir1/file1", |
| 558 | + () -> dfs.concat(srcs[0], srcs)); |
| 559 | + |
| 560 | + // the file should exists and read the file |
| 561 | + byte[] buff = new byte[1080]; |
| 562 | + FSDataInputStream stream = dfs.open(srcs[0]); |
| 563 | + stream.readFully(0, buff, 0, 512); |
| 564 | + |
| 565 | + assertEquals(1, dfs.getContentSummary(new Path(dir)).getFileCount()); |
| 566 | + } |
528 | 567 | } |
0 commit comments