use of alluxio.client.block.stream.TestBlockInStream in project alluxio by Alluxio.
the class AlluxioFileInStreamTest method readOneRetry.
@Test
public void readOneRetry() throws Exception {
long offset = 37;
// Setups a broken stream for the first block to throw an exception.
TestBlockInStream workingStream = mInStreams.get(0);
TestBlockInStream brokenStream = mock(TestBlockInStream.class);
when(mBlockStore.getInStream(any(BlockInfo.class), any(InStreamOptions.class), any())).thenReturn(brokenStream).thenReturn(workingStream);
when(brokenStream.read()).thenThrow(new UnavailableException("test exception"));
when(brokenStream.getPos()).thenReturn(offset);
mTestStream.seek(offset);
int b = mTestStream.read();
doReturn(0).when(brokenStream).read();
verify(brokenStream, times(1)).read();
assertEquals(offset, b);
}
use of alluxio.client.block.stream.TestBlockInStream in project alluxio by Alluxio.
the class AlluxioFileInStreamTest method positionedReadRetry.
@Test
public void positionedReadRetry() throws Exception {
TestBlockInStream workingStream = mInStreams.get(0);
TestBlockInStream brokenStream = mock(TestBlockInStream.class);
when(mBlockStore.getInStream(eq(0L), any(InStreamOptions.class), any())).thenReturn(brokenStream).thenReturn(workingStream);
when(brokenStream.positionedRead(anyLong(), any(byte[].class), anyInt(), anyInt())).thenThrow(new UnavailableException("test exception"));
byte[] b = new byte[(int) BLOCK_LENGTH * 2];
mTestStream.positionedRead(BLOCK_LENGTH / 2, b, 0, b.length);
doReturn(0).when(brokenStream).positionedRead(anyLong(), any(byte[].class), anyInt(), anyInt());
verify(brokenStream, times(1)).positionedRead(anyLong(), any(byte[].class), anyInt(), anyInt());
assertArrayEquals(BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH / 2, (int) BLOCK_LENGTH * 2), b);
}
Aggregations