use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class RemoteReadIntegrationTest method readTest3.
/**
* Tests the batch read API with offset and length from a remote location when the data is only in
* the underlying storage.
*/
@Test
public void readTest3() 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 / 2];
Assert.assertEquals(k / 2, is.read(ret, 0, k / 2));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k / 2, ret));
is.close();
if (k == 0) {
FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
} else {
Assert.assertFalse(mFileSystem.getStatus(uri).getInAlluxioPercentage() == 100);
}
is = mFileSystem.openFile(uri, mReadCache);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
is = mFileSystem.openFile(uri, mReadCache);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class LocalCacheFileInStreamIntegrationTest method positionedRead.
@Test
public void positionedRead() throws Exception {
AlluxioURI path = new AlluxioURI(mFilePath);
FileSystemTestUtils.createByteFile(mFileSystem, mFilePath, WritePType.MUST_CACHE, PAGE_SIZE_BYTES);
try (FileInStream stream = mFileSystem.openFile(path)) {
byte[] buffer = new byte[PAGE_SIZE_BYTES / 4];
int bytesRead = stream.positionedRead(PAGE_SIZE_BYTES / 10, buffer, 0, buffer.length);
assertEquals(buffer.length, bytesRead);
assertTrue(BufferUtils.equalIncreasingByteArray(PAGE_SIZE_BYTES / 10, buffer.length, buffer));
}
mClusterResource.get().stopWorkers();
// verify reading whole page from local cache
try (InputStream stream = mFileSystem.openFile(path)) {
assertTrue(BufferUtils.equalIncreasingByteArray(PAGE_SIZE_BYTES, ByteStreams.toByteArray(stream)));
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class LocalCacheFileInStreamIntegrationTest method multiPageRead.
@Test
public void multiPageRead() throws Exception {
AlluxioURI path = new AlluxioURI(mFilePath);
int pageCount = 8;
FileSystemTestUtils.createByteFile(mFileSystem, mFilePath, WritePType.MUST_CACHE, pageCount * PAGE_SIZE_BYTES);
// position read from even pages
try (FileInStream stream = mFileSystem.openFile(path)) {
byte[] buffer = new byte[PAGE_SIZE_BYTES / 4];
for (int i = 0; i < pageCount; i += 2) {
int bytesRead = stream.positionedRead(i * PAGE_SIZE_BYTES, buffer, 0, buffer.length);
assertEquals(buffer.length, bytesRead);
assertTrue(BufferUtils.equalIncreasingByteArray(i * PAGE_SIZE_BYTES, buffer.length, buffer));
}
}
// verify reading the files from mixed sources
try (InputStream stream = mFileSystem.openFile(path)) {
assertTrue(BufferUtils.equalIncreasingByteArray(pageCount * PAGE_SIZE_BYTES, ByteStreams.toByteArray(stream)));
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class AbstractFuseIntegrationTest method cp.
@Test
public void cp() throws Exception {
String testFile = "/cpTestFile";
String content = "Alluxio Cp Test File Content";
File localFile = generateFileContent("/TestFileOnLocalPath", content.getBytes());
ShellUtils.execCommand("cp", localFile.getPath(), mMountPoint + testFile);
assertTrue(mFileSystem.exists(new AlluxioURI(testFile)));
// Fuse release() is async
// Cp again to make sure the first cp is completed
String testFolder = "/cpTestFolder";
ShellUtils.execCommand("mkdir", mMountPoint + testFolder);
ShellUtils.execCommand("cp", mMountPoint + testFile, mMountPoint + testFolder + testFile);
assertTrue(mFileSystem.exists(new AlluxioURI(testFolder + testFile)));
byte[] read = new byte[content.length()];
try (FileInStream is = mFileSystem.openFile(new AlluxioURI(testFile), OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
is.read(read);
}
assertEquals(content, new String(read, "UTF8"));
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class AbstractFileOutStreamIntegrationTest method checkFileInAlluxio.
/**
* Checks the given file exists in Alluxio storage and expects its content to be an increasing
* array of the given length.
*
* @param filePath path of the tmp file
* @param fileLen length of the file
*/
protected void checkFileInAlluxio(AlluxioURI filePath, int fileLen) throws Exception {
URIStatus status = mFileSystem.getStatus(filePath);
Assert.assertEquals(fileLen, status.getLength());
try (FileInStream is = mFileSystem.openFile(filePath, OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
byte[] res = new byte[(int) status.getLength()];
Assert.assertEquals((int) status.getLength(), is.read(res));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileLen, res));
}
}
Aggregations