Search in sources :

Example 11 with CreateDirectoryContext

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());
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Test(org.junit.Test)

Example 12 with CreateDirectoryContext

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());
    }
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Test(org.junit.Test)

Example 13 with CreateDirectoryContext

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);
}
Also used : FileInfo(alluxio.wire.FileInfo) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Test(org.junit.Test)

Example 14 with CreateDirectoryContext

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);
}
Also used : CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Test(org.junit.Test)

Example 15 with CreateDirectoryContext

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")));
    }
}
Also used : CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)15 Test (org.junit.Test)10 AlluxioURI (alluxio.AlluxioURI)6 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)5 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 FileInfo (alluxio.wire.FileInfo)3 Command (alluxio.grpc.Command)2 AccessControlList (alluxio.security.authorization.AccessControlList)2 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)2 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 FileSystemCommand (alluxio.wire.FileSystemCommand)2 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)1 BlockInfoException (alluxio.exception.BlockInfoException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MountTable (alluxio.master.file.meta.MountTable)1 MutableInodeDirectory (alluxio.master.file.meta.MutableInodeDirectory)1 UpdateInodeEntry (alluxio.proto.journal.File.UpdateInodeEntry)1 LockResource (alluxio.resource.LockResource)1