use of alluxio.master.file.contexts.CreateDirectoryContext 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.CreateDirectoryContext in project alluxio by Alluxio.
the class InodeTreeTest method createPathTest.
/**
* Tests the {@link InodeTree#createPath(RpcContext, LockedInodePath, CreatePathContext)}
* 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.
CreateDirectoryContext dirContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setMode(TEST_DIR_MODE.toProto())).setOwner(TEST_OWNER).setGroup(TEST_GROUP);
// create nested directory
List<Inode> created = createPath(mTree, NESTED_URI, dirContext);
// 1 modified directory
assertNotEquals(lastModTime, getInodeByPath(NESTED_URI.getParent()).getLastModificationTimeMs());
// 2 created directories
assertEquals(2, created.size());
assertEquals("nested", created.get(0).getName());
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, dirContext);
fail("createPath should throw FileAlreadyExistsException");
} catch (FileAlreadyExistsException e) {
assertEquals("Not allowed to create directory because path already exists: " + NESTED_URI, e.getMessage());
}
// create a file
CreateFileContext options = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true));
created = createPath(mTree, NESTED_FILE_URI, options);
// test directory was modified
assertNotEquals(lastModTime, getInodeByPath(NESTED_URI).getLastModificationTimeMs());
// file was created
assertEquals(1, created.size());
assertEquals("file", created.get(0).getName());
// creating the file path again results in no new inodes.
try {
createPath(mTree, NESTED_FILE_URI, options);
fail("createPath should throw FileAlreadyExistsException");
} catch (FileAlreadyExistsException e) {
assertEquals("Not allowed to create file because path already exists: " + NESTED_FILE_URI, e.getMessage());
}
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlDirectoryDeleteReplay.
/**
* Tests that TTL delete of a directory is not forgotten across restarts.
*/
@Test
public void ttlDirectoryDeleteReplay() throws Exception {
CreateDirectoryContext context = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0)));
long dirId = mFileSystemMaster.createDirectory(NESTED_DIR_URI, context);
// Simulate restart.
stopServices();
startServices();
FileInfo fileInfo = mFileSystemMaster.getFileInfo(dirId);
assertEquals(fileInfo.getFileId(), dirId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(dirId);
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class FileSystemMasterTest method setSmallerTtlForDirectoryWithTtl.
/**
* Tests that an exception is thrown when trying to get information about a Directory after
* it has been deleted after the TTL has been set to 0.
*/
@Test
public void setSmallerTtlForDirectoryWithTtl() throws Exception {
CreateDirectoryContext directoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(Constants.HOUR_MS)).setRecursive(true));
mFileSystemMaster.createDirectory(NESTED_URI, directoryContext);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
assertTrue(mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT).getName() != null);
mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().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(NESTED_URI, GET_STATUS_CONTEXT);
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method createFilePerf.
@Test
public void createFilePerf() throws Exception {
for (int k = 0; k < 200; k++) {
CreateDirectoryContext context = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
mFsMaster.createDirectory(new AlluxioURI("/testFile").join(Constants.MASTER_COLUMN_FILE_PREFIX + k).join("0"), context);
}
for (int k = 0; k < 200; k++) {
mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFile").join(Constants.MASTER_COLUMN_FILE_PREFIX + k).join("0")));
}
}
Aggregations