Search in sources :

Example 46 with CreateFilePOptions

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

the class FileInStreamIntegrationTest method readTest3.

/**
 * Tests {@link FileInStream#read(byte[], int, int)}.
 */
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_STREAMING_READER_CHUNK_SIZE_BYTES, "64KB" })
public void readTest3() 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));
            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 = mFileSystem.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 : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 47 with CreateFilePOptions

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

the class FileInStreamIntegrationTest method before.

@Before
public void before() throws Exception {
    mFileSystem = mLocalAlluxioClusterResource.get().getClient();
    mWriteBoth = CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto()).setBlockSizeBytes(BLOCK_SIZE).setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
    mWriteAlluxio = CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto()).setBlockSizeBytes(BLOCK_SIZE).setWriteType(WritePType.MUST_CACHE).setRecursive(true).build();
    mWriteUnderStore = CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto()).setBlockSizeBytes(BLOCK_SIZE).setWriteType(WritePType.THROUGH).setRecursive(true).build();
    mTestPath = 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 (CreateFilePOptions op : getOptionSet()) {
            AlluxioURI path = new AlluxioURI(mTestPath + "/file_" + k + "_" + op.hashCode());
            FileSystemTestUtils.createByteFile(mFileSystem, path, op, k);
        }
    }
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) Before(org.junit.Before)

Example 48 with CreateFilePOptions

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

the class FileOutStreamIntegrationTest method writeSpecifyLocal.

/**
 * Tests writing to a file and specify the location to be localhost.
 */
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_BLOCK_WRITE_LOCATION_POLICY, "alluxio.client.block.policy.LocalFirstPolicy" })
public void writeSpecifyLocal() throws Exception {
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    final int length = 2;
    CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(mWriteType.toProto()).setRecursive(true).build();
    try (FileOutStream os = mFileSystem.createFile(filePath, op)) {
        os.write((byte) 0);
        os.write((byte) 1);
    }
    if (mWriteType.getAlluxioStorageType().isStore()) {
        checkFileInAlluxio(filePath, length);
    }
    if (mWriteType.getUnderStorageType().isSyncPersist()) {
        checkFileInUnderStorage(filePath, length);
    }
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 49 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions 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) {
        CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(mWriteType.toProto()).setRecursive(true).build();
        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 : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 50 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions 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 (CreateFilePOptions 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).getInAlluxioPercentage() == 100);
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

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