Search in sources :

Example 31 with CreateFileOptions

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

the class FileInStreamIntegrationTest method readTest3.

/**
   * Tests {@link FileInStream#read(byte[], int, int)}.
   */
@Test
public void readTest3() 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));
            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, FileSystemTestUtils.toOpenFileOptions(op));
            ret = new byte[k];
            Assert.assertEquals(k, is.read(ret, 0, k));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 32 with CreateFileOptions

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

the class FileInStreamIntegrationTest method readTest1.

/**
   * Tests {@link FileInStream#read()} across block boundary.
   */
@Test
public void readTest1() 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));
            byte[] ret = new byte[k];
            int value = is.read();
            int cnt = 0;
            while (value != -1) {
                Assert.assertTrue(value >= 0);
                Assert.assertTrue(value < 256);
                ret[cnt++] = (byte) value;
                value = is.read();
            }
            Assert.assertEquals(cnt, k);
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
            is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            ret = new byte[k];
            value = is.read();
            cnt = 0;
            while (value != -1) {
                Assert.assertTrue(value >= 0);
                Assert.assertTrue(value < 256);
                ret[cnt++] = (byte) value;
                value = is.read();
            }
            Assert.assertEquals(cnt, k);
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 33 with CreateFileOptions

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

the class FileOutStreamIntegrationTest method writeTwoByteArrays.

/**
   * Tests {@link FileOutStream#write(byte[], int, int)}.
   */
@Test
public void writeTwoByteArrays() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    for (int len = MIN_LEN; len <= MAX_LEN; len += DELTA) {
        CreateFileOptions op = CreateFileOptions.defaults().setWriteType(mWriteType);
        AlluxioURI filePath = new AlluxioURI(PathUtils.concatPath(uniqPath, "file_" + len + "_" + mWriteType));
        writeTwoIncreasingByteArraysToFile(filePath, len, op);
        if (mWriteType.getAlluxioStorageType().isStore()) {
            checkFileInAlluxio(filePath, len);
        }
        if (mWriteType.getUnderStorageType().isSyncPersist()) {
            checkFileInUnderStorage(filePath, len);
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 34 with CreateFileOptions

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

the class BufferedBlockInStreamIntegrationTest method readTest1.

/**
   * Tests {@link alluxio.client.block.BufferedBlockInStream#read()}.
   */
@Test
public void readTest1() throws IOException, AlluxioException {
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFileOptions op : getOptionSet()) {
            AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            for (int i = 0; i < 2; i++) {
                FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
                byte[] ret = new byte[k];
                int value = is.read();
                int cnt = 0;
                while (value != -1) {
                    Assert.assertTrue(value >= 0);
                    Assert.assertTrue(value < 256);
                    ret[cnt++] = (byte) value;
                    value = is.read();
                }
                Assert.assertEquals(cnt, k);
                Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
                is.close();
            }
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 35 with CreateFileOptions

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

the class BufferedBlockInStreamIntegrationTest method readTest2.

/**
   * Tests {@link alluxio.client.block.BufferedBlockInStream#read(byte[])}.
   */
@Test
public void readTest2() throws IOException, AlluxioException {
    for (int k = MIN_LEN; 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));
            byte[] ret = new byte[k];
            Assert.assertEquals(k, is.read(ret));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
            is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
            ret = new byte[k];
            Assert.assertEquals(k, is.read(ret));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
            is.close();
        }
    }
}
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