use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class BufferedBlockInStreamIntegrationTest method skip.
/**
* Tests {@link alluxio.client.block.BufferedBlockInStream#skip(long)}.
*/
@Test
public void skip() throws IOException, AlluxioException {
for (int k = MIN_LEN + DELTA; 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));
Assert.assertEquals(k / 2, is.skip(k / 2));
Assert.assertEquals(k / 2, is.read());
is.close();
is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
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();
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method positionedReadWithoutCaching.
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_FILE_READ_TYPE_DEFAULT, "NO_CACHE" })
public void positionedReadWithoutCaching() throws Exception {
for (CreateFilePOptions op : getOptionSet()) {
String filename = mTestPath + "/file_" + MIN_LEN + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[DELTA - 1];
Assert.assertEquals(DELTA - 1, is.positionedRead(MIN_LEN - DELTA + 1, ret, 0, DELTA));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MIN_LEN - DELTA + 1, DELTA - 1, ret));
is.close();
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method positionedReadWithLargeThreshold.
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_FILE_SEQUENTIAL_PREAD_THRESHOLD, "700KB" })
public void positionedReadWithLargeThreshold() throws Exception {
List<CreateFilePOptions> optionSet = new ArrayList<>(2);
optionSet.add(mWriteBoth);
optionSet.add(mWriteUnderStore);
for (CreateFilePOptions op : optionSet) {
String filename = mTestPath + "/file_" + MIN_LEN + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
byte[] ret = new byte[DELTA - 1];
Assert.assertEquals(DELTA - 1, is.positionedRead(MIN_LEN - DELTA + 1, ret, 0, DELTA));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MIN_LEN - DELTA + 1, DELTA - 1, ret));
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method skip.
/**
* Tests {@link FileInStream#skip(long)}.
*/
@Test
public void skip() 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));
Assert.assertEquals(k / 2, is.skip(k / 2));
Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 2), is.read());
Assert.assertEquals(k / 3, is.skip(k / 3));
// position is k / 2 (skip) + k / 3 (skip) + 1 (read)
Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 2 + k / 3 + 1), is.read());
is.close();
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method asyncCacheAfterSeek.
@Test(timeout = 10000)
public void asyncCacheAfterSeek() throws Exception {
String filename = mTestPath + "/file_" + MAX_LEN + "_" + mWriteUnderStore.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
for (ReadType readType : ReadType.values()) {
mFileSystem.free(uri);
CommonUtils.waitFor("No in-Alluxio data left from previous iteration.", () -> {
try {
URIStatus st = mFileSystem.getStatus(uri);
return st.getInAlluxioPercentage() == 0;
} catch (Exception e) {
return false;
}
});
FileInStream is = mFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(readType.toProto()).build());
URIStatus status = mFileSystem.getStatus(uri);
is.seek(status.getBlockSizeBytes() + 1);
is.read();
status = mFileSystem.getStatus(uri);
Assert.assertEquals(0, status.getInAlluxioPercentage());
is.close();
if (readType.isCache()) {
CommonUtils.waitFor("Second block to be cached.", () -> {
try {
URIStatus st = mFileSystem.getStatus(uri);
boolean achieved = true;
// Expect only second block to be cached, other blocks should be empty in Alluxio
for (int i = 0; i < st.getFileBlockInfos().size(); i++) {
FileBlockInfo info = st.getFileBlockInfos().get(i);
if (i == 1) {
achieved = achieved && !info.getBlockInfo().getLocations().isEmpty();
} else {
achieved = achieved && info.getBlockInfo().getLocations().isEmpty();
}
}
return achieved;
} catch (Exception e) {
return false;
}
});
} else {
Thread.sleep(1000);
status = mFileSystem.getStatus(uri);
Assert.assertEquals(0, status.getInAlluxioPercentage());
}
}
}
Aggregations