use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class IsolatedFileSystemIntegrationTest method lockBlockTest3.
@Test
public void lockBlockTest3() throws Exception {
String uniqPath = PathUtils.uniqPath();
FileInStream is;
ByteBuffer buf;
int numOfFiles = 5;
int fileSize = WORKER_CAPACITY_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.getInMemoryPercentage() == 100);
is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
int r = is.read(buf.array());
if (k < numOfFiles - 1) {
Assert.assertTrue(r != -1);
}
is.close();
}
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + numOfFiles));
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
URIStatus info = mFileSystem.getStatus(files.get(0));
Assert.assertFalse(info.getInMemoryPercentage() == 100);
for (int k = 1; k <= numOfFiles; k++) {
info = mFileSystem.getStatus(files.get(k));
Assert.assertTrue(info.getInMemoryPercentage() == 100);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class IsolatedFileSystemIntegrationTest method unlockBlockTest3.
@Test
public void unlockBlockTest3() throws Exception {
String uniqPath = PathUtils.uniqPath();
FileInStream is;
ByteBuffer buf1;
ByteBuffer buf2;
int numOfFiles = 5;
int fileSize = WORKER_CAPACITY_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.getInMemoryPercentage() == 100);
is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
buf1 = ByteBuffer.allocate((int) info.getBlockSizeBytes());
Assert.assertTrue(is.read(buf1.array()) != -1);
buf2 = ByteBuffer.allocate((int) info.getBlockSizeBytes());
is.seek(0);
Assert.assertTrue(is.read(buf2.array()) != -1);
is.close();
}
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + numOfFiles));
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
URIStatus info = mFileSystem.getStatus(files.get(0));
Assert.assertFalse(info.getInMemoryPercentage() == 100);
for (int k = 1; k <= numOfFiles; k++) {
URIStatus in = mFileSystem.getStatus(files.get(k));
Assert.assertTrue(in.getInMemoryPercentage() == 100);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class CpCommand method copyFile.
/**
* Copies a file in the Alluxio filesystem.
*
* @param srcPath the source {@link AlluxioURI} (has to be a file)
* @param dstPath the destination path in the Alluxio filesystem
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void copyFile(AlluxioURI srcPath, AlluxioURI dstPath) throws AlluxioException, IOException {
try (Closer closer = Closer.create()) {
OpenFileOptions openFileOptions = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
FileInStream is = closer.register(mFileSystem.openFile(srcPath, openFileOptions));
CreateFileOptions createFileOptions = CreateFileOptions.defaults();
FileOutStream os = closer.register(mFileSystem.createFile(dstPath, createFileOptions));
IOUtils.copy(is, os);
System.out.println("Copied " + srcPath + " to " + dstPath);
}
}
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, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
byte[] res = new byte[(int) status.getLength()];
Assert.assertEquals((int) status.getLength(), is.read(res));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileLen, res));
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class BufferedBlockInStreamIntegrationTest method readTest3.
/**
* Tests {@link alluxio.client.block.BufferedBlockInStream#read(byte[], int, int)}.
*/
@Test
public void readTest3() throws IOException, AlluxioException {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
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(path, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
Aggregations