Search in sources :

Example 6 with FileInStream

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

the class AbstractAlluxioShellTest method readContent.

protected byte[] readContent(AlluxioURI uri, int length) throws IOException, AlluxioException {
    try (FileInStream tfis = mFileSystem.openFile(uri, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
        byte[] read = new byte[length];
        tfis.read(read);
        return read;
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream)

Example 7 with FileInStream

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

the class CopyFromLocalCommandTest method copyFromLocalLarge.

@Test
public void copyFromLocalLarge() throws IOException, AlluxioException {
    File testFile = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testFile");
    testFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(testFile);
    byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
    fos.write(toWrite);
    fos.close();
    mFsShell.run("copyFromLocal", testFile.getAbsolutePath(), "/testFile");
    Assert.assertEquals(getCommandOutput(new String[] { "copyFromLocal", testFile.getAbsolutePath(), "/testFile" }), mOutput.toString());
    AlluxioURI uri = new AlluxioURI("/testFile");
    URIStatus status = mFileSystem.getStatus(uri);
    Assert.assertNotNull(status);
    Assert.assertEquals(SIZE_BYTES, status.getLength());
    try (FileInStream tfis = mFileSystem.openFile(uri, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
        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) URIStatus(alluxio.client.file.URIStatus) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AlluxioShellUtilsTest(alluxio.shell.AlluxioShellUtilsTest) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 8 with FileInStream

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

the class CpCommandTest method equals.

private boolean equals(AlluxioURI file1, AlluxioURI file2) throws Exception {
    try (Closer closer = Closer.create()) {
        OpenFileOptions openFileOptions = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
        FileInStream is1 = closer.register(mFileSystem.openFile(file1, openFileOptions));
        FileInStream is2 = closer.register(mFileSystem.openFile(file2, openFileOptions));
        return IOUtils.contentEquals(is1, is2);
    }
}
Also used : Closer(com.google.common.io.Closer) FileInStream(alluxio.client.file.FileInStream) OpenFileOptions(alluxio.client.file.options.OpenFileOptions)

Example 9 with FileInStream

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

the class TieredStoreIntegrationTest method promoteBlock.

/**
   * Tests the promotion of a file.
   */
@Test
public void promoteBlock() throws Exception {
    AlluxioURI uri1 = new AlluxioURI("/file1");
    AlluxioURI uri2 = new AlluxioURI("/file2");
    AlluxioURI uri3 = new AlluxioURI("/file3");
    FileSystemTestUtils.createByteFile(mFileSystem, uri1, WriteType.CACHE_THROUGH, MEM_CAPACITY_BYTES / 6);
    FileSystemTestUtils.createByteFile(mFileSystem, uri2, WriteType.CACHE_THROUGH, MEM_CAPACITY_BYTES / 2);
    FileSystemTestUtils.createByteFile(mFileSystem, uri3, WriteType.CACHE_THROUGH, MEM_CAPACITY_BYTES / 2);
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    AlluxioURI toPromote;
    int toPromoteLen;
    URIStatus file1Info = mFileSystem.getStatus(uri1);
    URIStatus file2Info = mFileSystem.getStatus(uri2);
    URIStatus file3Info = mFileSystem.getStatus(uri3);
    // any assumptions on the eviction policy
    if (file1Info.getInMemoryPercentage() < 100) {
        toPromote = uri1;
        toPromoteLen = (int) file1Info.getLength();
        Assert.assertEquals(100, file2Info.getInMemoryPercentage());
        Assert.assertEquals(100, file3Info.getInMemoryPercentage());
    } else if (file2Info.getInMemoryPercentage() < 100) {
        toPromote = uri2;
        toPromoteLen = (int) file2Info.getLength();
        Assert.assertEquals(100, file1Info.getInMemoryPercentage());
        Assert.assertEquals(100, file3Info.getInMemoryPercentage());
    } else {
        toPromote = uri3;
        toPromoteLen = (int) file3Info.getLength();
        Assert.assertEquals(100, file1Info.getInMemoryPercentage());
        Assert.assertEquals(100, file2Info.getInMemoryPercentage());
    }
    FileInStream is = mFileSystem.openFile(toPromote, OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE));
    byte[] buf = new byte[toPromoteLen];
    int len = is.read(buf);
    is.close();
    HeartbeatScheduler.schedule(HeartbeatContext.WORKER_BLOCK_SYNC);
    HeartbeatScheduler.await(HeartbeatContext.WORKER_BLOCK_SYNC, 10, TimeUnit.SECONDS);
    Assert.assertEquals(toPromoteLen, len);
    Assert.assertEquals(100, mFileSystem.getStatus(toPromote).getInMemoryPercentage());
}
Also used : FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 10 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_CAPACITY_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.getInMemoryPercentage() == 100);
        Assert.assertTrue(is.read(buf.array()) != -1);
        is.close();
    }
    FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
    files.add(new AlluxioURI(uniqPath + numOfFiles));
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    URIStatus info = mFileSystem.getStatus(files.get(0));
    Assert.assertFalse(info.getInMemoryPercentage() == 100);
    for (int k = 1; k <= numOfFiles; k++) {
        URIStatus in = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(in.getInMemoryPercentage() == 100);
    }
}
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)

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