@@ -219,7 +219,6 @@ public void testRenameWithoutValidFeature() throws Exception {
219
219
long expectedCount =
220
220
dfs .getQuotaUsage (new Path ("/" )).getFileAndDirectoryCount () - originDstDirUsage ;
221
221
ContentSummary contentSummary3 = dfs .getContentSummary (testParentDir2 );
222
-
223
222
// Src and dst must be same
224
223
// dstDir2=/testRename/testDir2/dst-dir
225
224
// dstDir3=/testRename/testDir3/dst-dir
@@ -303,10 +302,12 @@ public void testRenameUndoWithoutValidFeature() throws Exception {
303
302
Mockito .doReturn (false ).when (mockDir4 ).addChild (Mockito .eq (srcInode3 ), anyBoolean (), anyInt ());
304
303
rootDir .replaceChild (dir4 , mockDir4 , fsDirectory .getINodeMap ());
305
304
mockDir4 .setParent (rootDir );
305
+
306
306
// srcDir=/testRenameUndo/testDir3/src-dir
307
307
// dstDir=/testRenameUndo/testDir4/src-dir dstDir exist
308
308
assertThrows (RemoteException .class ,
309
309
() -> dfs .rename (srcDir3 , dstDir4 , Options .Rename .OVERWRITE ));
310
+
310
311
ContentSummary rootContentSummary4 = dfs .getContentSummary (new Path ("/" ));
311
312
QuotaUsage rootQuotaUsage4 = dfs .getQuotaUsage (new Path ("/" ));
312
313
ContentSummary contentSummary4 = dfs .getContentSummary (testParentDir3 );
@@ -316,4 +317,42 @@ public void testRenameUndoWithoutValidFeature() throws Exception {
316
317
assertEquals (rootContentSummary3 .getFileAndDirectoryCount (),
317
318
rootQuotaUsage4 .getFileAndDirectoryCount ());
318
319
}
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
+ Path file = new Path (testParentDir1 , "file1" );
331
+ DFSTestUtil .createFile (dfs , file , fileLen , replication , 0 );
332
+ dfs .allowSnapshot (testParentDir1 );
333
+ dfs .createSnapshot (testParentDir1 , "snapshot1" );
334
+
335
+ Path testParentDir2 = new Path (root , "testDir2" );
336
+ assertTrue (dfs .mkdirs (testParentDir2 ));
337
+
338
+ ContentSummary contentSummary1 = dfs .getContentSummary (new Path ("/" ));
339
+ QuotaUsage quotaUsage1 = dfs .getQuotaUsage (new Path ("/" ));
340
+ assertEquals (contentSummary1 .getSpaceConsumed (), quotaUsage1 .getSpaceConsumed ());
341
+ assertEquals (contentSummary1 .getFileAndDirectoryCount (),
342
+ quotaUsage1 .getFileAndDirectoryCount ());
343
+
344
+ // The snapshot of file1 not be cleaned up, rename2 interface similar
345
+ assertTrue (dfs .rename (new Path (testParentDir1 , "file1" ), testParentDir2 ));
346
+
347
+ ContentSummary contentSummary2 = dfs .getContentSummary (new Path ("/" ));
348
+ QuotaUsage quotaUsage2 = dfs .getQuotaUsage (new Path ("/" ));
349
+ assertEquals (quotaUsage1 .getFileAndDirectoryCount () + 1 ,
350
+ quotaUsage2 .getFileAndDirectoryCount ());
351
+ assertEquals (quotaUsage1 .getSpaceConsumed () + fileLen * replication ,
352
+ quotaUsage2 .getSpaceConsumed ());
353
+ // Root directory's actual capacity must match quota usage
354
+ assertEquals (contentSummary2 .getFileAndDirectoryCount (),
355
+ quotaUsage2 .getFileAndDirectoryCount ());
356
+ assertEquals (contentSummary2 .getSpaceConsumed (), quotaUsage2 .getSpaceConsumed ());
357
+ }
319
358
}
0 commit comments