Search in sources :

Example 6 with TestBlockInStream

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);
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) TestBlockInStream(alluxio.client.block.stream.TestBlockInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with TestBlockInStream

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);
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) TestBlockInStream(alluxio.client.block.stream.TestBlockInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TestBlockInStream (alluxio.client.block.stream.TestBlockInStream)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 UnavailableException (alluxio.exception.status.UnavailableException)3 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)2 TestBlockOutStream (alluxio.client.block.stream.TestBlockOutStream)2 InStreamOptions (alluxio.client.file.options.InStreamOptions)2 BlockInfo (alluxio.wire.BlockInfo)2 FileBlockInfo (alluxio.wire.FileBlockInfo)2 AlluxioURI (alluxio.AlluxioURI)1 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 BlockInStream (alluxio.client.block.stream.BlockInStream)1 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)1 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)1 FileInfo (alluxio.wire.FileInfo)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Mockito.anyLong (org.mockito.Mockito.anyLong)1