use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class AbstractAlluxioShellTest method readContent.
protected byte[] readContent(AlluxioURI uri, int length) throws IOException, AlluxioException {
try (FileInStream tfis = mFileSystem.openFile(uri, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
byte[] read = new byte[length];
tfis.read(read);
return read;
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class CopyFromLocalCommandTest method copyFromLocalLarge.
@Test
public void copyFromLocalLarge() throws IOException, AlluxioException {
File testFile = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testFile");
testFile.createNewFile();
FileOutputStream fos = new FileOutputStream(testFile);
byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
fos.write(toWrite);
fos.close();
mFsShell.run("copyFromLocal", testFile.getAbsolutePath(), "/testFile");
Assert.assertEquals(getCommandOutput(new String[] { "copyFromLocal", testFile.getAbsolutePath(), "/testFile" }), mOutput.toString());
AlluxioURI uri = new AlluxioURI("/testFile");
URIStatus status = mFileSystem.getStatus(uri);
Assert.assertNotNull(status);
Assert.assertEquals(SIZE_BYTES, status.getLength());
try (FileInStream tfis = mFileSystem.openFile(uri, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
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 CpCommandTest method equals.
private boolean equals(AlluxioURI file1, AlluxioURI file2) throws Exception {
try (Closer closer = Closer.create()) {
OpenFileOptions openFileOptions = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
FileInStream is1 = closer.register(mFileSystem.openFile(file1, openFileOptions));
FileInStream is2 = closer.register(mFileSystem.openFile(file2, openFileOptions));
return IOUtils.contentEquals(is1, is2);
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class TieredStoreIntegrationTest method promoteBlock.
/**
* Tests the promotion of a file.
*/
@Test
public void promoteBlock() throws Exception {
AlluxioURI uri1 = new AlluxioURI("/file1");
AlluxioURI uri2 = new AlluxioURI("/file2");
AlluxioURI uri3 = new AlluxioURI("/file3");
FileSystemTestUtils.createByteFile(mFileSystem, uri1, WriteType.CACHE_THROUGH, MEM_CAPACITY_BYTES / 6);
FileSystemTestUtils.createByteFile(mFileSystem, uri2, WriteType.CACHE_THROUGH, MEM_CAPACITY_BYTES / 2);
FileSystemTestUtils.createByteFile(mFileSystem, uri3, WriteType.CACHE_THROUGH, MEM_CAPACITY_BYTES / 2);
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
AlluxioURI toPromote;
int toPromoteLen;
URIStatus file1Info = mFileSystem.getStatus(uri1);
URIStatus file2Info = mFileSystem.getStatus(uri2);
URIStatus file3Info = mFileSystem.getStatus(uri3);
// any assumptions on the eviction policy
if (file1Info.getInMemoryPercentage() < 100) {
toPromote = uri1;
toPromoteLen = (int) file1Info.getLength();
Assert.assertEquals(100, file2Info.getInMemoryPercentage());
Assert.assertEquals(100, file3Info.getInMemoryPercentage());
} else if (file2Info.getInMemoryPercentage() < 100) {
toPromote = uri2;
toPromoteLen = (int) file2Info.getLength();
Assert.assertEquals(100, file1Info.getInMemoryPercentage());
Assert.assertEquals(100, file3Info.getInMemoryPercentage());
} else {
toPromote = uri3;
toPromoteLen = (int) file3Info.getLength();
Assert.assertEquals(100, file1Info.getInMemoryPercentage());
Assert.assertEquals(100, file2Info.getInMemoryPercentage());
}
FileInStream is = mFileSystem.openFile(toPromote, OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE));
byte[] buf = new byte[toPromoteLen];
int len = is.read(buf);
is.close();
HeartbeatScheduler.schedule(HeartbeatContext.WORKER_BLOCK_SYNC);
HeartbeatScheduler.await(HeartbeatContext.WORKER_BLOCK_SYNC, 10, TimeUnit.SECONDS);
Assert.assertEquals(toPromoteLen, len);
Assert.assertEquals(100, mFileSystem.getStatus(toPromote).getInMemoryPercentage());
}
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_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));
is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
Assert.assertTrue(info.getInMemoryPercentage() == 100);
Assert.assertTrue(is.read(buf.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);
}
}
Aggregations