Search in sources :

Example 6 with CreateFilePOptions

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

the class LocalBlockInStreamIntegrationTest method seekExceptionTest1.

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

Example 7 with CreateFilePOptions

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

the class LocalBlockInStreamIntegrationTest method readTest1.

/**
 * Tests {@link alluxio.client.block.LocalBlockInStream#read()}.
 */
@Test
public void readTest1() 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];
            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, sReadCachePromote);
            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();
            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)

Example 8 with CreateFilePOptions

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

the class LocalBlockInStreamIntegrationTest method seek.

/**
 * Tests {@link alluxio.client.block.LocalBlockInStream#seek(long)}.
 */
@Test
public void seek() throws Exception {
    for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
        for (CreateFilePOptions op : getOptionSet()) {
            AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
            FileInStream is = sFileSystem.openFile(uri, sReadNoCache);
            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 : FileInStream(alluxio.client.file.FileInStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 9 with CreateFilePOptions

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

Example 10 with CreateFilePOptions

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

the class UfsFallbackFileOutStreamIntegrationTest method shortCircuitWrite.

@Ignore
@Test
public void shortCircuitWrite() throws Exception {
    try (Closeable c = new ConfigurationRule(new HashMap<PropertyKey, Object>() {

        {
            put(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT, mBlockSize);
        }
    }, ServerConfiguration.global()).toResource()) {
        FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
        AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
        CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(WritePType.ASYNC_THROUGH).setRecursive(true).build();
        writeIncreasingBytesToFile(fs, filePath, mFileLength, op);
        CommonUtils.sleepMs(1);
        // check the file is completed but not persisted
        URIStatus status = mFileSystem.getStatus(filePath);
        Assert.assertEquals(PersistenceState.TO_BE_PERSISTED.toString(), status.getPersistenceState());
        Assert.assertTrue(status.isCompleted());
        IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
        status = mFileSystem.getStatus(filePath);
        Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
        checkFileInAlluxio(filePath, mFileLength);
        checkFileInUnderStorage(filePath, mFileLength);
    }
}
Also used : HashMap(java.util.HashMap) Closeable(java.io.Closeable) FileSystem(alluxio.client.file.FileSystem) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) URIStatus(alluxio.client.file.URIStatus) ConfigurationRule(alluxio.ConfigurationRule) AlluxioURI(alluxio.AlluxioURI) Ignore(org.junit.Ignore) Test(org.junit.Test)

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