@@ -219,7 +219,6 @@ public void testRenameWithoutValidFeature() throws Exception {
219219    long  expectedCount  =
220220        dfs .getQuotaUsage (new  Path ("/" )).getFileAndDirectoryCount () - originDstDirUsage ;
221221    ContentSummary  contentSummary3  = dfs .getContentSummary (testParentDir2 );
222- 
223222    // Src and dst must be same 
224223    // dstDir2=/testRename/testDir2/dst-dir 
225224    // dstDir3=/testRename/testDir3/dst-dir 
@@ -303,10 +302,12 @@ public void testRenameUndoWithoutValidFeature() throws Exception {
303302    Mockito .doReturn (false ).when (mockDir4 ).addChild (Mockito .eq (srcInode3 ), anyBoolean (), anyInt ());
304303    rootDir .replaceChild (dir4 , mockDir4 , fsDirectory .getINodeMap ());
305304    mockDir4 .setParent (rootDir );
305+ 
306306    // srcDir=/testRenameUndo/testDir3/src-dir 
307307    // dstDir=/testRenameUndo/testDir4/src-dir dstDir exist 
308308    assertThrows (RemoteException .class ,
309309        () -> dfs .rename (srcDir3 , dstDir4 , Options .Rename .OVERWRITE ));
310+ 
310311    ContentSummary  rootContentSummary4  = dfs .getContentSummary (new  Path ("/" ));
311312    QuotaUsage  rootQuotaUsage4  = dfs .getQuotaUsage (new  Path ("/" ));
312313    ContentSummary  contentSummary4  = dfs .getContentSummary (testParentDir3 );
@@ -316,4 +317,44 @@ public void testRenameUndoWithoutValidFeature() throws Exception {
316317    assertEquals (rootContentSummary3 .getFileAndDirectoryCount (),
317318        rootQuotaUsage4 .getFileAndDirectoryCount ());
318319  }
320+ 
321+   @ Test 
322+   public  void  testRenameFileInSnapshotDirWithoutValidFeature () throws  Exception  {
323+     final  int  fileLen  = 1024 ;
324+     final  short  replication  = 3 ;
325+     final  Path  root  = new  Path ("/testRenameFileInSnapshotDir" );
326+     assertTrue (dfs .mkdirs (root ));
327+ 
328+     Path  testParentDir1  = new  Path (root , "testDir1" );
329+     assertTrue (dfs .mkdirs (testParentDir1 ));
330+     for  (int  i  = 0 ; i  < 2 ; i ++) {
331+       Path  file  = new  Path (testParentDir1 , "file"  + i );
332+       DFSTestUtil .createFile (dfs , file , fileLen , replication , 0 ); 
333+     }
334+     dfs .allowSnapshot (testParentDir1 );
335+     dfs .createSnapshot (testParentDir1 , "snapshot1" );
336+ 
337+     Path  testParentDir2  = new  Path (root , "testDir2" );
338+     assertTrue (dfs .mkdirs (testParentDir2 ));
339+ 
340+     ContentSummary  contentSummary1  = dfs .getContentSummary (new  Path ("/" ));
341+     QuotaUsage  quotaUsage1  = dfs .getQuotaUsage (new  Path ("/" ));
342+     assertEquals (contentSummary1 .getSpaceConsumed (), quotaUsage1 .getSpaceConsumed ());
343+     assertEquals (contentSummary1 .getFileAndDirectoryCount (),
344+         quotaUsage1 .getFileAndDirectoryCount ());
345+ 
346+     // The snapshot of file1 not be cleaned up. 
347+     assertTrue (dfs .rename (new  Path (testParentDir1 , "file0" ), testParentDir2 ));
348+ 
349+     ContentSummary  contentSummary2  = dfs .getContentSummary (new  Path ("/" ));
350+     QuotaUsage  quotaUsage2  = dfs .getQuotaUsage (new  Path ("/" ));
351+     assertEquals (quotaUsage1 .getFileAndDirectoryCount () + 1 ,
352+         quotaUsage2 .getFileAndDirectoryCount ());
353+     assertEquals (quotaUsage1 .getSpaceConsumed () + fileLen  * replication ,
354+         quotaUsage2 .getSpaceConsumed ());
355+     // Root directory's actual capacity must match quota usage. 
356+     assertEquals (contentSummary2 .getFileAndDirectoryCount (),
357+         quotaUsage2 .getFileAndDirectoryCount ());
358+     assertEquals (contentSummary2 .getSpaceConsumed (), quotaUsage2 .getSpaceConsumed ());
359+   }
319360}
0 commit comments