@@ -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,47 @@ 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 ("/testRenameSrcWithSnapshot" );
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
+ Path testParentDir3 = new Path (root , "testDir3" );
340
+ assertTrue (dfs .mkdirs (testParentDir3 ));
341
+
342
+ // Test rename1
343
+ ContentSummary contentSummary1 = dfs .getContentSummary (new Path ("/" ));
344
+ QuotaUsage quotaUsage1 = dfs .getQuotaUsage (new Path ("/" ));
345
+ assertEquals (contentSummary1 .getSpaceConsumed (), quotaUsage1 .getSpaceConsumed ());
346
+ assertEquals (contentSummary1 .getFileAndDirectoryCount (),
347
+ quotaUsage1 .getFileAndDirectoryCount ());
348
+
349
+ // The snapshot of file1 not be cleaned up.
350
+ assertTrue (dfs .rename (new Path (testParentDir1 , "file0" ), testParentDir2 ));
351
+
352
+ ContentSummary contentSummary2 = dfs .getContentSummary (new Path ("/" ));
353
+ QuotaUsage quotaUsage2 = dfs .getQuotaUsage (new Path ("/" ));
354
+ assertEquals (quotaUsage1 .getFileAndDirectoryCount () + 1 ,
355
+ quotaUsage2 .getFileAndDirectoryCount ());
356
+ assertEquals (quotaUsage1 .getSpaceConsumed () + fileLen * replication ,
357
+ quotaUsage2 .getSpaceConsumed ());
358
+ // Root directory's actual capacity must match quota usage.
359
+ assertEquals (contentSummary2 .getFileAndDirectoryCount (),
360
+ quotaUsage2 .getFileAndDirectoryCount ());
361
+ assertEquals (contentSummary2 .getSpaceConsumed (), quotaUsage2 .getSpaceConsumed ());
362
+ }
319
363
}
0 commit comments