use of alluxio.client.file.options.OpenFileOptions in project alluxio by Alluxio.
the class TieredStoreIntegrationTest method deleteWhileRead.
/**
* Tests that deletes go through despite failing initially due to concurrent read.
*/
@Test
public void deleteWhileRead() throws Exception {
HeartbeatScheduler.await(HeartbeatContext.WORKER_BLOCK_SYNC, 10, TimeUnit.SECONDS);
AlluxioURI file = new AlluxioURI("/test1");
FileSystemTestUtils.createByteFile(mFileSystem, file, WriteType.MUST_CACHE, MEM_CAPACITY_BYTES);
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
Assert.assertEquals(100, mFileSystem.getStatus(file).getInMemoryPercentage());
// Open the file
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.CACHE);
FileInStream in = mFileSystem.openFile(file, options);
Assert.assertEquals(0, in.read());
// Delete the file
mFileSystem.delete(file);
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
// After the delete, the master should no longer serve the file
Assert.assertFalse(mFileSystem.exists(file));
// However, the previous read should still be able to read it as the data still exists
byte[] res = new byte[MEM_CAPACITY_BYTES];
Assert.assertEquals(MEM_CAPACITY_BYTES - 1, in.read(res, 1, MEM_CAPACITY_BYTES - 1));
res[0] = 0;
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MEM_CAPACITY_BYTES, res));
in.close();
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
// After the file is closed, the master's delete should go through and new files can be created
AlluxioURI newFile = new AlluxioURI("/test2");
FileSystemTestUtils.createByteFile(mFileSystem, newFile, WriteType.MUST_CACHE, MEM_CAPACITY_BYTES);
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
Assert.assertEquals(100, mFileSystem.getStatus(newFile).getInMemoryPercentage());
}
use of alluxio.client.file.options.OpenFileOptions in project alluxio by Alluxio.
the class BaseFileSystemTest method openFile.
/**
* Tests for the {@link BaseFileSystem#openFile(AlluxioURI, OpenFileOptions)} method to
* complete successfully.
*/
@Test
public void openFile() throws Exception {
AlluxioURI file = new AlluxioURI("/file");
URIStatus status = new URIStatus(new FileInfo());
Mockito.when(mFileSystemMasterClient.getStatus(file)).thenReturn(status);
OpenFileOptions openOptions = OpenFileOptions.defaults();
mFileSystem.openFile(file, openOptions);
Mockito.verify(mFileSystemMasterClient).getStatus(file);
}
Aggregations