Search in sources :

Example 1 with BufferedBlockInStream

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

the class FileInStreamTest method before.

/**
   * Sets up the context and streams before a test runs.
   *
   * @throws AlluxioException when the worker ufs operations fail
   * @throws IOException when the read and write streams fail
   */
@Before
public void before() throws Exception {
    mInfo = new FileInfo().setBlockSizeBytes(BLOCK_LENGTH).setLength(FILE_LENGTH);
    mDelegateUfsOps = Configuration.getBoolean(PropertyKey.USER_UFS_DELEGATION_ENABLED);
    ClientTestUtils.setSmallBufferSizes();
    mContext = PowerMockito.mock(FileSystemContext.class);
    mBlockStore = Mockito.mock(AlluxioBlockStore.class);
    PowerMockito.mockStatic(AlluxioBlockStore.class);
    PowerMockito.when(AlluxioBlockStore.create(mContext)).thenReturn(mBlockStore);
    PowerMockito.when(mBlockStore.getWorkerInfoList()).thenReturn(new ArrayList<BlockWorkerInfo>());
    Mockito.mock(StreamFactory.class);
    PowerMockito.mockStatic(StreamFactory.class);
    // Set up BufferedBlockInStreams and caching streams
    mCacheStreams = new ArrayList<>();
    List<Long> blockIds = new ArrayList<>();
    for (int i = 0; i < NUM_STREAMS; i++) {
        blockIds.add((long) i);
        mCacheStreams.add(new TestBufferedBlockOutStream(i, getBlockLength(i), mContext));
        Mockito.when(mBlockStore.getInStream(Mockito.eq((long) i), Mockito.any(InStreamOptions.class))).thenAnswer(new Answer<BufferedBlockInStream>() {

            @Override
            public BufferedBlockInStream answer(InvocationOnMock invocation) throws Throwable {
                long i = (Long) invocation.getArguments()[0];
                byte[] input = BufferUtils.getIncreasingByteArray((int) (i * BLOCK_LENGTH), (int) getBlockLength((int) i));
                return new TestBufferedBlockInStream(i, input);
            }
        });
        Mockito.when(mBlockStore.getOutStream(Mockito.eq((long) i), Mockito.anyLong(), Mockito.any(WorkerNetAddress.class), Mockito.any(OutStreamOptions.class))).thenAnswer(new Answer<BufferedBlockOutStream>() {

            @Override
            public BufferedBlockOutStream answer(InvocationOnMock invocation) throws Throwable {
                long i = (Long) invocation.getArguments()[0];
                return mCacheStreams.get((int) i).isClosed() ? null : mCacheStreams.get((int) i);
            }
        });
    }
    mInfo.setBlockIds(blockIds);
    mStatus = new URIStatus(mInfo);
    mTestStream = new FileInStream(mStatus, InStreamOptions.defaults().setReadType(ReadType.CACHE_PROMOTE).setCachePartiallyReadBlock(false), mContext);
}
Also used : TestBufferedBlockOutStream(alluxio.client.block.TestBufferedBlockOutStream) BufferedBlockInStream(alluxio.client.block.BufferedBlockInStream) TestBufferedBlockInStream(alluxio.client.block.TestBufferedBlockInStream) ArrayList(java.util.ArrayList) TestBufferedBlockOutStream(alluxio.client.block.TestBufferedBlockOutStream) BufferedBlockOutStream(alluxio.client.block.BufferedBlockOutStream) TestBufferedBlockInStream(alluxio.client.block.TestBufferedBlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) FileInfo(alluxio.wire.FileInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) Before(org.junit.Before)

Aggregations

AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 BufferedBlockInStream (alluxio.client.block.BufferedBlockInStream)1 BufferedBlockOutStream (alluxio.client.block.BufferedBlockOutStream)1 TestBufferedBlockInStream (alluxio.client.block.TestBufferedBlockInStream)1 TestBufferedBlockOutStream (alluxio.client.block.TestBufferedBlockOutStream)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1 OutStreamOptions (alluxio.client.file.options.OutStreamOptions)1 FileInfo (alluxio.wire.FileInfo)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1