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)));
}
}
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());
}
}
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
}
}
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());
}
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());
}
Aggregations