Search in sources :

Example 16 with CreateFileContext

use of alluxio.master.file.contexts.CreateFileContext 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 {
    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();
    // Simulate restart.
    stopServices();
    startServices();
    FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
    assertEquals(fileInfo.getFileId(), fileId);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    mThrown.expect(FileDoesNotExistException.class);
    mFileSystemMaster.getFileInfo(fileId);
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 17 with CreateFileContext

use of alluxio.master.file.contexts.CreateFileContext 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 {
    CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(Constants.HOUR_MS)).setBlockSizeBytes(Constants.KB).setRecursive(true));
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, context).getFileId();
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    // Since TTL is 1 hour, the file won't be deleted during last TTL check.
    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 reset to 0, the file should have been deleted during last TTL check.
    mThrown.expect(FileDoesNotExistException.class);
    mFileSystemMaster.getFileInfo(fileId);
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) Test(org.junit.Test)

Example 18 with CreateFileContext

use of alluxio.master.file.contexts.CreateFileContext 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 {
    CreateDirectoryContext directoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
    mFileSystemMaster.createDirectory(NESTED_URI, directoryContext);
    mFileSystemMaster.createDirectory(NESTED_DIR_URI, directoryContext);
    CreateFileContext createFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true));
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, createFileContext).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());
    // Set ttl.
    mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().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, GET_STATUS_CONTEXT);
    mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT);
    mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT);
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Test(org.junit.Test)

Example 19 with CreateFileContext

use of alluxio.master.file.contexts.CreateFileContext 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 20 with CreateFileContext

use of alluxio.master.file.contexts.CreateFileContext in project alluxio by Alluxio.

the class JournalSinkTest method createFile.

private void createFile(String path) throws Exception {
    CreateFileContext createFileContext = CreateFileContext.create(CreateFilePOptions.newBuilder().setRecursive(true).setBlockSizeBytes(1024));
    mFileSystemMaster.createFile(new AlluxioURI(path), createFileContext);
    mFileSystemMaster.completeFile(new AlluxioURI(path), CompleteFileContext.defaults());
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) AlluxioURI(alluxio.AlluxioURI)

Aggregations

CreateFileContext (alluxio.master.file.contexts.CreateFileContext)26 Test (org.junit.Test)22 AlluxioURI (alluxio.AlluxioURI)14 FileInfo (alluxio.wire.FileInfo)10 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)9 CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)5 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)4 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 AccessControlList (alluxio.security.authorization.AccessControlList)2 DefaultAccessControlList (alluxio.security.authorization.DefaultAccessControlList)2 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)1 BlockInfoException (alluxio.exception.BlockInfoException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 FileSystemMaster (alluxio.master.file.FileSystemMaster)1 CompleteFileContext (alluxio.master.file.contexts.CompleteFileContext)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MergeJournalContext (alluxio.master.journal.MergeJournalContext)1 UpdateInodeEntry (alluxio.proto.journal.File.UpdateInodeEntry)1 LockResource (alluxio.resource.LockResource)1 Mode (alluxio.security.authorization.Mode)1