Package org.apache.directmemory.memory.buffer

Examples of org.apache.directmemory.memory.buffer.MemoryBuffer.capacity()


        allocator.setSizeRatioThreshold( 10 );

        MemoryBuffer bf1 = allocator.allocate( 180 );
        Assert.assertEquals( 180, bf1.maxCapacity() );
        Assert.assertEquals( 180, bf1.capacity() );

        MemoryBuffer bf2 = allocator.allocate( 10 );
        Assert.assertEquals( 20, bf2.maxCapacity() );
        Assert.assertEquals( 10, bf2.capacity() );
View Full Code Here


        Assert.assertEquals( 180, bf1.maxCapacity() );
        Assert.assertEquals( 180, bf1.capacity() );

        MemoryBuffer bf2 = allocator.allocate( 10 );
        Assert.assertEquals( 20, bf2.maxCapacity() );
        Assert.assertEquals( 10, bf2.capacity() );

        allocator.close();
    }

    @Test( expected = BufferOverflowException.class )
View Full Code Here

        final Pointer<Object> allocatedPointer1 = mms.allocate( Object.class, allocatedPayload1.length, -1, -1 );
        Assert.assertNotNull( allocatedPointer1 );
        final MemoryBuffer buffer1 = allocatedPointer1.getMemoryBuffer();
        Assert.assertNotNull( buffer1 );
        Assert.assertEquals( 0, buffer1.writerIndex() );
        Assert.assertEquals( size1, buffer1.capacity() );
        Assert.assertEquals( size1, buffer1.capacity() );
        buffer1.writeBytes( allocatedPayload1 );
        Assert.assertEquals( new String( allocatedPayload1 ), new String( mms.retrieve( allocatedPointer1 ) ) );

        final int size2 = 2 * SMALL_PAYLOAD_LENGTH;
 
View Full Code Here

        Assert.assertNotNull( allocatedPointer1 );
        final MemoryBuffer buffer1 = allocatedPointer1.getMemoryBuffer();
        Assert.assertNotNull( buffer1 );
        Assert.assertEquals( 0, buffer1.writerIndex() );
        Assert.assertEquals( size1, buffer1.capacity() );
        Assert.assertEquals( size1, buffer1.capacity() );
        buffer1.writeBytes( allocatedPayload1 );
        Assert.assertEquals( new String( allocatedPayload1 ), new String( mms.retrieve( allocatedPointer1 ) ) );

        final int size2 = 2 * SMALL_PAYLOAD_LENGTH;
        final byte[] allocatedPayload2 = MemoryTestUtils.generateRandomPayload( size2 );
View Full Code Here

        final byte[] allocatedPayload2 = MemoryTestUtils.generateRandomPayload( size2 );
        final Pointer<Object> allocatedPointer2 = mms.allocate( Object.class, allocatedPayload2.length, -1, -1 );
        Assert.assertNotNull( allocatedPointer2 );
        final MemoryBuffer buffer2 = allocatedPointer2.getMemoryBuffer();
        Assert.assertNotNull( buffer2 );
        Assert.assertEquals( size2, buffer2.capacity() );
        buffer2.writeBytes( allocatedPayload2 );
        Assert.assertEquals( new String( allocatedPayload2 ), new String( mms.retrieve( allocatedPointer2 ) ) );

        // Ensure the new allocation has not overwritten other data
        Assert.assertEquals( new String( payload2 ), new String( mms.retrieve( pointer2 ) ) );
View Full Code Here

       
        Allocator allocator = new SlabByteBufferAllocator( 0, slabs, false );
       
        MemoryBuffer bf1 = allocator.allocate( 250 );
        Assert.assertEquals( 256, bf1.maxCapacity() );
        Assert.assertEquals( 250, bf1.capacity() );
       
        MemoryBuffer bf2 = allocator.allocate( 251 );
        Assert.assertEquals( 256, bf2.maxCapacity() );
        Assert.assertEquals( 251, bf2.capacity() );
       
View Full Code Here

        Assert.assertEquals( 256, bf1.maxCapacity() );
        Assert.assertEquals( 250, bf1.capacity() );
       
        MemoryBuffer bf2 = allocator.allocate( 251 );
        Assert.assertEquals( 256, bf2.maxCapacity() );
        Assert.assertEquals( 251, bf2.capacity() );
       
        MemoryBuffer bf3 = allocator.allocate( 200 );
        Assert.assertEquals( 256, bf3.maxCapacity() );
        Assert.assertEquals( 200, bf3.capacity() );
       
View Full Code Here

        Assert.assertEquals( 256, bf2.maxCapacity() );
        Assert.assertEquals( 251, bf2.capacity() );
       
        MemoryBuffer bf3 = allocator.allocate( 200 );
        Assert.assertEquals( 256, bf3.maxCapacity() );
        Assert.assertEquals( 200, bf3.capacity() );
       
        MemoryBuffer bf4 = allocator.allocate( 100 );
        Assert.assertEquals( 128, bf4.maxCapacity() );
        Assert.assertEquals( 100, bf4.capacity() );
       
View Full Code Here

        Assert.assertEquals( 256, bf3.maxCapacity() );
        Assert.assertEquals( 200, bf3.capacity() );
       
        MemoryBuffer bf4 = allocator.allocate( 100 );
        Assert.assertEquals( 128, bf4.maxCapacity() );
        Assert.assertEquals( 100, bf4.capacity() );
       
        MemoryBuffer bf5 = allocator.allocate( 550 );
        Assert.assertEquals( 1024, bf5.maxCapacity() );
        Assert.assertEquals( 550, bf5.capacity() );
       
View Full Code Here

        Assert.assertEquals( 128, bf4.maxCapacity() );
        Assert.assertEquals( 100, bf4.capacity() );
       
        MemoryBuffer bf5 = allocator.allocate( 550 );
        Assert.assertEquals( 1024, bf5.maxCapacity() );
        Assert.assertEquals( 550, bf5.capacity() );
       
        MemoryBuffer bf6 = allocator.allocate( 800 );
        Assert.assertNull( bf6 );

        allocator.free( bf5 );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.