Search in sources :

Example 16 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.

the class InodeTreeTest method createPathTest.

/**
   * Tests the {@link InodeTree#createPath(LockedInodePath, CreatePathOptions)} 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.
    CreateDirectoryOptions dirOptions = CreateDirectoryOptions.defaults().setOwner(TEST_OWNER).setGroup(TEST_GROUP).setMode(TEST_DIR_MODE).setRecursive(true);
    // create nested directory
    InodeTree.CreatePathResult createResult = createPath(mTree, NESTED_URI, dirOptions);
    List<Inode<?>> modified = createResult.getModified();
    List<Inode<?>> created = createResult.getCreated();
    // 1 modified directory
    Assert.assertEquals(1, modified.size());
    Assert.assertEquals("", modified.get(0).getName());
    Assert.assertNotEquals(lastModTime, modified.get(0).getLastModificationTimeMs());
    // 2 created directories
    Assert.assertEquals(2, created.size());
    Assert.assertEquals("nested", created.get(0).getName());
    Assert.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, dirOptions);
        Assert.assertTrue("createPath should throw FileAlreadyExistsException", false);
    } catch (FileAlreadyExistsException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(NESTED_URI));
    }
    // create a file
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true);
    createResult = createPath(mTree, NESTED_FILE_URI, options);
    modified = createResult.getModified();
    created = createResult.getCreated();
    // test directory was modified
    Assert.assertEquals(1, modified.size());
    Assert.assertEquals("test", modified.get(0).getName());
    Assert.assertNotEquals(lastModTime, modified.get(0).getLastModificationTimeMs());
    // file was created
    Assert.assertEquals(1, created.size());
    Assert.assertEquals("file", created.get(0).getName());
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) CreateDirectoryOptions(alluxio.master.file.options.CreateDirectoryOptions) Test(org.junit.Test)

Example 17 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions 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");
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(-1);
    createPath(mTree, TEST_URI, options);
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) Test(org.junit.Test)

Example 18 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions 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 {
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(Constants.HOUR_MS);
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    // Since TTL is 1 hour, the file won't be deleted during last TTL check.
    Assert.assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI).getFileId());
    mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeOptions.defaults().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 : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) Test(org.junit.Test)

Example 19 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions 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 {
    CreateDirectoryOptions createDirectoryOptions = CreateDirectoryOptions.defaults().setRecursive(true);
    mFileSystemMaster.createDirectory(NESTED_URI, createDirectoryOptions);
    mFileSystemMaster.createDirectory(NESTED_DIR_URI, createDirectoryOptions);
    CreateFileOptions createFileOptions = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true);
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, createFileOptions);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    // Since no TTL is set, the file should not be deleted.
    Assert.assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI).getFileId());
    // Set ttl
    mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeOptions.defaults().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);
    mFileSystemMaster.getFileInfo(NESTED_DIR_URI);
    mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) CreateDirectoryOptions(alluxio.master.file.options.CreateDirectoryOptions) Test(org.junit.Test)

Example 20 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions 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 {
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(0);
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
    // Simulate restart.
    stopServices();
    startServices();
    FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(fileInfo.getFileId(), fileId);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    mThrown.expect(FileDoesNotExistException.class);
    mFileSystemMaster.getFileInfo(fileId);
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Aggregations

CreateFileOptions (alluxio.master.file.options.CreateFileOptions)24 Test (org.junit.Test)20 AlluxioURI (alluxio.AlluxioURI)13 FileInfo (alluxio.wire.FileInfo)9 CreateDirectoryOptions (alluxio.master.file.options.CreateDirectoryOptions)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)2 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2 ArrayList (java.util.ArrayList)2 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)1 BlockInfoException (alluxio.exception.BlockInfoException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 CompleteFileOptions (alluxio.master.file.options.CompleteFileOptions)1 RenameOptions (alluxio.master.file.options.RenameOptions)1 MkdirsOptions (alluxio.underfs.options.MkdirsOptions)1 HashSet (java.util.HashSet)1