Search in sources :

Example 31 with FileInStream

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));
}
Also used : FileOutputStream(java.io.FileOutputStream) FileInStream(alluxio.client.file.FileInStream) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 32 with FileInStream

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();
            }
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 33 with FileInStream

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;
}
Also used : FileInStream(alluxio.client.file.FileInStream)

Example 34 with FileInStream

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());
}
Also used : FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream) Test(org.junit.Test)

Example 35 with FileInStream

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();
}
Also used : FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream) Test(org.junit.Test)

Aggregations

FileInStream (alluxio.client.file.FileInStream)179 AlluxioURI (alluxio.AlluxioURI)148 Test (org.junit.Test)132 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)67 URIStatus (alluxio.client.file.URIStatus)44 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)31 FileOutStream (alluxio.client.file.FileOutStream)25 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)21 FileSystem (alluxio.client.file.FileSystem)17 ByteBuffer (java.nio.ByteBuffer)16 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)11 File (java.io.File)11 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)10 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)8 FileInfo (alluxio.wire.FileInfo)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 InstancedConfiguration (alluxio.conf.InstancedConfiguration)5 FileIncompleteException (alluxio.exception.FileIncompleteException)5