@Test public void deleteFileTest() throws Exception { long fileId = mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileOptions.defaults()); Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFile"))); mFsMaster.delete(new AlluxioURI("/testFile"), true); Assert.assertEquals(IdUtils.INVALID_FILE_ID, mFsMaster.getFileId(new AlluxioURI("/testFile"))); }
@Test public void deleteDirectoryWithDirectoriesTest2() throws Exception { mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults()); mFsMaster.createDirectory( new AlluxioURI("/testFolder/testFolder2"), CreateDirectoryOptions.defaults()); long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), CreateFileOptions.defaults()); long fileId2 = mFsMaster.createFile( new AlluxioURI("/testFolder/testFolder2/testFile2"), CreateFileOptions.defaults()); Assert.assertEquals(1, mFsMaster.getFileId(new AlluxioURI("/testFolder"))); Assert.assertEquals(2, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2"))); Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile"))); Assert.assertEquals( fileId2, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2"))); try { mFsMaster.delete(new AlluxioURI("/testFolder/testFolder2"), false); Assert.fail("Deleting a nonempty directory nonrecursively should fail"); } catch (DirectoryNotEmptyException e) { Assert.assertEquals( ExceptionMessage.DELETE_NONEMPTY_DIRECTORY_NONRECURSIVE.getMessage("testFolder2"), e.getMessage()); } Assert.assertEquals(1, mFsMaster.getFileId(new AlluxioURI("/testFolder"))); Assert.assertEquals(2, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2"))); Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile"))); Assert.assertEquals( fileId2, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2"))); }
@Test public void deleteEmptyDirectoryTest() throws Exception { mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults()); Assert.assertEquals(1, mFsMaster.getFileId(new AlluxioURI("/testFolder"))); mFsMaster.delete(new AlluxioURI("/testFolder"), true); Assert.assertEquals( IdUtils.INVALID_FILE_ID, mFsMaster.getFileId(new AlluxioURI("/testFolder"))); }
/** Tests that deleting a file from a folder updates the folder's last modification time. */ @Test public void lastModificationTimeDeleteTest() throws Exception { mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults()); mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), CreateFileOptions.defaults()); long folderId = mFsMaster.getFileId(new AlluxioURI("/testFolder")); long modificationTimeBeforeDelete = mFsMaster.getFileInfo(folderId).getLastModificationTimeMs(); CommonUtils.sleepMs(2); mFsMaster.delete(new AlluxioURI("/testFolder/testFile"), true); long modificationTimeAfterDelete = mFsMaster.getFileInfo(folderId).getLastModificationTimeMs(); Assert.assertTrue(modificationTimeBeforeDelete < modificationTimeAfterDelete); }
@Test public void deleteDirectoryWithDirectoriesTest() throws Exception { mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults()); mFsMaster.createDirectory( new AlluxioURI("/testFolder/testFolder2"), CreateDirectoryOptions.defaults()); long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), CreateFileOptions.defaults()); long fileId2 = mFsMaster.createFile( new AlluxioURI("/testFolder/testFolder2/testFile2"), CreateFileOptions.defaults()); Assert.assertEquals(1, mFsMaster.getFileId(new AlluxioURI("/testFolder"))); Assert.assertEquals(2, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2"))); Assert.assertEquals(fileId, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile"))); Assert.assertEquals( fileId2, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2"))); mFsMaster.delete(new AlluxioURI("/testFolder"), true); Assert.assertEquals( IdUtils.INVALID_FILE_ID, mFsMaster.getFileId(new AlluxioURI("/testFolder/testFolder2/testFile2"))); }
@Test public void deleteRootTest() throws Exception { mThrown.expect(InvalidPathException.class); mThrown.expectMessage(ExceptionMessage.DELETE_ROOT_DIRECTORY.getMessage()); mFsMaster.delete(new AlluxioURI("/"), true); }