46
46
import java .util .Collections ;
47
47
48
48
import static org .apache .hadoop .fs .CommonConfigurationKeysPublic .FS_TRASH_INTERVAL_KEY ;
49
+ import static org .apache .hadoop .hdfs .server .federation .router .RBFConfigKeys .DFS_ROUTER_TRASH_PATH_CREATED_BY_MOUNT_POINT ;
49
50
import static org .junit .Assert .assertTrue ;
50
51
import static org .junit .Assert .assertFalse ;
51
52
import static org .junit .Assert .assertEquals ;
@@ -70,6 +71,8 @@ public class TestRouterTrash {
70
71
private static String ns1 ;
71
72
private static final String MOUNT_POINT = "/home/data" ;
72
73
private static final String FILE = MOUNT_POINT + "/file1" ;
74
+ private static final String DST_PATH = "/home/dst_data" ;
75
+ private static final String DST_FILE = DST_PATH + "/file1" ;
73
76
private static final String TRASH_ROOT = "/user/" + TEST_USER + "/.Trash" ;
74
77
private static final String CURRENT = "/Current" ;
75
78
@@ -276,6 +279,81 @@ public void testDeleteToTrashExistMountPoint() throws IOException,
276
279
assertEquals (2 , fileStatuses .length );
277
280
}
278
281
282
+ private void deleteToTrashExistMountPoint () throws IOException ,
283
+ URISyntaxException , InterruptedException {
284
+ MountTable addEntry = MountTable .newInstance (MOUNT_POINT ,
285
+ Collections .singletonMap (ns0 , DST_PATH ));
286
+ assertTrue (addMountTable (addEntry ));
287
+
288
+ // current user client
289
+ DFSClient client = nnContext .getClient ();
290
+ client .setOwner ("/" , TEST_USER , TEST_USER );
291
+ UserGroupInformation ugi = UserGroupInformation .
292
+ createRemoteUser (TEST_USER );
293
+ // test user client
294
+ client = nnContext .getClient (ugi );
295
+ client .mkdirs (DST_PATH , new FsPermission ("777" ), true );
296
+ assertTrue (client .exists (DST_PATH ));
297
+ // create test file
298
+ client .create (DST_FILE , true );
299
+
300
+ Path filePath = new Path (FILE );
301
+ FileStatus [] fileStatuses = routerFs .listStatus (filePath );
302
+ assertEquals (1 , fileStatuses .length );
303
+ assertEquals (TEST_USER , fileStatuses [0 ].getOwner ());
304
+
305
+ // move to Trash.
306
+ Configuration routerConf = routerContext .getConf ();
307
+ FileSystem fs =
308
+ DFSTestUtil .getFileSystemAs (ugi , routerConf );
309
+ Trash trash = new Trash (fs , routerConf );
310
+ assertTrue (trash .moveToTrash (filePath ));
311
+ }
312
+
313
+ @ Test
314
+ public void testTrashPathStructure () throws IOException ,
315
+ URISyntaxException , InterruptedException {
316
+ // Trash path created by dst_path by default.
317
+ deleteToTrashExistMountPoint ();
318
+ FileStatus [] fileStatuses = nnFs .listStatus (
319
+ new Path (TRASH_ROOT + CURRENT + DST_PATH ));
320
+ assertEquals (1 , fileStatuses .length );
321
+ assertTrue (nnFs .exists (new Path (TRASH_ROOT + CURRENT + DST_FILE )));
322
+
323
+ // Re-build and start a federated cluster with dfs.federation.router.trash-path.created-by.mount-point=true.
324
+ tearDown ();
325
+ cluster = new StateStoreDFSCluster (false , 2 );
326
+ Configuration conf = new RouterConfigBuilder ()
327
+ .stateStore ()
328
+ .admin ()
329
+ .rpc ()
330
+ .http ()
331
+ .build ();
332
+ conf .set (FS_TRASH_INTERVAL_KEY , "100" );
333
+ conf .setBoolean (DFS_ROUTER_TRASH_PATH_CREATED_BY_MOUNT_POINT , true );
334
+ cluster .addRouterOverrides (conf );
335
+ cluster .startCluster ();
336
+ cluster .startRouters ();
337
+ cluster .waitClusterUp ();
338
+
339
+ ns0 = cluster .getNameservices ().get (0 );
340
+ ns1 = cluster .getNameservices ().get (1 );
341
+
342
+ routerContext = cluster .getRandomRouter ();
343
+ routerFs = routerContext .getFileSystem ();
344
+ nnContext = cluster .getNamenode (ns0 , null );
345
+ nnFs = nnContext .getFileSystem ();
346
+ Router router = routerContext .getRouter ();
347
+ mountTable = (MountTableResolver ) router .getSubclusterResolver ();
348
+
349
+ // Trash path created by mount_point.
350
+ deleteToTrashExistMountPoint ();
351
+ fileStatuses = nnFs .listStatus (
352
+ new Path (TRASH_ROOT + CURRENT + MOUNT_POINT ));
353
+ assertEquals (1 , fileStatuses .length );
354
+ assertTrue (nnFs .exists (new Path (TRASH_ROOT + CURRENT + FILE )));
355
+ }
356
+
279
357
@ Test
280
358
public void testIsTrashPath () throws IOException {
281
359
UserGroupInformation ugi = UserGroupInformation .getCurrentUser ();
0 commit comments