use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.
the class InodeTreeTest method createPathTest.
/**
* Tests the {@link InodeTree#createPath(LockedInodePath, CreatePathOptions)} method.
*/
@Test
public void createPathTest() throws Exception {
// save the last mod time of the root
long lastModTime = mTree.getRoot().getLastModificationTimeMs();
// sleep to ensure a different last modification time
CommonUtils.sleepMs(10);
// Need to use updated options to set the correct last mod time.
CreateDirectoryOptions dirOptions = CreateDirectoryOptions.defaults().setOwner(TEST_OWNER).setGroup(TEST_GROUP).setMode(TEST_DIR_MODE).setRecursive(true);
// create nested directory
InodeTree.CreatePathResult createResult = createPath(mTree, NESTED_URI, dirOptions);
List<Inode<?>> modified = createResult.getModified();
List<Inode<?>> created = createResult.getCreated();
// 1 modified directory
Assert.assertEquals(1, modified.size());
Assert.assertEquals("", modified.get(0).getName());
Assert.assertNotEquals(lastModTime, modified.get(0).getLastModificationTimeMs());
// 2 created directories
Assert.assertEquals(2, created.size());
Assert.assertEquals("nested", created.get(0).getName());
Assert.assertEquals("test", created.get(1).getName());
// save the last mod time of 'test'
lastModTime = created.get(1).getLastModificationTimeMs();
// sleep to ensure a different last modification time
CommonUtils.sleepMs(10);
// creating the directory path again results in no new inodes.
try {
createPath(mTree, NESTED_URI, dirOptions);
Assert.assertTrue("createPath should throw FileAlreadyExistsException", false);
} catch (FileAlreadyExistsException e) {
Assert.assertEquals(e.getMessage(), ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(NESTED_URI));
}
// create a file
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true);
createResult = createPath(mTree, NESTED_FILE_URI, options);
modified = createResult.getModified();
created = createResult.getCreated();
// test directory was modified
Assert.assertEquals(1, modified.size());
Assert.assertEquals("test", modified.get(0).getName());
Assert.assertNotEquals(lastModTime, modified.get(0).getLastModificationTimeMs());
// file was created
Assert.assertEquals(1, created.size());
Assert.assertEquals("file", created.get(0).getName());
}
use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.
the class InodeTreeTest method createFileWithNegativeBlockSize.
/**
* Tests that an exception is thrown when trying to create a file with a negative block size.
*/
@Test
public void createFileWithNegativeBlockSize() throws Exception {
mThrown.expect(BlockInfoException.class);
mThrown.expectMessage("Invalid block size -1");
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(-1);
createPath(mTree, TEST_URI, options);
}
use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.
the class FileSystemMasterTest method setSmallerTtlForFileWithTtl.
/**
* Tests that an exception is thrown when trying to get information about a file after it has been
* deleted after the TTL has been set to 0.
*/
@Test
public void setSmallerTtlForFileWithTtl() throws Exception {
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(Constants.HOUR_MS);
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// Since TTL is 1 hour, the file won't be deleted during last TTL check.
Assert.assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI).getFileId());
mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeOptions.defaults().setTtl(0));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is reset to 0, the file should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(fileId);
}
use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.
the class FileSystemMasterTest method setTtlForDirectoryWithNoTtl.
/**
* Tests that an exception is thrown when trying to get information about a Directory after
* it has been deleted because of a TTL of 0.
*/
@Test
public void setTtlForDirectoryWithNoTtl() throws Exception {
CreateDirectoryOptions createDirectoryOptions = CreateDirectoryOptions.defaults().setRecursive(true);
mFileSystemMaster.createDirectory(NESTED_URI, createDirectoryOptions);
mFileSystemMaster.createDirectory(NESTED_DIR_URI, createDirectoryOptions);
CreateFileOptions createFileOptions = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true);
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, createFileOptions);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// Since no TTL is set, the file should not be deleted.
Assert.assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI).getFileId());
// Set ttl
mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeOptions.defaults().setTtl(0));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file and directory should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(NESTED_URI);
mFileSystemMaster.getFileInfo(NESTED_DIR_URI);
mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
}
use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlFileDeleteReplay.
/**
* Tests that TTL delete of a file is not forgotten across restarts.
*/
@Test
public void ttlFileDeleteReplay() throws Exception {
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(0);
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
// Simulate restart.
stopServices();
startServices();
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(fileInfo.getFileId(), fileId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(fileId);
}
Aggregations