Search in sources :

Example 1 with ReadType

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

the class OpenFileOptionsTest method fields.

/**
   * Tests getting and setting fields.
   */
@Test
public void fields() {
    FileWriteLocationPolicy policy = new RoundRobinPolicy();
    ReadType readType = ReadType.NO_CACHE;
    OpenFileOptions options = OpenFileOptions.defaults();
    options.setReadType(readType);
    options.setCacheLocationPolicy(policy);
    options.setMaxUfsReadConcurrency(5);
    options.setUfsReadLocationPolicy((BlockLocationPolicy) policy);
    Assert.assertEquals(readType, options.getReadType());
    Assert.assertEquals(policy, options.getCacheLocationPolicy());
    Assert.assertEquals(5, options.getMaxUfsReadConcurrency());
    Assert.assertEquals(policy, options.getUfsReadLocationPolicy());
}
Also used : FileWriteLocationPolicy(alluxio.client.file.policy.FileWriteLocationPolicy) ReadType(alluxio.client.ReadType) RoundRobinPolicy(alluxio.client.file.policy.RoundRobinPolicy) Test(org.junit.Test)

Example 2 with ReadType

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

the class FileInStreamIntegrationTest method asyncCacheAfterSeek.

@Test(timeout = 10000)
public void asyncCacheAfterSeek() 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());
        URIStatus status = mFileSystem.getStatus(uri);
        is.seek(status.getBlockSizeBytes() + 1);
        is.read();
        status = mFileSystem.getStatus(uri);
        Assert.assertEquals(0, status.getInAlluxioPercentage());
        is.close();
        if (readType.isCache()) {
            CommonUtils.waitFor("Second block to be cached.", () -> {
                try {
                    URIStatus st = mFileSystem.getStatus(uri);
                    boolean achieved = true;
                    // Expect only second 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 == 1) {
                            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());
        }
    }
}
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)

Example 3 with ReadType

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

the class InStreamOptionsTest method fields.

/**
   * Tests getting and setting fields.
   */
@Test
public void fields() {
    ReadType readType = ReadType.NO_CACHE;
    FileWriteLocationPolicy policy = new RoundRobinPolicy();
    BlockLocationPolicy blockLocationPolicy = new DeterministicHashPolicy();
    InStreamOptions options = InStreamOptions.defaults();
    options.setReadType(readType);
    options.setLocationPolicy(policy);
    options.setCachePartiallyReadBlock(true);
    options.setSeekBufferSizeBytes(Constants.MB);
    options.setUfsReadLocationPolicy(blockLocationPolicy);
    options.setMaxUfsReadConcurrency(5);
    Assert.assertEquals(options.getAlluxioStorageType(), readType.getAlluxioStorageType());
    Assert.assertEquals(policy, options.getCacheLocationPolicy());
    Assert.assertTrue(options.isCachePartiallyReadBlock());
    Assert.assertEquals(Constants.MB, options.getSeekBufferSizeBytes());
    Assert.assertEquals(blockLocationPolicy, options.getUfsReadLocationPolicy());
    Assert.assertEquals(5, options.getMaxUfsReadConcurrency());
}
Also used : FileWriteLocationPolicy(alluxio.client.file.policy.FileWriteLocationPolicy) DeterministicHashPolicy(alluxio.client.block.policy.DeterministicHashPolicy) ReadType(alluxio.client.ReadType) RoundRobinPolicy(alluxio.client.file.policy.RoundRobinPolicy) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) Test(org.junit.Test)

Example 4 with ReadType

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

the class TestRunner method runTests.

/**
 * Runs combinations of tests of operation, read and write type.
 *
 * @return the number of failed tests
 */
private int runTests() throws Exception {
    mDirectory = PathUtils.concatPath(mDirectory, TEST_DIRECTORY_NAME);
    AlluxioURI testDir = new AlluxioURI(mDirectory);
    FileSystemContext fsContext = FileSystemContext.create(new InstancedConfiguration(ConfigurationUtils.defaults()));
    FileSystem fs = FileSystem.Factory.create(fsContext);
    if (fs.exists(testDir)) {
        fs.delete(testDir, DeletePOptions.newBuilder().setRecursive(true).setUnchecked(true).build());
    }
    int failed = 0;
    List<ReadType> readTypes = mReadType == null ? READ_TYPES : Lists.newArrayList(ReadType.valueOf(mReadType));
    List<WriteType> writeTypes = mWriteType == null ? WRITE_TYPES : Lists.newArrayList(WriteType.valueOf(mWriteType));
    List<OperationType> operations = mOperation == null ? Lists.newArrayList(OperationType.values()) : Lists.newArrayList(OperationType.valueOf(mOperation));
    for (ReadType readType : readTypes) {
        for (WriteType writeType : writeTypes) {
            for (OperationType opType : operations) {
                System.out.println(String.format("runTest --operation %s --readType %s --writeType %s", opType, readType, writeType));
                failed += runTest(opType, readType, writeType, fsContext);
            }
        }
    }
    if (failed > 0) {
        System.out.println("Number of failed tests: " + failed);
    }
    return failed;
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) ReadType(alluxio.client.ReadType) WriteType(alluxio.client.WriteType) FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioURI(alluxio.AlluxioURI)

Example 5 with ReadType

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

the class FileInStreamIntegrationTest method asyncCacheFirstBlock.

@Test(timeout = 10000)
public void asyncCacheFirstBlock() 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());
        is.read();
        URIStatus status = mFileSystem.getStatus(uri);
        Assert.assertEquals(0, status.getInAlluxioPercentage());
        is.close();
        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());
        }
    }
}
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