use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class JournalIntegrationTest method pinTestUtil.
private void pinTestUtil(URIStatus directory, URIStatus file0, URIStatus file1) throws AccessControlException, IOException, InvalidPathException, FileDoesNotExistException {
FileSystemMaster fsMaster = createFsMasterFromJournal();
FileInfo info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder")));
Assert.assertEquals(directory, new URIStatus(info));
Assert.assertTrue(info.isPinned());
info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder/file0")));
Assert.assertEquals(file0, new URIStatus(info));
Assert.assertFalse(info.isPinned());
info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder/file1")));
Assert.assertEquals(file1, new URIStatus(info));
Assert.assertTrue(info.isPinned());
fsMaster.stop();
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class FileDataManager method prepareUfsFilePath.
/**
* Prepares the destination file path of the given file id. Also creates the parent folder if it
* does not exist.
*
* @param fileId the file id
* @return the path for persistence
* @throws AlluxioException if an unexpected Alluxio exception is thrown
* @throws IOException if the folder creation fails
*/
private String prepareUfsFilePath(long fileId) throws AlluxioException, IOException {
FileInfo fileInfo = mBlockWorker.getFileInfo(fileId);
AlluxioURI alluxioPath = new AlluxioURI(fileInfo.getPath());
FileSystem fs = FileSystem.Factory.get();
URIStatus status = fs.getStatus(alluxioPath);
String ufsPath = status.getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsPath);
UnderFileSystemUtils.prepareFilePath(alluxioPath, ufsPath, fs, ufs);
return ufsPath;
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class BlockServiceHandlerIntegrationTest method lockBlock.
// Tests that lock block returns the correct path
@Test
public void lockBlock() throws Exception {
final int blockSize = (int) WORKER_CAPACITY_BYTES / 2;
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(blockSize).setWriteType(WriteType.MUST_CACHE);
FileOutStream out = mFileSystem.createFile(new AlluxioURI("/testFile"), options);
URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
final long blockId = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
out.write(BufferUtils.getIncreasingByteArray(blockSize));
out.close();
String localPath = mBlockWorkerServiceHandler.lockBlock(blockId, SESSION_ID, new LockBlockTOptions()).getBlockPath();
// The local path should exist
Assert.assertNotNull(localPath);
UnderFileSystem ufs = UnderFileSystem.Factory.get(localPath);
byte[] data = new byte[blockSize];
InputStream in = ufs.open(localPath);
int bytesRead = in.read(data);
// The data in the local file should equal the data we wrote earlier
Assert.assertEquals(blockSize, bytesRead);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(bytesRead, data));
mBlockWorkerServiceHandler.unlockBlock(blockId, SESSION_ID);
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class BlockServiceHandlerIntegrationTest method cacheBlock.
// Tests that caching a block successfully persists the block if the block exists
@Test
public void cacheBlock() throws Exception {
mFileSystem.createFile(new AlluxioURI("/testFile")).close();
URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
final int writeTier = Constants.FIRST_TIER;
final int blockSize = (int) WORKER_CAPACITY_BYTES / 10;
// Construct the block ids for the file.
final long blockId0 = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
final long blockId1 = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 1);
String filename = mBlockWorkerServiceHandler.requestBlockLocation(SESSION_ID, blockId0, blockSize, writeTier);
createBlockFile(filename, blockSize);
mBlockWorkerServiceHandler.cacheBlock(SESSION_ID, blockId0);
// The master should be immediately updated with the persisted block
Assert.assertEquals(blockSize, mBlockMasterClient.getUsedBytes());
// Attempting to cache a non existent block should throw an exception
Exception exception = null;
try {
mBlockWorkerServiceHandler.cacheBlock(SESSION_ID, blockId1);
} catch (TException e) {
exception = e;
}
Assert.assertNotNull(exception);
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class DataServerIntegrationTest method readThroughClientNonExistent.
// TODO(calvin): Make this work with the new BlockReader.
// @Test
public void readThroughClientNonExistent() throws Exception {
final int length = 10;
FileSystemTestUtils.createByteFile(mFileSystem, "/file", WriteType.MUST_CACHE, length);
BlockInfo block = getFirstBlockInfo(new AlluxioURI("/file"));
// Get the maximum block id, for use in determining a non-existent block id.
URIStatus status = mFileSystem.getStatus(new AlluxioURI("/file"));
long maxBlockId = block.getBlockId();
for (long blockId : status.getBlockIds()) {
if (blockId > maxBlockId) {
maxBlockId = blockId;
}
}
RemoteBlockReader client = RemoteBlockReader.Factory.create(FileSystemContext.INSTANCE);
block.setBlockId(maxBlockId + 1);
ByteBuffer result = readRemotely(client, block, length);
Assert.assertNull(result);
}
Aggregations