Search in sources :

Example 16 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class BufferedBlockInStreamIntegrationTest method skip.

/**
 * Tests {@link alluxio.client.block.BufferedBlockInStream#skip(long)}.
 */
@Test
public void skip() throws IOException, AlluxioException {
    for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
        for (CreateFilePOptions op : getOptionSet()) {
            AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
            Assert.assertEquals(k / 2, is.skip(k / 2));
            Assert.assertEquals(k / 2, is.read());
            is.close();
            is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
            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();
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 17 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class BufferedBlockInStreamIntegrationTest method getOptionSet.

private static List<CreateFilePOptions> getOptionSet() {
    List<CreateFilePOptions> ret = new ArrayList<>(3);
    CreateFilePOptions optionsDefault = CreateFilePOptions.getDefaultInstance();
    ret.add(optionsDefault.toBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build());
    ret.add(optionsDefault.toBuilder().setWriteType(WritePType.MUST_CACHE).setRecursive(true).build());
    ret.add(optionsDefault.toBuilder().setWriteType(WritePType.THROUGH).setRecursive(true).build());
    return ret;
}
Also used : ArrayList(java.util.ArrayList) CreateFilePOptions(alluxio.grpc.CreateFilePOptions)

Example 18 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method positionedReadWithoutCaching.

@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_FILE_READ_TYPE_DEFAULT, "NO_CACHE" })
public void positionedReadWithoutCaching() throws Exception {
    for (CreateFilePOptions op : getOptionSet()) {
        String filename = mTestPath + "/file_" + MIN_LEN + "_" + op.hashCode();
        AlluxioURI uri = new AlluxioURI(filename);
        FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
        byte[] ret = new byte[DELTA - 1];
        Assert.assertEquals(DELTA - 1, is.positionedRead(MIN_LEN - DELTA + 1, ret, 0, DELTA));
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MIN_LEN - DELTA + 1, DELTA - 1, ret));
        is.close();
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 19 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method positionedReadWithLargeThreshold.

@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_FILE_SEQUENTIAL_PREAD_THRESHOLD, "700KB" })
public void positionedReadWithLargeThreshold() throws Exception {
    List<CreateFilePOptions> optionSet = new ArrayList<>(2);
    optionSet.add(mWriteBoth);
    optionSet.add(mWriteUnderStore);
    for (CreateFilePOptions op : optionSet) {
        String filename = mTestPath + "/file_" + MIN_LEN + "_" + op.hashCode();
        AlluxioURI uri = new AlluxioURI(filename);
        try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
            byte[] ret = new byte[DELTA - 1];
            Assert.assertEquals(DELTA - 1, is.positionedRead(MIN_LEN - DELTA + 1, ret, 0, DELTA));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MIN_LEN - DELTA + 1, DELTA - 1, ret));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 20 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method skip.

/**
 * Tests {@link FileInStream#skip(long)}.
 */
@Test
public void skip() throws Exception {
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFilePOptions op : getOptionSet()) {
            String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
            AlluxioURI uri = new AlluxioURI(filename);
            FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            Assert.assertEquals(k / 2, is.skip(k / 2));
            Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 2), is.read());
            Assert.assertEquals(k / 3, is.skip(k / 3));
            // position is k / 2 (skip) + k / 3 (skip) + 1 (read)
            Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 2 + k / 3 + 1), is.read());
            is.close();
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

CreateFilePOptions (alluxio.grpc.CreateFilePOptions)68 AlluxioURI (alluxio.AlluxioURI)61 Test (org.junit.Test)49 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)36 FileInStream (alluxio.client.file.FileInStream)27 FileOutStream (alluxio.client.file.FileOutStream)16 URIStatus (alluxio.client.file.URIStatus)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FileSystem (alluxio.client.file.FileSystem)4 AlluxioException (alluxio.exception.AlluxioException)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)4 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)4 IOException (java.io.IOException)4 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 ArrayList (java.util.ArrayList)3 ConfigurationRule (alluxio.ConfigurationRule)2 BlockMaster (alluxio.master.block.BlockMaster)2 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2