Search in sources :

Example 36 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions 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 (CreateFilePOptions op : getOptionSet()) {
            String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
            AlluxioURI uri = new AlluxioURI(filename);
            try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
                is.seek(k + 1);
            }
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 37 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions 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 (CreateFilePOptions op : getOptionSet()) {
            String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
            AlluxioURI uri = new AlluxioURI(filename);
            FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
            is.seek(k / 3);
            Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 3), is.read());
            is.seek(k / 2);
            Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 2), is.read());
            is.seek(k / 4);
            Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 4), is.read());
            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 38 with CreateFilePOptions

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

the class FileInStreamIntegrationTest method positionedReadWithSmallThreshold.

@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_FILE_SEQUENTIAL_PREAD_THRESHOLD, "200KB" })
public void positionedReadWithSmallThreshold() throws Exception {
    List<CreateFilePOptions> optionSet = new ArrayList<>(2);
    optionSet.add(mWriteBoth);
    optionSet.add(mWriteUnderStore);
    for (CreateFilePOptions op : optionSet) {
        String filename = mTestPath + "/file_" + MIN_LEN + "_" + op.hashCode();
        AlluxioURI uri = new AlluxioURI(filename);
        try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
            byte[] ret = new byte[DELTA - 1];
            Assert.assertEquals(DELTA - 1, is.positionedRead(MIN_LEN - DELTA + 1, ret, 0, DELTA));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MIN_LEN - DELTA + 1, DELTA - 1, ret));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 39 with CreateFilePOptions

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

the class FileInStreamRehydrationIntegrationTest method testRehydration.

@Test
public void testRehydration() throws Exception {
    FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
    // Create a file with 10 blocks.
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
    byte[] content = generateContent(BLOCK_BYTES * 10);
    try (FileOutStream os = fs.createFile(filePath, op)) {
        os.write(content);
    }
    // Validate file size and content.
    validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
    // Grab the block master for emulating lost blocks.
    MasterProcess masterProcess = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster(), "mMasterProcess");
    BlockMaster blockMaster = masterProcess.getMaster(BlockMaster.class);
    // Remove blocks externally from block-master.
    URIStatus status = fs.getStatus(filePath);
    blockMaster.removeBlocks(status.getBlockIds(), true);
    // Validate file size and content.
    validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) MasterProcess(alluxio.master.MasterProcess) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractFileOutStreamIntegrationTest(alluxio.client.fs.io.AbstractFileOutStreamIntegrationTest)

Example 40 with CreateFilePOptions

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

the class BufferedBlockInStreamIntegrationTest method readTest3.

/**
 * Tests {@link alluxio.client.block.BufferedBlockInStream#read(byte[], int, int)}.
 */
@Test
public void readTest3() throws IOException, AlluxioException {
    for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
        for (CreateFilePOptions op : getOptionSet()) {
            AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            FileInStream is = sFileSystem.openFile(path, 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(path, 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) 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