private void testDeletedRecords(short blobVersion, BlobType blobType) throws Exception {
    // MessageSievingInputStream contains put records for 2 valid blobs and 1 delete record
    // id1(put record for valid blob), id2(delete record) and id3(put record for valid blob)
    ArrayList<Short> versions = new ArrayList<>();
    versions.add(Message_Header_Version_V1);
    if (blobVersion != Blob_Version_V1) {
      versions.add(Message_Header_Version_V2);
      versions.add(Message_Header_Version_V3);
    }

    try {
      for (short version : versions) {
        headerVersionToUse = version;
        // create message stream for blob 1
        StoreKey key1 = new MockId("id1");
        short accountId = Utils.getRandomShort(RANDOM);
        short containerId = Utils.getRandomShort(RANDOM);
        BlobProperties prop1 = new BlobProperties(10, "servid1", accountId, containerId, false);
        byte[] encryptionKey1 = new byte[100];
        RANDOM.nextBytes(encryptionKey1);
        byte[] usermetadata1 = new byte[1000];
        RANDOM.nextBytes(usermetadata1);
        int blobContentSize = 2000;
        byte[] data1 = new byte[blobContentSize];
        RANDOM.nextBytes(data1);
        if (blobVersion >= Blob_Version_V2 && blobType == BlobType.MetadataBlob) {
          ByteBuffer byteBufferBlob = MessageFormatTestUtils.getBlobContentForMetadataBlob(blobContentSize);
          data1 = byteBufferBlob.array();
          blobContentSize = data1.length;
        }
        ByteBufferInputStream stream1 = new ByteBufferInputStream(ByteBuffer.wrap(data1));

        MessageFormatInputStream messageFormatStream1 =
            (blobVersion >= Blob_Version_V2) ? new PutMessageFormatInputStream(key1, ByteBuffer.wrap(encryptionKey1),
                prop1, ByteBuffer.wrap(usermetadata1), stream1, blobContentSize, blobType)
                : new PutMessageFormatBlobV1InputStream(key1, prop1, ByteBuffer.wrap(usermetadata1), stream1,
                    blobContentSize, blobType);
        MessageInfo msgInfo1 =
            new MessageInfo(key1, messageFormatStream1.getSize(), accountId, containerId, prop1.getCreationTimeInMs());

        // create message stream for blob 2 and mark it as deleted
        StoreKey key2 = new MockId("id2");
        accountId = Utils.getRandomShort(RANDOM);
        containerId = Utils.getRandomShort(RANDOM);
        long deletionTimeMs = SystemTime.getInstance().milliseconds() + RANDOM.nextInt();
        MessageFormatInputStream messageFormatStream2 =
            new DeleteMessageFormatInputStream(key2, accountId, containerId, deletionTimeMs);

        MessageInfo msgInfo2 =
            new MessageInfo(key2, messageFormatStream2.getSize(), accountId, containerId, deletionTimeMs);

        // create message stream for blob 3
        StoreKey key3 = new MockId("id3");
        accountId = Utils.getRandomShort(RANDOM);
        containerId = Utils.getRandomShort(RANDOM);
        BlobProperties prop3 = new BlobProperties(10, "servid3", accountId, containerId, false);
        byte[] encryptionKey3 = new byte[100];
        RANDOM.nextBytes(encryptionKey3);
        byte[] usermetadata3 = new byte[1000];
        RANDOM.nextBytes(usermetadata3);
        blobContentSize = 2000;
        byte[] data3 = new byte[blobContentSize];
        RANDOM.nextBytes(data3);
        if (blobVersion >= Blob_Version_V2 && blobType == BlobType.MetadataBlob) {
          ByteBuffer byteBufferBlob = MessageFormatTestUtils.getBlobContentForMetadataBlob(blobContentSize);
          data3 = byteBufferBlob.array();
          blobContentSize = data3.length;
        }
        ByteBufferInputStream stream3 = new ByteBufferInputStream(ByteBuffer.wrap(data3));

        MessageFormatInputStream messageFormatStream3 =
            (blobVersion >= Blob_Version_V2) ? new PutMessageFormatInputStream(key3, ByteBuffer.wrap(encryptionKey3),
                prop3, ByteBuffer.wrap(usermetadata3), stream3, blobContentSize, blobType)
                : new PutMessageFormatBlobV1InputStream(key3, prop3, ByteBuffer.wrap(usermetadata3), stream3,
                    blobContentSize, blobType);

        MessageInfo msgInfo3 =
            new MessageInfo(key3, messageFormatStream3.getSize(), accountId, containerId, prop3.getCreationTimeInMs());

        //create input stream for all blob messages together
        byte[] totalMessageContent =
            new byte[(int) messageFormatStream1.getSize() + (int) messageFormatStream2.getSize()
                + (int) messageFormatStream3.getSize()];
        messageFormatStream1.read(totalMessageContent, 0, (int) messageFormatStream1.getSize());
        messageFormatStream2.read(totalMessageContent, (int) messageFormatStream1.getSize(),
            (int) messageFormatStream2.getSize());
        messageFormatStream3.read(totalMessageContent,
            (int) messageFormatStream1.getSize() + (int) messageFormatStream2.getSize(),
            (int) messageFormatStream3.getSize());

        InputStream inputStream = new ByteBufferInputStream(ByteBuffer.wrap(totalMessageContent));

        List<MessageInfo> msgInfoList = new ArrayList<MessageInfo>();
        msgInfoList.add(msgInfo1);
        msgInfoList.add(msgInfo2);
        msgInfoList.add(msgInfo3);

        new MessageSievingInputStream(inputStream, msgInfoList, transformers, new MetricRegistry());
        if (!options.isEmpty()) {
          Assert.fail("IOException should have been thrown due to delete record ");
        }
      }
    } catch (IOException e) {
      if (options.isEmpty()) {
        Assert.fail("No exceptions should have occurred");
      }
    }
    headerVersionToUse = Message_Header_Version_V1;
  }
Test the case where there are delete records in messages.
ambry-messageformat/src/test/java/com/github/ambry/messageformat/MessageSievingInputStreamTest.java