Search in sources :

Example 6 with CreateFileOptions

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

the class FileInStreamIntegrationTest method seek.

/**
   * Tests {@link FileInStream#seek(long)}.
   */
@Test
public void seek() 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));
            is.seek(k / 3);
            Assert.assertEquals(k / 3, is.read());
            is.seek(k / 2);
            Assert.assertEquals(k / 2, is.read());
            is.seek(k / 4);
            Assert.assertEquals(k / 4, 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 7 with CreateFileOptions

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

the class ReadOnlyMountIntegrationTest method createFile.

@Test
public void createFile() throws IOException, AlluxioException {
    CreateFileOptions writeBoth = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    AlluxioURI uri = new AlluxioURI(FILE_PATH + "_create");
    try {
        mFileSystem.createFile(uri, writeBoth).close();
        Assert.fail("createFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH));
    }
    uri = new AlluxioURI(SUB_FILE_PATH + "_create");
    try {
        mFileSystem.createFile(uri, writeBoth).close();
        Assert.fail("createFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH));
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 8 with CreateFileOptions

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

the class FileInStreamIntegrationTest method seekExceptionTest1.

/**
   * Tests {@link FileInStream#seek(long)}. Validate the expected exception for seeking a negative
   * position.
   */
@Test
public void seekExceptionTest1() throws Exception {
    mThrown.expect(IllegalArgumentException.class);
    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))) {
                is.seek(-1);
            }
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 9 with CreateFileOptions

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

the class FileInStreamIntegrationTest method seekExceptionTest2.

/**
   * Tests {@link FileInStream#seek(long)}. Validate the expected exception for seeking a position
   * that is past EOF.
   */
@Test
public void seekExceptionTest2() throws Exception {
    mThrown.expect(IllegalArgumentException.class);
    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))) {
                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 10 with CreateFileOptions

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

the class FileOutStreamIntegrationTest method writeByteArray.

/**
   * Tests {@link FileOutStream#write(byte[])}.
   */
@Test
public void writeByteArray() 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));
        writeIncreasingByteArrayToFile(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)

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