Search in sources :

Example 6 with ReadType

use of alluxio.client.ReadType in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method asyncCacheFirstBlockPRead.

@Test(timeout = 10000)
public void asyncCacheFirstBlockPRead() throws Exception {
    String filename = mTestPath + "/file_" + MAX_LEN + "_" + mWriteUnderStore.hashCode();
    AlluxioURI uri = new AlluxioURI(filename);
    for (ReadType readType : ReadType.values()) {
        mFileSystem.free(uri);
        CommonUtils.waitFor("No in-Alluxio data left from previous iteration.", () -> {
            try {
                URIStatus st = mFileSystem.getStatus(uri);
                return st.getInAlluxioPercentage() == 0;
            } catch (Exception e) {
                return false;
            }
        });
        FileInStream is = mFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(readType.toProto()).build());
        // Positioned reads trigger async caching after reading and do not need to wait for a close
        // or a block boundary to be crossed.
        URIStatus status = mFileSystem.getStatus(uri);
        Assert.assertEquals(0, status.getInAlluxioPercentage());
        is.positionedRead(BLOCK_SIZE / 2, new byte[1], 0, 1);
        if (readType.isCache()) {
            CommonUtils.waitFor("First block to be cached.", () -> {
                try {
                    URIStatus st = mFileSystem.getStatus(uri);
                    boolean achieved = true;
                    // Expect only first block to be cached, other blocks should be empty in Alluxio
                    for (int i = 0; i < st.getFileBlockInfos().size(); i++) {
                        FileBlockInfo info = st.getFileBlockInfos().get(i);
                        if (i == 0) {
                            achieved = achieved && !info.getBlockInfo().getLocations().isEmpty();
                        } else {
                            achieved = achieved && info.getBlockInfo().getLocations().isEmpty();
                        }
                    }
                    return achieved;
                } catch (Exception e) {
                    return false;
                }
            });
        } else {
            Thread.sleep(1000);
            status = mFileSystem.getStatus(uri);
            Assert.assertEquals(0, status.getInAlluxioPercentage());
        }
        is.close();
    }
}
Also used : ReadType(alluxio.client.ReadType) FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) ExpectedException(org.junit.rules.ExpectedException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

ReadType (alluxio.client.ReadType)6 Test (org.junit.Test)5 AlluxioURI (alluxio.AlluxioURI)4 FileInStream (alluxio.client.file.FileInStream)3 URIStatus (alluxio.client.file.URIStatus)3 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)3 FileBlockInfo (alluxio.wire.FileBlockInfo)3 ExpectedException (org.junit.rules.ExpectedException)3 FileWriteLocationPolicy (alluxio.client.file.policy.FileWriteLocationPolicy)2 RoundRobinPolicy (alluxio.client.file.policy.RoundRobinPolicy)2 WriteType (alluxio.client.WriteType)1 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)1 DeterministicHashPolicy (alluxio.client.block.policy.DeterministicHashPolicy)1 FileSystem (alluxio.client.file.FileSystem)1 FileSystemContext (alluxio.client.file.FileSystemContext)1 InstancedConfiguration (alluxio.conf.InstancedConfiguration)1