use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class FileOutStreamAsyncWriteIntegrationTest method asyncWriteEmptyFile.
@Test
public void asyncWriteEmptyFile() throws Exception {
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH)).close();
// check the file is completed but not persisted
URIStatus status = mFileSystem.getStatus(filePath);
Assert.assertNotEquals(PersistenceState.PERSISTED, status.getPersistenceState());
Assert.assertTrue(status.isCompleted());
IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
status = mFileSystem.getStatus(filePath);
Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
checkFileInAlluxio(filePath, 0);
checkFileInUnderStorage(filePath, 0);
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class AbstractFileOutStreamIntegrationTest method checkFileInUnderStorage.
/**
* Checks the given file exists in under storage and expects its content to be an increasing
* array of the given length.
*
* @param filePath path of the tmp file
* @param fileLen length of the file
*/
protected void checkFileInUnderStorage(AlluxioURI filePath, int fileLen) throws Exception {
URIStatus status = mFileSystem.getStatus(filePath);
String checkpointPath = status.getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(checkpointPath);
try (InputStream is = ufs.open(checkpointPath)) {
byte[] res = new byte[(int) status.getLength()];
String underFSClass = UnderFileSystemCluster.getUnderFSClass();
if ((LocalMiniDFSCluster.class.getName().equals(underFSClass)) && 0 == res.length) {
// Returns -1 for zero-sized byte array to indicate no more bytes available here.
Assert.assertEquals(-1, is.read(res));
} else {
Assert.assertEquals((int) status.getLength(), is.read(res));
}
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileLen, res));
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class FileSystemIntegrationTest method renameFileTest2.
@Test
public void renameFileTest2() throws Exception {
AlluxioURI uniqUri = new AlluxioURI(PathUtils.uniqPath());
mFileSystem.createFile(uniqUri, mWriteBoth).close();
URIStatus f = mFileSystem.getStatus(uniqUri);
long oldFileId = f.getFileId();
mFileSystem.rename(uniqUri, uniqUri);
Assert.assertEquals(oldFileId, mFileSystem.getStatus(uniqUri).getFileId());
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class DuCommand method getFileOrFolderSize.
/**
* Calculates the size of a path (file or folder) specified by a {@link AlluxioURI}.
*
* @param fs a {@link FileSystem}
* @param path a {@link AlluxioURI} denoting the path
* @return total size of the specified path in byte
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private long getFileOrFolderSize(FileSystem fs, AlluxioURI path) throws AlluxioException, IOException {
long sizeInBytes = 0;
List<URIStatus> statuses = fs.listStatus(path);
for (URIStatus status : statuses) {
if (status.isFolder()) {
AlluxioURI subFolder = new AlluxioURI(status.getPath());
sizeInBytes += getFileOrFolderSize(fs, subFolder);
} else {
sizeInBytes += status.getLength();
}
}
return sizeInBytes;
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class StatCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
if (status.isFolder()) {
System.out.println(path + " is a directory path.");
System.out.println(status);
} else {
System.out.println(path + " is a file path.");
System.out.println(status);
System.out.println("Containing the following blocks: ");
AlluxioBlockStore blockStore = AlluxioBlockStore.create();
for (long blockId : status.getBlockIds()) {
System.out.println(blockStore.getInfo(blockId));
}
}
}
Aggregations