Search in sources :

Example 1 with UnderFileSystemBlockInStream

use of alluxio.client.block.UnderFileSystemBlockInStream in project alluxio by Alluxio.

the class FileInStreamTest method failToUnderFs.

/**
   * Tests the capability to fall back to a ufs stream when getting an alluxio stream fails.
   */
@Test
public void failToUnderFs() throws AlluxioException, IOException {
    mInfo.setPersisted(true).setUfsPath("testUfsPath");
    mStatus = new URIStatus(mInfo);
    mTestStream = new FileInStream(mStatus, InStreamOptions.defaults().setCachePartiallyReadBlock(false), mContext);
    Mockito.when(mBlockStore.getInStream(Mockito.eq(1L), Mockito.any(InStreamOptions.class))).thenThrow(new IOException("test IOException"));
    if (mDelegateUfsOps) {
        UnderFileSystemBlockInStream inStream = PowerMockito.mock(UnderFileSystemBlockInStream.class);
        PowerMockito.when(StreamFactory.createUfsBlockInStream(Mockito.any(FileSystemContext.class), Mockito.anyString(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(WorkerNetAddress.class), Mockito.any(InStreamOptions.class))).thenReturn(inStream);
        mTestStream.seek(BLOCK_LENGTH + (BLOCK_LENGTH / 2));
    } else {
        UnderFileSystem ufs = ClientMockUtils.mockUnderFileSystem(Mockito.eq("testUfsPath"));
        InputStream stream = Mockito.mock(InputStream.class);
        Mockito.when(ufs.open("testUfsPath")).thenReturn(stream);
        Mockito.when(stream.skip(BLOCK_LENGTH)).thenReturn(BLOCK_LENGTH);
        Mockito.when(stream.skip(BLOCK_LENGTH / 2)).thenReturn(BLOCK_LENGTH / 2);
        mTestStream.seek(BLOCK_LENGTH + (BLOCK_LENGTH / 2));
        Mockito.verify(ufs).open("testUfsPath");
        Mockito.verify(stream).skip(100);
        Mockito.verify(stream).skip(50);
    }
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) InputStream(java.io.InputStream) UnderFileSystemBlockInStream(alluxio.client.block.UnderFileSystemBlockInStream) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UnderFileSystemBlockInStream (alluxio.client.block.UnderFileSystemBlockInStream)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1