use of alluxio.master.file.contexts.CreateFileContext in project alluxio by Alluxio.
the class FileSystemMasterTest method setTtlForFileWithNoTtl.
/**
* Tests that an exception is thrown when trying to get information about a file after it
* has been deleted because of a TTL of 0.
*/
@Test
public void setTtlForFileWithNoTtl() throws Exception {
CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true));
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, context).getFileId();
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// Since no TTL is set, the file should not be deleted.
assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getFileId());
mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(fileId);
}
use of alluxio.master.file.contexts.CreateFileContext 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");
CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(-1));
createPath(mTree, TEST_URI, context);
}
use of alluxio.master.file.contexts.CreateFileContext in project alluxio by Alluxio.
the class InodeTreeTest method createPathInheritanceTest.
/**
* Tests the {@link InodeTree#createPath(RpcContext, LockedInodePath, CreatePathContext)} method
* for inheriting owner and group when empty.
*/
@Test
public void createPathInheritanceTest() throws Exception {
// create nested directory
CreateDirectoryContext dirContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setMode(TEST_DIR_MODE.toProto())).setOwner(TEST_OWNER).setGroup(TEST_GROUP);
List<Inode> created = createPath(mTree, NESTED_URI, dirContext);
assertEquals(2, created.size());
// 1. create a nested directory with empty owner and group
CreateDirectoryContext nestedDirContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setMode(TEST_DIR_MODE.toProto())).setOwner("").setGroup("");
created = createPath(mTree, NESTED_DIR_URI, nestedDirContext);
assertEquals(1, created.size());
assertEquals("dir", created.get(0).getName());
assertEquals(TEST_OWNER, created.get(0).getOwner());
assertEquals(TEST_GROUP, created.get(0).getGroup());
// 2. create a file with empty owner and group
CreateFileContext nestedDirFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true)).setOwner("").setGroup("");
created = createPath(mTree, NESTED_DIR_FILE_URI, nestedDirFileContext);
assertEquals(1, created.size());
assertEquals("file1", created.get(0).getName());
assertEquals(TEST_OWNER, created.get(0).getOwner());
assertEquals(TEST_GROUP, created.get(0).getGroup());
}
use of alluxio.master.file.contexts.CreateFileContext in project alluxio by Alluxio.
the class InodeTreeTest method createFileWithInvalidBlockSize.
/**
* Tests that an exception is thrown when trying to create a file with invalid block size.
*/
@Test
public void createFileWithInvalidBlockSize() throws Exception {
mThrown.expect(BlockInfoException.class);
mThrown.expectMessage("Invalid block size 0");
CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(0));
createPath(mTree, TEST_URI, context);
}
use of alluxio.master.file.contexts.CreateFileContext in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlFileDelete.
/**
* Tests that an exception is in the
* {@link FileSystemMaster#createFile(AlluxioURI, CreateFileContext)} with a
* TTL set in the {@link CreateFileContext} after the TTL check was done once.
*/
@Test
public void ttlFileDelete() throws Exception {
CreateFileContext context = CreateFileContext.defaults();
context.getOptions().setBlockSizeBytes(Constants.KB);
context.getOptions().setRecursive(true);
context.getOptions().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0));
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, context).getFileId();
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
assertEquals(fileInfo.getFileId(), fileId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(fileId);
}
Aggregations