use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class AbstractFileSystemShellTest method checkFilePersisted.
/**
* Checks whether the given file is actually persisted by freeing it, then
* reading it and comparing it against the expected byte array.
*
* @param uri The uri to persist
* @param size The size of the file
*/
protected void checkFilePersisted(AlluxioURI uri, int size) throws Exception {
assertTrue(sFileSystem.getStatus(uri).isPersisted());
CommonUtils.waitFor("file to be completely freed", () -> {
try {
// Call free inside the loop in case a worker reports blocks after the call to free.
sFileSystem.free(uri);
return sFileSystem.getStatus(uri).getInAlluxioPercentage() == 0;
} catch (Exception e) {
throw new RuntimeException(e);
}
}, WaitForOptions.defaults().setTimeoutMs(10000));
try (FileInStream tfis = sFileSystem.openFile(uri)) {
byte[] actual = new byte[size];
tfis.read(actual);
assertArrayEquals(BufferUtils.getIncreasingByteArray(size), actual);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class CopyFromLocalCommandIntegrationTest method copyFromLocalLarge.
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.WORKER_NETWORK_NETTY_WATERMARK_HIGH, "1.0" })
public void copyFromLocalLarge() throws IOException, AlluxioException {
File testFile = new File(sLocalAlluxioCluster.getAlluxioHome() + "/testFile");
testFile.createNewFile();
FileOutputStream fos = new FileOutputStream(testFile);
byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
fos.write(toWrite);
fos.close();
sFsShell.run("copyFromLocal", testFile.getAbsolutePath(), "/testFile");
Assert.assertEquals(getCommandOutput(new String[] { "copyFromLocal", testFile.getAbsolutePath(), "/testFile" }), mOutput.toString());
AlluxioURI uri = new AlluxioURI("/testFile");
URIStatus status = sFileSystem.getStatus(uri);
Assert.assertNotNull(status);
Assert.assertEquals(SIZE_BYTES, status.getLength());
try (FileInStream tfis = sFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
byte[] read = new byte[SIZE_BYTES];
tfis.read(read);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class UnderStorageReadIntegrationTest method seek.
/**
* Tests seeking through files only in the underfs.
*/
@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 IsolatedFileSystemIntegrationTest method lockBlockTest2.
@Test
public void lockBlockTest2() throws Exception {
String uniqPath = PathUtils.uniqPath();
FileInStream is;
ByteBuffer buf;
int numOfFiles = 5;
int fileSize = WORKER_UNRESERVED_BYTES / numOfFiles;
List<AlluxioURI> files = new ArrayList<>();
for (int k = 0; k < numOfFiles; k++) {
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + k));
}
for (int k = 0; k < numOfFiles; k++) {
URIStatus info = mFileSystem.getStatus(files.get(k));
Assert.assertTrue(info.getInAlluxioPercentage() == 100);
is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
Assert.assertTrue(is.read(buf.array()) != -1);
is.close();
}
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + numOfFiles));
Assert.assertEquals(numOfFiles, numCached(files));
Assert.assertEquals(100, mFileSystem.getStatus(files.get(numOfFiles)).getInAlluxioPercentage());
Assert.assertNotEquals(100, mFileSystem.getStatus(files.get(0)).getInAlluxioPercentage());
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class IsolatedFileSystemIntegrationTest method unlockBlockTest1.
@Test
public void unlockBlockTest1() throws Exception {
String uniqPath = PathUtils.uniqPath();
FileInStream is;
ByteBuffer buf;
int numOfFiles = 5;
int fileSize = WORKER_UNRESERVED_BYTES / numOfFiles;
List<AlluxioURI> files = new ArrayList<>();
for (int k = 0; k < numOfFiles; k++) {
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + k));
}
for (int k = 0; k < numOfFiles; k++) {
URIStatus info = mFileSystem.getStatus(files.get(k));
is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
Assert.assertTrue(info.getInAlluxioPercentage() == 100);
Assert.assertTrue(is.read(buf.array()) != -1);
is.close();
}
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + numOfFiles));
Assert.assertEquals(numOfFiles, numCached(files));
Assert.assertEquals(100, mFileSystem.getStatus(files.get(numOfFiles)).getInAlluxioPercentage());
Assert.assertNotEquals(100, mFileSystem.getStatus(files.get(0)).getInAlluxioPercentage());
}
Aggregations