private static void checkHeaderAndStoreKeyForUpdate(InputStream stream, Long expectedRecordSize, StoreKey key,
      short lifeVersion) throws IOException, MessageFormatException {
    MessageFormatRecord.MessageHeader_Format header = MessageFormatRecordTest.getHeader(new DataInputStream(stream));
    header.verifyHeader();

    short messageHeaderVersion = MessageFormatRecord.headerVersionToUse;
    Assert.assertEquals("Version not as expected", messageHeaderVersion, header.getVersion());
    // update record relative offset. This is the only relative offset with a valid value.
    Assert.assertEquals("Update record relative offset not as expected",
        MessageFormatRecord.getHeaderSizeForVersion(messageHeaderVersion) + key.sizeInBytes(),
        header.getUpdateRecordRelativeOffset());
    if (expectedRecordSize != null) {
      Assert.assertEquals("Size of record not as expected", expectedRecordSize.longValue(), header.getMessageSize());
    }
    Assert.assertEquals("Encryption key relative offset should be invalid",
        MessageFormatRecord.Message_Header_Invalid_Relative_Offset, header.getBlobEncryptionKeyRecordRelativeOffset());
    Assert.assertEquals("Blob props relative offset should be invalid",
        MessageFormatRecord.Message_Header_Invalid_Relative_Offset, header.getBlobPropertiesRecordRelativeOffset());
    Assert.assertEquals("UM relative offset should be invalid",
        MessageFormatRecord.Message_Header_Invalid_Relative_Offset, header.getUserMetadataRecordRelativeOffset());
    Assert.assertEquals("Blob relative offset should be invalid",
        MessageFormatRecord.Message_Header_Invalid_Relative_Offset, header.getBlobRecordRelativeOffset());

    if (header.getVersion() == MessageFormatRecord.Message_Header_Version_V3) {
      Assert.assertTrue("Header should have lifeVersion", header.hasLifeVersion());
      Assert.assertEquals("LifeVersion mismatch", lifeVersion, header.getLifeVersion());
    } else {
      Assert.assertEquals("LifeVersion mismatch", (short) 0, header.getLifeVersion());
    }

    // verify StoreKey
    byte[] keyBytes = Utils.readBytesFromStream(stream, key.sizeInBytes());
    Assert.assertArrayEquals("StoreKey not as expected", key.toBytes(), keyBytes);
  }
Checks the header and storekey for an update message in {@code stream}
@param stream the {@link InputStream} to read data from
@param expectedRecordSize the expected size of the record in the message. Can be {@code null} if unknown (won't be
                           checked)
@param key the expected {@link StoreKey}
@param lifeVersion the life version of this update.
@throws IOException
@throws MessageFormatException
ambry-messageformat/src/test/java/com/github/ambry/messageformat/MessageFormatInputStreamTest.java