Search in sources :

Example 71 with FileInStream

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

the class AbstractFileSystemShellTest method checkFilePersisted.

/**
 * Checks whether the given file is actually persisted by freeing it, then
 * reading it and comparing it against the expected byte array.
 *
 * @param uri The uri to persist
 * @param size The size of the file
 */
protected void checkFilePersisted(AlluxioURI uri, int size) throws Exception {
    assertTrue(sFileSystem.getStatus(uri).isPersisted());
    CommonUtils.waitFor("file to be completely freed", () -> {
        try {
            // Call free inside the loop in case a worker reports blocks after the call to free.
            sFileSystem.free(uri);
            return sFileSystem.getStatus(uri).getInAlluxioPercentage() == 0;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }, WaitForOptions.defaults().setTimeoutMs(10000));
    try (FileInStream tfis = sFileSystem.openFile(uri)) {
        byte[] actual = new byte[size];
        tfis.read(actual);
        assertArrayEquals(BufferUtils.getIncreasingByteArray(size), actual);
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 72 with FileInStream

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

the class CopyFromLocalCommandIntegrationTest method copyFromLocalLarge.

@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.WORKER_NETWORK_NETTY_WATERMARK_HIGH, "1.0" })
public void copyFromLocalLarge() throws IOException, AlluxioException {
    File testFile = new File(sLocalAlluxioCluster.getAlluxioHome() + "/testFile");
    testFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(testFile);
    byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
    fos.write(toWrite);
    fos.close();
    sFsShell.run("copyFromLocal", testFile.getAbsolutePath(), "/testFile");
    Assert.assertEquals(getCommandOutput(new String[] { "copyFromLocal", testFile.getAbsolutePath(), "/testFile" }), mOutput.toString());
    AlluxioURI uri = new AlluxioURI("/testFile");
    URIStatus status = sFileSystem.getStatus(uri);
    Assert.assertNotNull(status);
    Assert.assertEquals(SIZE_BYTES, status.getLength());
    try (FileInStream tfis = sFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
        byte[] read = new byte[SIZE_BYTES];
        tfis.read(read);
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileInStream(alluxio.client.file.FileInStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URIStatus(alluxio.client.file.URIStatus) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Example 73 with FileInStream

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

the class UnderStorageReadIntegrationTest method seek.

/**
 * Tests seeking through files only in the underfs.
 */
@Test
public void seek() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
        AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
        FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteUnderStore, k);
        FileInStream is = mFileSystem.openFile(uri, mReadCache);
        Assert.assertEquals(0, is.read());
        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) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 74 with FileInStream

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

the class IsolatedFileSystemIntegrationTest method lockBlockTest2.

@Test
public void lockBlockTest2() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    FileInStream is;
    ByteBuffer buf;
    int numOfFiles = 5;
    int fileSize = WORKER_UNRESERVED_BYTES / numOfFiles;
    List<AlluxioURI> files = new ArrayList<>();
    for (int k = 0; k < numOfFiles; k++) {
        FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
        files.add(new AlluxioURI(uniqPath + k));
    }
    for (int k = 0; k < numOfFiles; k++) {
        URIStatus info = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(info.getInAlluxioPercentage() == 100);
        is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
        buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
        Assert.assertTrue(is.read(buf.array()) != -1);
        is.close();
    }
    FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
    files.add(new AlluxioURI(uniqPath + numOfFiles));
    Assert.assertEquals(numOfFiles, numCached(files));
    Assert.assertEquals(100, mFileSystem.getStatus(files.get(numOfFiles)).getInAlluxioPercentage());
    Assert.assertNotEquals(100, mFileSystem.getStatus(files.get(0)).getInAlluxioPercentage());
}
Also used : FileInStream(alluxio.client.file.FileInStream) ArrayList(java.util.ArrayList) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 75 with FileInStream

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

the class IsolatedFileSystemIntegrationTest method unlockBlockTest1.

@Test
public void unlockBlockTest1() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    FileInStream is;
    ByteBuffer buf;
    int numOfFiles = 5;
    int fileSize = WORKER_UNRESERVED_BYTES / numOfFiles;
    List<AlluxioURI> files = new ArrayList<>();
    for (int k = 0; k < numOfFiles; k++) {
        FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
        files.add(new AlluxioURI(uniqPath + k));
    }
    for (int k = 0; k < numOfFiles; k++) {
        URIStatus info = mFileSystem.getStatus(files.get(k));
        is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
        buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
        Assert.assertTrue(info.getInAlluxioPercentage() == 100);
        Assert.assertTrue(is.read(buf.array()) != -1);
        is.close();
    }
    FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
    files.add(new AlluxioURI(uniqPath + numOfFiles));
    Assert.assertEquals(numOfFiles, numCached(files));
    Assert.assertEquals(100, mFileSystem.getStatus(files.get(numOfFiles)).getInAlluxioPercentage());
    Assert.assertNotEquals(100, mFileSystem.getStatus(files.get(0)).getInAlluxioPercentage());
}
Also used : FileInStream(alluxio.client.file.FileInStream) ArrayList(java.util.ArrayList) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) 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