use of alluxio.client.block.TestBufferedBlockInStream 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);
}
Aggregations