Search in sources :

Example 26 with CreateFileOptions

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

the class LocalBlockInStreamIntegrationTest method beforeClass.

@BeforeClass
public static final void beforeClass() throws Exception {
    sFileSystem = sLocalAlluxioClusterResource.get().getClient();
    sWriteBoth = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    sWriteAlluxio = CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE);
    sReadCachePromote = OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE);
    sReadNoCache = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
    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 27 with CreateFileOptions

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

the class LocalBlockInStreamIntegrationTest method readTest3.

/**
   * Tests {@link alluxio.client.block.LocalBlockInStream#read(byte[], int, int)}.
   */
@Test
public void readTest3() throws Exception {
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFileOptions op : getOptionSet()) {
            AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            FileInStream is = sFileSystem.openFile(uri, sReadNoCache);
            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();
            is = sFileSystem.openFile(uri, sReadCachePromote);
            ret = new byte[k];
            Assert.assertEquals(k, is.read(ret, 0, k));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
            Assert.assertTrue(sFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 28 with CreateFileOptions

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

the class LocalBlockInStreamIntegrationTest method seekExceptionTest2.

/**
   * Tests {@link alluxio.client.block.LocalBlockInStream#seek(long)}. Validate the expected
   * exception for seeking a position that is past buffer limit.
   */
@Test
public void seekExceptionTest2() throws Exception {
    mThrown.expect(IllegalArgumentException.class);
    mThrown.expectMessage(String.format(PreconditionMessage.ERR_SEEK_PAST_END_OF_FILE.toString(), 1));
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFileOptions op : getOptionSet()) {
            AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            try (FileInStream is = sFileSystem.openFile(uri, sReadNoCache)) {
                is.seek(k + 1);
            }
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 29 with CreateFileOptions

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

the class LocalBlockInStreamIntegrationTest method readTest2.

/**
   * Tests {@link alluxio.client.block.LocalBlockInStream#read(byte[])}.
   */
@Test
public void readTest2() throws Exception {
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFileOptions op : getOptionSet()) {
            AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            FileInStream is = sFileSystem.openFile(uri, sReadNoCache);
            byte[] ret = new byte[k];
            Assert.assertEquals(k, is.read(ret));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
            is = sFileSystem.openFile(uri, sReadCachePromote);
            ret = new byte[k];
            Assert.assertEquals(k, is.read(ret));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
            Assert.assertTrue(sFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 30 with CreateFileOptions

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

the class FileInStreamIntegrationTest method readEndOfFile.

/**
   * Tests {@link FileInStream#read(byte[], int, int)} for end of file.
   */
@Test
public void readEndOfFile() 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);
            try (FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
                byte[] ret = new byte[k / 2];
                int readBytes = is.read(ret, 0, k / 2);
                while (readBytes != -1) {
                    readBytes = is.read(ret);
                    Assert.assertTrue(0 != readBytes);
                }
                Assert.assertEquals(-1, readBytes);
            }
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) 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