private void testBlobRecordV2(int blobSize, BlobType blobType) throws IOException, MessageFormatException {

    ByteBuffer blobContent = ByteBuffer.allocate(blobSize);
    new Random().nextBytes(blobContent.array());
    int size = (int) MessageFormatRecord.Blob_Format_V2.getBlobRecordSize(blobSize);
    ByteBuffer entireBlob = ByteBuffer.allocate(size);
    BlobData blobData = getBlobRecordV2(blobSize, blobType, blobContent, entireBlob);
    Assert.assertEquals("Blob size mismatch", blobSize, blobData.getSize());
    byte[] verify = new byte[blobSize];
    blobData.content().readBytes(verify);
    Assert.assertArrayEquals("BlobContent mismatch", blobContent.array(), verify);
    blobData.release();

    // corrupt blob record V2
    entireBlob.flip();
    byte savedByte = entireBlob.get(blobSize / 2);
    entireBlob.put(blobSize / 2, (byte) (savedByte + 1));
    try {
      MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(entireBlob));
      fail("Failed to detect corruption of blob record");
    } catch (MessageFormatException e) {
      Assert.assertEquals("Error code mismatch", MessageFormatErrorCodes.DataCorrupt, e.getErrorCode());
    }
  }
Tests Blob Record Version 2
Creates test data and creates a blob record version 2 for the specified blob type with the test data
Verifies that the stream from blob output is same as the passed in data
Corrupts data and verifies that de-serialization fails
@param blobSize
@param blobType
@throws IOException
@throws MessageFormatException
ambry-messageformat/src/test/java/com/github/ambry/messageformat/MessageFormatRecordTest.java