use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readMultiBlockFile.
/**
* Tests that reading a file consisting of more than one block from the underfs works.
*/
@Test
public void readMultiBlockFile() throws Exception {
String uniqPath = PathUtils.uniqPath();
int blockSizeByte = 10;
int numBlocks = 10;
AlluxioURI uri = new AlluxioURI(uniqPath);
FileOutStream os = mFileSystem.createFile(uri, mWriteUnderStore);
for (int i = 0; i < numBlocks; i++) {
for (int j = 0; j < blockSizeByte; j++) {
os.write((byte) (i * blockSizeByte + j));
}
}
os.close();
FileInStream is = mFileSystem.openFile(uri, mReadCache);
for (int i = 0; i < blockSizeByte * numBlocks; i++) {
Assert.assertEquals((byte) i, is.read());
}
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method incompleteFileReadCancelsRecache.
/**
* Tests that not reading a file the whole way through then closing it will cause it to not
* recache.
*/
@Test
public void incompleteFileReadCancelsRecache() throws Exception {
String uniqPath = PathUtils.uniqPath();
AlluxioURI uri = new AlluxioURI(uniqPath);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, 2);
FileInStream is = mFileSystem.openFile(uri, mReadNoCache);
Assert.assertEquals(0, is.read());
is.close();
Assert.assertFalse(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
is = mFileSystem.openFile(uri, mReadNoCache);
is.close();
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest2.
/**
* Tests {@link RemoteBlockInStream#read(byte[])}. Read from underfs.
*/
@Test
public void readTest2() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, k);
FileInStream is = mFileSystem.openFile(uri, mReadNoCache);
byte[] ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
if (k == 0) {
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
} else {
Assert.assertFalse(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
is = mFileSystem.openFile(uri, mReadCache);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
is = mFileSystem.openFile(uri, mReadCache);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest7.
/**
* Tests {@link RemoteBlockInStream#read(byte[])}. Read from underfs.
*/
@Test
public void readTest7() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, k);
FileInStream is = mFileSystem.openFile(uri, mReadNoCache);
byte[] ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
Assert.assertEquals(-1, is.read(ret));
is.close();
Assert.assertFalse(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method skip.
/**
* Tests {@link RemoteBlockInStream#skip(long)}.
*/
@Test
public void skip() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, k);
FileInStream is = mFileSystem.openFile(uri, mReadCache);
Assert.assertEquals(k / 2, is.skip(k / 2));
Assert.assertEquals(k / 2, is.read());
is.close();
Assert.assertEquals(100, mFileSystem.getStatus(uri).getInMemoryPercentage());
if (k >= 3) {
is = mFileSystem.openFile(uri, mReadCache);
int t = k / 3;
Assert.assertEquals(t, is.skip(t));
Assert.assertEquals(t, is.read());
Assert.assertEquals(t, is.skip(t));
Assert.assertEquals(2 * t + 1, is.read());
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
}
Aggregations