@Before public void setUp() throws Exception { // create the test root on local_fs fcTarget = FileContext.getLocalFSFileContext(); chrootedTo = fileContextTestHelper.getAbsoluteTestRootPath(fcTarget); // In case previous test was killed before cleanup fcTarget.delete(chrootedTo, true); fcTarget.mkdir(chrootedTo, FileContext.DEFAULT_PERM, true); Configuration conf = new Configuration(); // ChRoot to the root of the testDirectory fc = FileContext.getFileContext( new ChRootedFs(fcTarget.getDefaultFileSystem(), chrootedTo), conf); }
@Test(timeout = 30000) public void testCreateSnapshot() throws Exception { Path snapRootPath = new Path("/snapPath"); Path chRootedSnapRootPath = new Path( Path.getPathWithoutSchemeAndAuthority(chrootedTo), "snapPath"); AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, chrootedTo); Mockito.doReturn(snapRootPath).when(baseFs) .createSnapshot(chRootedSnapRootPath, "snap1"); Assert.assertEquals(snapRootPath, chRootedFs.createSnapshot(snapRootPath, "snap1")); Mockito.verify(baseFs).createSnapshot(chRootedSnapRootPath, "snap1"); }
@Test(timeout = 30000) public void testDeleteSnapshot() throws Exception { Path snapRootPath = new Path("/snapPath"); Path chRootedSnapRootPath = new Path( Path.getPathWithoutSchemeAndAuthority(chrootedTo), "snapPath"); AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, chrootedTo); Mockito.doNothing().when(baseFs) .deleteSnapshot(chRootedSnapRootPath, "snap1"); chRootedFs.deleteSnapshot(snapRootPath, "snap1"); Mockito.verify(baseFs).deleteSnapshot(chRootedSnapRootPath, "snap1"); }
@Test(timeout = 30000) public void testRenameSnapshot() throws Exception { Path snapRootPath = new Path("/snapPath"); Path chRootedSnapRootPath = new Path( Path.getPathWithoutSchemeAndAuthority(chrootedTo), "snapPath"); AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, chrootedTo); Mockito.doNothing().when(baseFs) .renameSnapshot(chRootedSnapRootPath, "snapOldName", "snapNewName"); chRootedFs.renameSnapshot(snapRootPath, "snapOldName", "snapNewName"); Mockito.verify(baseFs).renameSnapshot(chRootedSnapRootPath, "snapOldName", "snapNewName"); }
@Test public void testIsValidNameValidInBaseFs() throws Exception { AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot")); Mockito.doReturn(true).when(baseFs).isValidName(Mockito.anyString()); Assert.assertTrue(chRootedFs.isValidName("/test")); Mockito.verify(baseFs).isValidName("/chroot/test"); }
@Test public void testIsValidNameInvalidInBaseFs() throws Exception { AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot")); Mockito.doReturn(false).when(baseFs).isValidName(Mockito.anyString()); Assert.assertFalse(chRootedFs.isValidName("/test")); Mockito.verify(baseFs).isValidName("/chroot/test"); }