Search in sources :

Example 1 with RefCnt

use of org.apache.hadoop.hbase.nio.RefCnt in project hbase by apache.

the class TestFileIOEngine method testReadFailedShouldReleaseByteBuff.

@Test
public void testReadFailedShouldReleaseByteBuff() {
    ByteBuffAllocator alloc = Mockito.mock(ByteBuffAllocator.class);
    final RefCnt refCnt = RefCnt.create();
    Mockito.when(alloc.allocate(Mockito.anyInt())).thenAnswer(new Answer<ByteBuff>() {

        @Override
        public ByteBuff answer(InvocationOnMock invocation) throws Throwable {
            int len = invocation.getArgument(0);
            return ByteBuff.wrap(new ByteBuffer[] { ByteBuffer.allocate(len + 1) }, refCnt);
        }
    });
    int len = 10;
    byte[] data1 = new byte[len];
    assertEquals(1, refCnt.refCnt());
    try {
        fileIOEngine.write(ByteBuffer.wrap(data1), 0);
        BucketEntry be = createBucketEntry(0, len, alloc);
        fileIOEngine.read(be);
        fail();
    } catch (IOException ioe) {
    // expected exception.
    }
    assertEquals(0, refCnt.refCnt());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RefCnt(org.apache.hadoop.hbase.nio.RefCnt) TestByteBufferIOEngine.getByteBuff(org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.getByteBuff) ByteBuff(org.apache.hadoop.hbase.nio.ByteBuff) TestByteBufferIOEngine.createBucketEntry(org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.createBucketEntry) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ByteBuffAllocator(org.apache.hadoop.hbase.io.ByteBuffAllocator) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ByteBuffAllocator (org.apache.hadoop.hbase.io.ByteBuffAllocator)1 TestByteBufferIOEngine.createBucketEntry (org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.createBucketEntry)1 TestByteBufferIOEngine.getByteBuff (org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.getByteBuff)1 ByteBuff (org.apache.hadoop.hbase.nio.ByteBuff)1 RefCnt (org.apache.hadoop.hbase.nio.RefCnt)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1