Search in sources :

Example 51 with FileInStream

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

the class RemoteReadIntegrationTest method readTest3.

/**
 * Tests the batch read API with offset and length from a remote location when the data is only in
 * the underlying storage.
 */
@Test
public void readTest3() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
        FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, k);
        FileInStream is = mFileSystem.openFile(uri, mReadNoCache);
        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();
        if (k == 0) {
            FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
        } else {
            Assert.assertFalse(mFileSystem.getStatus(uri).getInAlluxioPercentage() == 100);
        }
        is = mFileSystem.openFile(uri, mReadCache);
        ret = new byte[k];
        Assert.assertEquals(k, is.read(ret, 0, k));
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
        is.close();
        FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
        is = mFileSystem.openFile(uri, mReadCache);
        ret = new byte[k];
        Assert.assertEquals(k, is.read(ret));
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
        is.close();
        FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 52 with FileInStream

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

the class LocalCacheFileInStreamIntegrationTest method positionedRead.

@Test
public void positionedRead() throws Exception {
    AlluxioURI path = new AlluxioURI(mFilePath);
    FileSystemTestUtils.createByteFile(mFileSystem, mFilePath, WritePType.MUST_CACHE, PAGE_SIZE_BYTES);
    try (FileInStream stream = mFileSystem.openFile(path)) {
        byte[] buffer = new byte[PAGE_SIZE_BYTES / 4];
        int bytesRead = stream.positionedRead(PAGE_SIZE_BYTES / 10, buffer, 0, buffer.length);
        assertEquals(buffer.length, bytesRead);
        assertTrue(BufferUtils.equalIncreasingByteArray(PAGE_SIZE_BYTES / 10, buffer.length, buffer));
    }
    mClusterResource.get().stopWorkers();
    // verify reading whole page from local cache
    try (InputStream stream = mFileSystem.openFile(path)) {
        assertTrue(BufferUtils.equalIncreasingByteArray(PAGE_SIZE_BYTES, ByteStreams.toByteArray(stream)));
    }
}
Also used : InputStream(java.io.InputStream) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 53 with FileInStream

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

the class LocalCacheFileInStreamIntegrationTest method multiPageRead.

@Test
public void multiPageRead() throws Exception {
    AlluxioURI path = new AlluxioURI(mFilePath);
    int pageCount = 8;
    FileSystemTestUtils.createByteFile(mFileSystem, mFilePath, WritePType.MUST_CACHE, pageCount * PAGE_SIZE_BYTES);
    // position read from even pages
    try (FileInStream stream = mFileSystem.openFile(path)) {
        byte[] buffer = new byte[PAGE_SIZE_BYTES / 4];
        for (int i = 0; i < pageCount; i += 2) {
            int bytesRead = stream.positionedRead(i * PAGE_SIZE_BYTES, buffer, 0, buffer.length);
            assertEquals(buffer.length, bytesRead);
            assertTrue(BufferUtils.equalIncreasingByteArray(i * PAGE_SIZE_BYTES, buffer.length, buffer));
        }
    }
    // verify reading the files from mixed sources
    try (InputStream stream = mFileSystem.openFile(path)) {
        assertTrue(BufferUtils.equalIncreasingByteArray(pageCount * PAGE_SIZE_BYTES, ByteStreams.toByteArray(stream)));
    }
}
Also used : InputStream(java.io.InputStream) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 54 with FileInStream

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

the class AbstractFuseIntegrationTest method cp.

@Test
public void cp() throws Exception {
    String testFile = "/cpTestFile";
    String content = "Alluxio Cp Test File Content";
    File localFile = generateFileContent("/TestFileOnLocalPath", content.getBytes());
    ShellUtils.execCommand("cp", localFile.getPath(), mMountPoint + testFile);
    assertTrue(mFileSystem.exists(new AlluxioURI(testFile)));
    // Fuse release() is async
    // Cp again to make sure the first cp is completed
    String testFolder = "/cpTestFolder";
    ShellUtils.execCommand("mkdir", mMountPoint + testFolder);
    ShellUtils.execCommand("cp", mMountPoint + testFile, mMountPoint + testFolder + testFile);
    assertTrue(mFileSystem.exists(new AlluxioURI(testFolder + testFile)));
    byte[] read = new byte[content.length()];
    try (FileInStream is = mFileSystem.openFile(new AlluxioURI(testFile), OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
        is.read(read);
    }
    assertEquals(content, new String(read, "UTF8"));
}
Also used : FileInStream(alluxio.client.file.FileInStream) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 55 with FileInStream

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, OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
        byte[] res = new byte[(int) status.getLength()];
        Assert.assertEquals((int) status.getLength(), is.read(res));
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileLen, res));
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus)

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