Search in sources :

Example 46 with FileInStream

use of alluxio.client.file.FileInStream in project alluxio by Alluxio.

the class PathConfigurationIntegrationTest method checkCacheStatus.

private void checkCacheStatus(String path, boolean shouldCache) throws Exception {
    AlluxioURI uri = new AlluxioURI(path);
    Assert.assertEquals(0, mFileSystem.getStatus(uri).getInMemoryPercentage());
    try (FileInStream is = mFileSystem.openFile(uri)) {
        IOUtils.copy(is, ByteStreams.nullOutputStream());
    }
    FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, shouldCache ? 100 : 0);
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI)

Example 47 with FileInStream

use of alluxio.client.file.FileInStream in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method openFile.

@Test
public void openFile() throws IOException, AlluxioException {
    AlluxioURI fileUri = new AlluxioURI(FILE_PATH);
    FileInStream inStream = mFileSystem.openFile(fileUri);
    Assert.assertNotNull(inStream);
    inStream.close();
    fileUri = new AlluxioURI(SUB_FILE_PATH);
    inStream = mFileSystem.openFile(fileUri);
    Assert.assertNotNull(inStream);
    inStream.close();
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 48 with FileInStream

use of alluxio.client.file.FileInStream in project alluxio by Alluxio.

the class RemoteReadIntegrationTest method incompleteFileReadCancelsRecache.

/**
 * Tests that not reading a file the whole way through then closing it will cause it to not
 * recache.
 */
@Test
public void incompleteFileReadCancelsRecache() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    AlluxioURI uri = new AlluxioURI(uniqPath);
    FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, 2);
    FileInStream is = mFileSystem.openFile(uri, mReadNoCache);
    Assert.assertEquals(0, is.read());
    is.close();
    Assert.assertFalse(mFileSystem.getStatus(uri).getInAlluxioPercentage() == 100);
    is = mFileSystem.openFile(uri, mReadNoCache);
    is.close();
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 49 with FileInStream

use of alluxio.client.file.FileInStream in project alluxio by Alluxio.

the class RemoteReadIntegrationTest method skip.

/**
 * Tests skipping through data which is in a remote location.
 */
@Test
public void skip() 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(k / 2, is.skip(k / 2));
        Assert.assertEquals(k / 2, is.read());
        is.close();
        IntegrationTestUtils.waitForFileCached(mFileSystem, uri, 1000);
        if (k >= 3) {
            is = mFileSystem.openFile(uri, mReadCache);
            int t = k / 3;
            Assert.assertEquals(t, is.skip(t));
            Assert.assertEquals(t, is.read());
            Assert.assertEquals(t, is.skip(t));
            Assert.assertEquals(2 * t + 1, is.read());
            is.close();
            IntegrationTestUtils.waitForFileCached(mFileSystem, uri, 1000);
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 50 with FileInStream

use of alluxio.client.file.FileInStream in project alluxio by Alluxio.

the class RemoteReadIntegrationTest method heartbeat1.

/**
 * Tests the read API from a remote location after a delay longer than the netty heartbeat
 * timeout.
 */
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.WORKER_NETWORK_KEEPALIVE_TIME_MS, "1sec" })
public void heartbeat1() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    int size = 100;
    AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + size);
    FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, size);
    FileInStream is = mFileSystem.openFile(uri, mReadNoCache);
    CommonUtils.sleepMs(2000);
    byte[] ret = new byte[size];
    Assert.assertEquals(size, is.read(ret));
    Assert.assertTrue(BufferUtils.equalIncreasingByteArray(size, ret));
    Assert.assertEquals(-1, is.read(ret));
    is.close();
    Assert.assertFalse(mFileSystem.getStatus(uri).getInAlluxioPercentage() == 100);
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) 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