Search in sources :

Example 41 with FileInStream

use of alluxio.client.file.FileInStream in project alluxio by Alluxio.

the class CpCommandIntegrationTest method equals.

private boolean equals(AlluxioURI file1, AlluxioURI file2) throws Exception {
    try (Closer closer = Closer.create()) {
        OpenFilePOptions openFileOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
        FileInStream is1 = closer.register(sFileSystem.openFile(file1, openFileOptions));
        FileInStream is2 = closer.register(sFileSystem.openFile(file2, openFileOptions));
        return IOUtils.contentEquals(is1, is2);
    }
}
Also used : Closer(com.google.common.io.Closer) FileInStream(alluxio.client.file.FileInStream) OpenFilePOptions(alluxio.grpc.OpenFilePOptions)

Example 42 with FileInStream

use of alluxio.client.file.FileInStream 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 43 with FileInStream

use of alluxio.client.file.FileInStream 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 44 with FileInStream

use of alluxio.client.file.FileInStream 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 45 with FileInStream

use of alluxio.client.file.FileInStream 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)

Aggregations

FileInStream (alluxio.client.file.FileInStream)179 AlluxioURI (alluxio.AlluxioURI)148 Test (org.junit.Test)132 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)67 URIStatus (alluxio.client.file.URIStatus)44 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)31 FileOutStream (alluxio.client.file.FileOutStream)25 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)21 FileSystem (alluxio.client.file.FileSystem)17 ByteBuffer (java.nio.ByteBuffer)16 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)11 File (java.io.File)11 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)10 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)8 FileInfo (alluxio.wire.FileInfo)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 InstancedConfiguration (alluxio.conf.InstancedConfiguration)5 FileIncompleteException (alluxio.exception.FileIncompleteException)5