use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.
the class LocalBlockInStreamIntegrationTest method beforeClass.
@BeforeClass
public static final void beforeClass() throws Exception {
sFileSystem = sLocalAlluxioClusterResource.get().getClient();
sWriteBoth = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
sWriteAlluxio = CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE);
sReadCachePromote = OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE);
sReadNoCache = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
sTestPath = PathUtils.uniqPath();
// Create files of varying size and write type to later read from
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileSystemTestUtils.createByteFile(sFileSystem, path, op, k);
}
}
}
use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.
the class LocalBlockInStreamIntegrationTest method readTest3.
/**
* Tests {@link alluxio.client.block.LocalBlockInStream#read(byte[], int, int)}.
*/
@Test
public void readTest3() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileInStream is = sFileSystem.openFile(uri, sReadNoCache);
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, sReadCachePromote);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(sFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
}
use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.
the class LocalBlockInStreamIntegrationTest method seekExceptionTest2.
/**
* Tests {@link alluxio.client.block.LocalBlockInStream#seek(long)}. Validate the expected
* exception for seeking a position that is past buffer limit.
*/
@Test
public void seekExceptionTest2() throws Exception {
mThrown.expect(IllegalArgumentException.class);
mThrown.expectMessage(String.format(PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), 1));
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
try (FileInStream is = sFileSystem.openFile(uri, sReadNoCache)) {
is.seek(k + 1);
}
}
}
}
use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.
the class LocalBlockInStreamIntegrationTest method readTest2.
/**
* Tests {@link alluxio.client.block.LocalBlockInStream#read(byte[])}.
*/
@Test
public void readTest2() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileInStream is = sFileSystem.openFile(uri, sReadNoCache);
byte[] ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
is = sFileSystem.openFile(uri, sReadCachePromote);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(sFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
}
use of alluxio.client.file.options.CreateFileOptions 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);
}
}
}
}
Aggregations