use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class BufferedBlockInStreamIntegrationTest method readTest1.
/**
* Tests {@link alluxio.client.block.BufferedBlockInStream#read()}.
*/
@Test
public void readTest1() throws IOException, AlluxioException {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
for (int i = 0; i < 2; i++) {
FileInStream is = sFileSystem.openFile(path, 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();
}
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class BufferedBlockInStreamIntegrationTest method readTest2.
/**
* Tests {@link alluxio.client.block.BufferedBlockInStream#read(byte[])}.
*/
@Test
public void readTest2() throws IOException, AlluxioException {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
use of alluxio.grpc.CreateFilePOptions 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 (CreateFilePOptions op : getOptionSet()) {
String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
try (FileInStream is = mFileSystem.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.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readTest1.
/**
* Tests {@link FileInStream#read()} across block boundary.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_STREAMING_READER_CHUNK_SIZE_BYTES, "64KB" })
public void readTest1() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = mFileSystem.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 = mFileSystem.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();
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method seekExceptionTest1.
/**
* Tests {@link FileInStream#seek(long)}. Validate the expected exception for seeking a negative
* position.
*/
@Test
public void seekExceptionTest1() throws Exception {
mThrown.expect(IllegalArgumentException.class);
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
is.seek(-1);
}
}
}
}
Aggregations