Search in sources :

Example 11 with CreateFileContext

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

Example 12 with CreateFileContext

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

Example 13 with CreateFileContext

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

Example 14 with CreateFileContext

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

Example 15 with CreateFileContext

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

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