use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class UnderFileSystemBlockInStreamIntegrationTest method seek.
/**
* Tests {@link UnderFileSystemBlockInStream#seek(long)}.
*/
@Test
public void seek() 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(0, is.read());
is.seek(k / 3);
Assert.assertEquals(k / 3, is.read());
is.seek(k / 2);
Assert.assertEquals(k / 2, is.read());
is.seek(k / 4);
Assert.assertEquals(k / 4, is.read());
is.close();
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method seekExceptionTest1.
/**
* Tests {@link RemoteBlockInStream#seek(long)}. Validate the expected exception for seeking a
* negative position.
*/
@Test
public void seekExceptionTest1() throws Exception {
mThrown.expect(IllegalArgumentException.class);
mThrown.expectMessage(String.format(PreconditionMessage.ERR_SEEK_NEGATIVE.toString(), -1));
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);
try (FileInStream is = mFileSystem.openFile(uri, mReadNoCache)) {
is.seek(-1);
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readEndOfFile.
/**
* Tests {@link FileInStream#read(byte[], int, int)} for end of file.
*/
@Test
public void readEndOfFile() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
String filename = sTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
try (FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
byte[] ret = new byte[k / 2];
int readBytes = is.read(ret, 0, k / 2);
while (readBytes != -1) {
readBytes = is.read(ret);
Assert.assertTrue(0 != readBytes);
}
Assert.assertEquals(-1, readBytes);
}
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readTest3.
/**
* Tests {@link FileInStream#read(byte[], int, int)}.
*/
@Test
public void readTest3() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
String filename = sTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[k / 2];
Assert.assertEquals(k / 2, is.read(ret, 0, k / 2));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k / 2, ret));
is.close();
is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readTest1.
/**
* Tests {@link FileInStream#read()} across block boundary.
*/
@Test
public void readTest1() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
String filename = sTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[k];
int value = is.read();
int cnt = 0;
while (value != -1) {
Assert.assertTrue(value >= 0);
Assert.assertTrue(value < 256);
ret[cnt++] = (byte) value;
value = is.read();
}
Assert.assertEquals(cnt, k);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
value = is.read();
cnt = 0;
while (value != -1) {
Assert.assertTrue(value >= 0);
Assert.assertTrue(value < 256);
ret[cnt++] = (byte) value;
value = is.read();
}
Assert.assertEquals(cnt, k);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
Aggregations