Search in sources :

Example 36 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions 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 (CreateFileOptions 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 : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 37 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method beforeClass.

@BeforeClass
public static final void beforeClass() throws Exception {
    sFileSystem = sLocalAlluxioClusterResource.get().getClient();
    sWriteBoth = CreateFileOptions.defaults().setMode(Mode.createFullAccess()).setWriteType(WriteType.CACHE_THROUGH);
    sWriteAlluxio = CreateFileOptions.defaults().setMode(Mode.createFullAccess()).setWriteType(WriteType.MUST_CACHE);
    sWriteUnderStore = CreateFileOptions.defaults().setMode(Mode.createFullAccess()).setWriteType(WriteType.THROUGH);
    sTestPath = PathUtils.uniqPath();
    // Create files of varying size and write type to later read from
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFileOptions op : getOptionSet()) {
            AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            FileSystemTestUtils.createByteFile(sFileSystem, path, op, k);
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) AlluxioURI(alluxio.AlluxioURI) BeforeClass(org.junit.BeforeClass)

Example 38 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions 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 (CreateFileOptions op : getOptionSet()) {
            String filename = sTestPath + "/file_" + k + "_" + op.hashCode();
            AlluxioURI uri = new AlluxioURI(filename);
            FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            Assert.assertEquals(k / 2, is.skip(k / 2));
            Assert.assertEquals(k / 2, is.read());
            is.close();
            is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            Assert.assertEquals(k / 3, is.skip(k / 3));
            Assert.assertEquals(k / 3, is.read());
            is.close();
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 39 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method eofSeek.

/**
   * Tests {@link FileInStream#seek(long)} when at the end of a file at the block boundary.
   */
@Test
public void eofSeek() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    int length = BLOCK_SIZE * 3;
    for (CreateFileOptions op : getOptionSet()) {
        String filename = uniqPath + "/file_" + op.hashCode();
        AlluxioURI uri = new AlluxioURI(filename);
        FileSystemTestUtils.createByteFile(sFileSystem, filename, length, op);
        FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
        byte[] data = new byte[length];
        is.read(data, 0, length);
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(length, data));
        is.seek(0);
        is.read(data, 0, length);
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(length, data));
        is.close();
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 40 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project alluxio by Alluxio.

the class JournalIntegrationTest method addBlock.

/**
   * Tests adding a block.
   */
@Test
public void addBlock() throws Exception {
    AlluxioURI uri = new AlluxioURI("/xyz");
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(64);
    FileOutStream os = mFileSystem.createFile(uri, options);
    for (int k = 0; k < 1000; k++) {
        os.write(k);
    }
    os.close();
    URIStatus status = mFileSystem.getStatus(uri);
    mLocalAlluxioCluster.stopFS();
    addBlockTestUtil(status);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

CreateFileOptions (alluxio.client.file.options.CreateFileOptions)54 AlluxioURI (alluxio.AlluxioURI)48 Test (org.junit.Test)42 FileInStream (alluxio.client.file.FileInStream)22 FileOutStream (alluxio.client.file.FileOutStream)11 URIStatus (alluxio.client.file.URIStatus)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 CreateDirectoryOptions (alluxio.client.file.options.CreateDirectoryOptions)4 BeforeClass (org.junit.BeforeClass)3 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 FileSystem (alluxio.client.file.FileSystem)1 DeleteOptions (alluxio.client.file.options.DeleteOptions)1 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)1 SetAttributeOptions (alluxio.client.file.options.SetAttributeOptions)1 LineageFileSystem (alluxio.client.lineage.LineageFileSystem)1 LineageMasterClient (alluxio.client.lineage.LineageMasterClient)1 AccessControlException (alluxio.exception.AccessControlException)1