use of alluxio.client.file.FileInStream in project zeppelin by apache.
the class AlluxioInterpreterTest method copyFromLocalLargeTest.
@Test
public void copyFromLocalLargeTest() 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();
InterpreterResult output = alluxioInterpreter.interpret("copyFromLocal " + testFile.getAbsolutePath() + " /testFile", null);
Assert.assertEquals("Copied " + testFile.getAbsolutePath() + " to /testFile\n\n", output.message().get(0).getData());
long fileLength = fs.getStatus(new AlluxioURI("/testFile")).getLength();
Assert.assertEquals(SIZE_BYTES, fileLength);
FileInStream fStream = fs.openFile(new AlluxioURI("/testFile"));
byte[] read = new byte[SIZE_BYTES];
fStream.read(read);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
}
use of alluxio.client.file.FileInStream in project SSM by Intel-bigdata.
the class LoadAction method loadInternal.
// load file into memory recursively
private void loadInternal(AlluxioURI path) throws Exception {
URIStatus status = alluxioFs.getStatus(path);
if (status.isFolder()) {
List<URIStatus> statuses = alluxioFs.listStatus(path);
for (URIStatus uriStatus : statuses) {
AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
loadInternal(newPath);
}
} else {
if (status.getInMemoryPercentage() == 100) {
// The file has already been fully loaded into Alluxio memory.
return;
}
FileInStream in = null;
try {
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE);
in = alluxioFs.openFile(path, options);
byte[] buf = new byte[8 * Constants.MB];
while (in.read(buf) != -1) {
}
} catch (Exception e) {
exceptionMessages.add(e.getMessage());
} finally {
if (null != in) {
in.close();
}
}
}
}
use of alluxio.client.file.FileInStream in project SSM by Intel-bigdata.
the class SmartAlluxioBaseFileSystem method openFile.
@Override
public FileInStream openFile(AlluxioURI uri, OpenFileOptions options) throws FileDoesNotExistException, IOException, AlluxioException {
FileInStream fis = super.openFile(uri, options);
reportFileAccessEvent(uri.getPath());
return fis;
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class StreamCacheTest method size.
@Test
public void size() throws Exception {
StreamCache streamCache = new StreamCache(Constants.HOUR_MS);
FileInStream is = mock(FileInStream.class);
FileOutStream os = mock(FileOutStream.class);
Assert.assertEquals(0, streamCache.size());
int isId = streamCache.put(is);
Assert.assertEquals(1, streamCache.size());
int osId = streamCache.put(os);
Assert.assertEquals(2, streamCache.size());
streamCache.invalidate(isId);
Assert.assertEquals(1, streamCache.size());
streamCache.invalidate(osId);
Assert.assertEquals(0, streamCache.size());
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class StreamCacheTest method operations.
@Test
public void operations() throws Exception {
StreamCache streamCache = new StreamCache(Constants.HOUR_MS);
FileInStream is = mock(FileInStream.class);
FileOutStream os = mock(FileOutStream.class);
Integer isId = streamCache.put(is);
Integer osId = streamCache.put(os);
Assert.assertSame(is, streamCache.getInStream(isId));
Assert.assertNull(streamCache.getInStream(osId));
Assert.assertNull(streamCache.getOutStream(isId));
Assert.assertSame(os, streamCache.getOutStream(osId));
Assert.assertSame(is, streamCache.invalidate(isId));
Assert.assertSame(os, streamCache.invalidate(osId));
Assert.assertNull(streamCache.invalidate(isId));
Assert.assertNull(streamCache.invalidate(osId));
Assert.assertNull(streamCache.getInStream(isId));
Assert.assertNull(streamCache.getOutStream(osId));
verify(is).close();
verify(os).close();
}
Aggregations