final int size1 = 4 * SMALL_PAYLOAD_LENGTH;
final byte[] allocatedPayload1 = MemoryTestUtils.generateRandomPayload( size1 );
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;
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 ) ) );
Assert.assertEquals( new String( payload3 ), new String( mms.retrieve( pointer3 ) ) );