Search in sources :

Example 51 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class SwiftUnderFileSystemTest method getContainerName.

/**
   * Test case for {@link SwiftUnderFileSystem#getContainerName(AlluxioURI)}.
   */
@Test
public void getContainerName() {
    // Test valid container names
    String[] validContainerNames = { "container", "swift_container", "a@b:123", "a.b.c" };
    for (String containerName : validContainerNames) {
        AlluxioURI uri = new AlluxioURI(SCHEME + containerName);
        Assert.assertTrue(containerName.equals(SwiftUnderFileSystem.getContainerName(uri)));
    }
    // Test separator splits container name
    String[] paths = new String[validContainerNames.length];
    for (int i = 0; i < paths.length; ++i) {
        paths[i] = validContainerNames[i] + "/folder/file";
    }
    for (int i = 0; i < paths.length; ++i) {
        AlluxioURI uri = new AlluxioURI(SCHEME + paths[i]);
        Assert.assertTrue(validContainerNames[i].equals(SwiftUnderFileSystem.getContainerName(uri)));
    }
}
Also used : AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 52 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemTestUtils method listFiles.

/**
   * Returns a list of files at a given {@code path}.
   *
   * @param fs a {@link FileSystem} handler
   * @param path a path in alluxio file system
   * @return a list of strings representing the file names under the given path
   * @throws IOException if {@code path} does not exist or is invalid
   */
public static List<String> listFiles(FileSystem fs, String path) throws IOException {
    try {
        List<URIStatus> statuses = fs.listStatus(new AlluxioURI(path));
        List<String> res = new ArrayList<>();
        for (URIStatus status : statuses) {
            res.add(status.getPath());
            if (status.isFolder()) {
                res.addAll(listFiles(fs, status.getPath()));
            }
        }
        return res;
    } catch (AlluxioException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 53 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemClientRestApiTest method delete.

@Test
public void delete() throws Exception {
    AlluxioURI uri = new AlluxioURI("/file");
    writeFile(uri, null);
    new TestCase(mHostname, mPort, PATHS_PREFIX + uri.toString() + "/" + PathsRestServiceHandler.DELETE, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(DeleteOptions.defaults())).run();
    try {
        mFileSystemMaster.getFileInfo(uri);
        Assert.fail("file should have been removed");
    } catch (FileDoesNotExistException e) {
    // Expected
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 54 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemClientRestApiTest method listStatus.

@Test
public void listStatus() throws Exception {
    AlluxioURI uri = new AlluxioURI("/file");
    writeFile(uri, null);
    String result = new TestCase(mHostname, mPort, PATHS_PREFIX + uri.toString() + "/" + PathsRestServiceHandler.LIST_STATUS, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(ListStatusOptions.defaults())).call();
    List<FileInfo> fileInfos = new ObjectMapper().readValue(result, new TypeReference<List<FileInfo>>() {
    });
    FileInfo fileInfo = Iterables.getOnlyElement(fileInfos);
    Assert.assertEquals(uri.getPath(), fileInfo.getPath());
    Assert.assertEquals(0, fileInfo.getLength());
}
Also used : FileInfo(alluxio.wire.FileInfo) TestCase(alluxio.rest.TestCase) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 55 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemClientRestApiTest method setAttribute.

@Test
public void setAttribute() throws Exception {
    AlluxioURI uri = new AlluxioURI("/file");
    writeFile(uri, null);
    new TestCase(mHostname, mPort, PATHS_PREFIX + uri.toString() + "/" + PathsRestServiceHandler.SET_ATTRIBUTE, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(SetAttributeOptions.defaults().setMode(Mode.defaults()))).run();
    FileInfo fileInfo = mFileSystemMaster.getFileInfo(uri);
    Assert.assertEquals(uri.toString(), fileInfo.getPath());
}
Also used : FileInfo(alluxio.wire.FileInfo) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1552 Test (org.junit.Test)1094 URIStatus (alluxio.client.file.URIStatus)356 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)303 IOException (java.io.IOException)154 FileInStream (alluxio.client.file.FileInStream)152 FileInfo (alluxio.wire.FileInfo)130 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)124 ArrayList (java.util.ArrayList)120 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)119 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)114 File (java.io.File)107 FileSystem (alluxio.client.file.FileSystem)99 FileOutStream (alluxio.client.file.FileOutStream)97 AlluxioException (alluxio.exception.AlluxioException)92 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)76 InvalidPathException (alluxio.exception.InvalidPathException)68 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)63 UnderFileSystem (alluxio.underfs.UnderFileSystem)63 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)62