Source:
public void messageFormatDeleteRecordTest() throws IOException { StoreKey key = new MockId("id1"); MessageFormatInputStream messageFormatStream = new MessageFormatInputStream(key, true); int headerSize = MessageFormat.getCurrentVersionHeaderSize(); int systemMetadataSize = MessageFormat.getCurrentVersionDeleteRecordSize(); Assert.assertEquals(headerSize + systemMetadataSize + 4 + key.sizeInBytes(), messageFormatStream.getSize()); byte[] headerOutput = new byte[headerSize]; messageFormatStream.read(headerOutput); ByteBuffer headerBuf = ByteBuffer.wrap(headerOutput); Assert.assertEquals(1, headerBuf.getShort()); Assert.assertEquals(systemMetadataSize, headerBuf.getLong()); Assert.assertEquals(headerSize + 4 + key.sizeInBytes(), headerBuf.getInt()); Assert.assertEquals(-1, headerBuf.getInt()); Assert.assertEquals(-1, headerBuf.getInt()); Crc32 crc = new Crc32(); crc.update(headerOutput, 0, headerSize - 8); Assert.assertEquals(crc.getValue(), headerBuf.getLong()); byte[] handleOutput = new byte[4 + key.sizeInBytes()]; ByteBuffer handleOutputBuf = ByteBuffer.wrap(handleOutput); messageFormatStream.read(handleOutput); Assert.assertEquals(handleOutputBuf.getInt(), key.sizeInBytes()); byte[] dest = new byte[key.sizeInBytes()]; handleOutputBuf.get(dest); Assert.assertArrayEquals(dest, key.toBytes().array()); byte[] systemMetadataOutput = new byte[systemMetadataSize]; ByteBuffer systemMetadataBuf = ByteBuffer.wrap(systemMetadataOutput); messageFormatStream.read(systemMetadataOutput); Assert.assertEquals(systemMetadataBuf.getShort(), 1); Assert.assertEquals(MessageFormat.SystemMetadataType.DeleteRecord.ordinal(), systemMetadataBuf.getShort()); Assert.assertEquals(true, systemMetadataBuf.get() == 1 ? true : false); crc = new Crc32(); crc.update(systemMetadataOutput, 0, systemMetadataSize - 8); Assert.assertEquals(crc.getValue(), systemMetadataBuf.getLong()); }

Target:
public void messageFormatDeleteRecordTest() throws IOException { StoreKey key = new MockId("id1"); MessageFormatInputStream messageFormatStream = new DeleteMessageFormatInputStream(key); int headerSize = MessageFormat.getCurrentVersionHeaderSize(); int systemMetadataSize = MessageFormat.getCurrentVersionDeleteRecordSize(); Assert.assertEquals(headerSize + systemMetadataSize + Key_Size + key.sizeInBytes(), messageFormatStream.getSize()); byte[] headerOutput = new byte[headerSize]; messageFormatStream.read(headerOutput); ByteBuffer headerBuf = ByteBuffer.wrap(headerOutput); Assert.assertEquals(MessageFormat.Header_Current_Version, headerBuf.getShort()); Assert.assertEquals(systemMetadataSize, headerBuf.getLong()); Assert.assertEquals(headerSize + Key_Size + key.sizeInBytes(), headerBuf.getInt()); Assert.assertEquals(MessageFormat.Message_Header_Invalid_Relative_Offset, headerBuf.getInt()); Assert.assertEquals(MessageFormat.Message_Header_Invalid_Relative_Offset, headerBuf.getInt()); Crc32 crc = new Crc32(); crc.update(headerOutput, 0, headerSize - MessageFormat.Crc_Size); Assert.assertEquals(crc.getValue(), headerBuf.getLong()); byte[] handleOutput = new byte[Key_Size + key.sizeInBytes()]; ByteBuffer handleOutputBuf = ByteBuffer.wrap(handleOutput); messageFormatStream.read(handleOutput); Assert.assertEquals(handleOutputBuf.getInt(), key.sizeInBytes()); byte[] dest = new byte[key.sizeInBytes()]; handleOutputBuf.get(dest); Assert.assertArrayEquals(dest, key.toBytes().array()); byte[] systemMetadataOutput = new byte[systemMetadataSize]; ByteBuffer systemMetadataBuf = ByteBuffer.wrap(systemMetadataOutput); messageFormatStream.read(systemMetadataOutput); Assert.assertEquals(systemMetadataBuf.getShort(), MessageFormat.SystemMetadata_Current_Version); Assert.assertEquals(MessageFormat.SystemMetadataRecordType.DeleteRecord.ordinal(), systemMetadataBuf.getShort()); Assert.assertEquals(true, systemMetadataBuf.get() == 1 ? true : false); crc = new Crc32(); crc.update(systemMetadataOutput, 0, systemMetadataSize - MessageFormat.Crc_Size); Assert.assertEquals(crc.getValue(), systemMetadataBuf.getLong()); }