Search in sources :

Example 91 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class ConcurrentFileSystemMasterTest method sameDstConcurrentRename.

/**
   * Tests renaming files concurrently to the same destination will only succeed once.
   */
@Test
public void sameDstConcurrentRename() throws Exception {
    int numThreads = CONCURRENCY_FACTOR;
    final AlluxioURI[] srcs = new AlluxioURI[numThreads];
    final AlluxioURI[] dsts = new AlluxioURI[numThreads];
    for (int i = 0; i < numThreads; i++) {
        srcs[i] = new AlluxioURI("/file" + i);
        mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
        dsts[i] = new AlluxioURI("/renamed");
    }
    int errors = concurrentRename(srcs, dsts);
    // We should get an error for all but 1 rename.
    Assert.assertEquals(numThreads - 1, errors);
    List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
    // Store file names in a set to ensure the names are all unique.
    Set<String> renamedFiles = new HashSet<>();
    Set<String> originalFiles = new HashSet<>();
    for (URIStatus file : files) {
        if (file.getName().startsWith("renamed")) {
            renamedFiles.add(file.getName());
        }
        if (file.getName().startsWith("file")) {
            originalFiles.add(file.getName());
        }
    }
    // One renamed file should exist, and numThreads - 1 original source files
    Assert.assertEquals(numThreads, files.size());
    Assert.assertEquals(1, renamedFiles.size());
    Assert.assertEquals(numThreads - 1, originalFiles.size());
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) HashSet(java.util.HashSet) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) Test(org.junit.Test)

Example 92 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class ConcurrentFileSystemMasterTest method folderConcurrentRename.

/**
   * Tests concurrent renames within a folder do not block on each other.
   */
@Test
public void folderConcurrentRename() throws Exception {
    final int numThreads = CONCURRENCY_FACTOR;
    AlluxioURI[] srcs = new AlluxioURI[numThreads];
    AlluxioURI[] dsts = new AlluxioURI[numThreads];
    AlluxioURI dir = new AlluxioURI("/dir");
    mFileSystem.createDirectory(dir);
    for (int i = 0; i < numThreads; i++) {
        srcs[i] = dir.join("/file" + i);
        mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
        dsts[i] = dir.join("/renamed" + i);
    }
    int errors = concurrentRename(srcs, dsts);
    Assert.assertEquals("More than 0 errors: " + errors, 0, errors);
    List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/dir"));
    Collections.sort(files, new IntegerSuffixedPathComparator());
    for (int i = 0; i < numThreads; i++) {
        Assert.assertEquals(dsts[i].getName(), files.get(i).getName());
    }
    Assert.assertEquals(numThreads, files.size());
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 93 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class JournalIntegrationTest method setAcl.

@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.SECURITY_AUTHENTICATION_TYPE, "SIMPLE", PropertyKey.Name.SECURITY_AUTHORIZATION_PERMISSION_ENABLED, "true", PropertyKey.Name.SECURITY_GROUP_MAPPING_CLASS, FakeUserGroupsMapping.FULL_CLASS_NAME })
public void setAcl() throws Exception {
    AlluxioURI filePath = new AlluxioURI("/file");
    String user = "alluxio";
    Configuration.set(PropertyKey.SECURITY_LOGIN_USERNAME, user);
    CreateFileOptions op = CreateFileOptions.defaults().setBlockSizeBytes(64);
    mFileSystem.createFile(filePath, op).close();
    // TODO(chaomin): also setOwner and setGroup once there's a way to fake the owner/group in UFS.
    mFileSystem.setAttribute(filePath, SetAttributeOptions.defaults().setMode(new Mode((short) 0400)).setRecursive(false));
    URIStatus status = mFileSystem.getStatus(filePath);
    mLocalAlluxioCluster.stopFS();
    aclTestUtil(status, user);
    deleteFsMasterJournalLogs();
    aclTestUtil(status, user);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) Mode(alluxio.security.authorization.Mode) Matchers.anyString(org.mockito.Matchers.anyString) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 94 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class JournalIntegrationTest method aclTestUtil.

private void aclTestUtil(URIStatus status, String user) throws Exception {
    FileSystemMaster fsMaster = createFsMasterFromJournal();
    AuthenticatedClientUser.set(user);
    FileInfo info = fsMaster.getFileInfo(new AlluxioURI("/file"));
    Assert.assertEquals(status, new URIStatus(info));
    fsMaster.stop();
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystemMaster(alluxio.master.file.FileSystemMaster) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 95 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class JournalIntegrationTest method directory.

/**
   * Tests directory creation.
   */
@Test
public void directory() throws Exception {
    AlluxioURI directoryPath = new AlluxioURI("/xyz");
    mFileSystem.createDirectory(directoryPath);
    URIStatus status = mFileSystem.getStatus(directoryPath);
    mLocalAlluxioCluster.stopFS();
    directoryTestUtil(status);
    deleteFsMasterJournalLogs();
    directoryTestUtil(status);
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

URIStatus (alluxio.client.file.URIStatus)119 AlluxioURI (alluxio.AlluxioURI)111 Test (org.junit.Test)78 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)23 IOException (java.io.IOException)19 FileInStream (alluxio.client.file.FileInStream)17 ArrayList (java.util.ArrayList)15 AlluxioException (alluxio.exception.AlluxioException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)13 AlluxioShellUtilsTest (alluxio.shell.AlluxioShellUtilsTest)12 FileInfo (alluxio.wire.FileInfo)12 File (java.io.File)10 FileOutStream (alluxio.client.file.FileOutStream)9 FileSystem (alluxio.client.file.FileSystem)7 InvalidPathException (alluxio.exception.InvalidPathException)7 ByteBuffer (java.nio.ByteBuffer)7 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)6 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)5 UnderFileSystem (alluxio.underfs.UnderFileSystem)5