Search in sources :

Example 21 with CreateFileContext

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

the class FileSystemMasterIntegrationTest method listFiles.

@Test
public void listFiles() throws Exception {
    CreateFileContext options = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(64));
    HashSet<Long> ids = new HashSet<>();
    HashSet<Long> dirIds = new HashSet<>();
    for (int i = 0; i < 10; i++) {
        AlluxioURI dir = new AlluxioURI("/i" + i);
        mFsMaster.createDirectory(dir, CreateDirectoryContext.defaults());
        dirIds.add(mFsMaster.getFileId(dir));
        for (int j = 0; j < 10; j++) {
            ids.add(mFsMaster.createFile(dir.join("j" + j), options).getFileId());
        }
    }
    HashSet<Long> listedIds = new HashSet<>();
    HashSet<Long> listedDirIds = new HashSet<>();
    List<FileInfo> infoList = mFsMaster.listStatus(new AlluxioURI("/"), ListStatusContext.defaults());
    for (FileInfo info : infoList) {
        long id = info.getFileId();
        listedDirIds.add(id);
        for (FileInfo fileInfo : mFsMaster.listStatus(new AlluxioURI(info.getPath()), ListStatusContext.defaults())) {
            listedIds.add(fileInfo.getFileId());
        }
    }
    Assert.assertEquals(ids, listedIds);
    Assert.assertEquals(dirIds, listedDirIds);
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileInfo(alluxio.wire.FileInfo) HashSet(java.util.HashSet) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 22 with CreateFileContext

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

the class FileSystemMasterIntegrationTest method listStatus.

@Test
public void listStatus() throws Exception {
    CreateFileContext options = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(64));
    for (int i = 0; i < 10; i++) {
        mFsMaster.createDirectory(new AlluxioURI("/i" + i), CreateDirectoryContext.defaults());
        for (int j = 0; j < 10; j++) {
            mFsMaster.createFile(new AlluxioURI("/i" + i + "/j" + j), options);
        }
    }
    Assert.assertEquals(1, mFsMaster.listStatus(new AlluxioURI("/i0/j0"), ListStatusContext.defaults()).size());
    for (int i = 0; i < 10; i++) {
        Assert.assertEquals(10, mFsMaster.listStatus(new AlluxioURI("/i" + i), ListStatusContext.defaults()).size());
    }
    Assert.assertEquals(10, mFsMaster.listStatus(new AlluxioURI("/"), ListStatusContext.defaults()).size());
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 23 with CreateFileContext

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

the class FileSystemMasterIntegrationTest method ttlExpiredCreateFile.

@Test
public void ttlExpiredCreateFile() throws Exception {
    mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
    long ttl = 1;
    CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl)));
    long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile1"), context).getFileId();
    FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile1")));
    Assert.assertEquals(fileId, folderInfo.getFileId());
    Assert.assertEquals(ttl, folderInfo.getTtl());
    // Sleep for the ttl expiration.
    CommonUtils.sleepMs(2 * TTL_CHECKER_INTERVAL_MS);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    mThrown.expect(FileDoesNotExistException.class);
    mFsMaster.getFileInfo(fileId);
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 24 with CreateFileContext

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

the class FileSystemMasterIntegrationTest method ttlCreateFile.

@Test
public void ttlCreateFile() throws Exception {
    mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryContext.defaults());
    long ttl = 100;
    CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl).setTtlAction(alluxio.grpc.TtlAction.FREE)));
    mFsMaster.createFile(new AlluxioURI("/testFolder/testFile"), context);
    FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile")));
    Assert.assertEquals(ttl, folderInfo.getTtl());
    Assert.assertEquals(TtlAction.FREE, folderInfo.getTtlAction());
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 25 with CreateFileContext

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

the class PermissionCheckTest method verifyCreateFile.

private void verifyCreateFile(TestUser user, String path, boolean recursive) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setRecursive(recursive)).setOwner(SecurityUtils.getOwnerFromGrpcClient(ServerConfiguration.global())).setGroup(SecurityUtils.getGroupFromGrpcClient(ServerConfiguration.global())).setWriteType(WriteType.CACHE_THROUGH);
        FileInfo fileInfo = mFileSystemMaster.createFile(new AlluxioURI(path), context);
        String[] pathComponents = path.split("/");
        assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
        assertEquals(user.getUser(), fileInfo.getOwner());
    }
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) 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