Source:
<code>public void testBlobRecordWithMetadataContent() throws IOException, MessageFormatException { List<String> keys = getKeys(60, 5); ByteBuffer metadataContent = getMetadataContent(keys); int metadataContentSize = MessageFormatRecord.Metadata_Content_Format_V1.getMetadataContentSize(60, keys.size()); long blobSize = MessageFormatRecord.Blob_Format_V2.getBlobRecordSize(metadataContentSize); metadataContent.rewind(); ByteBuffer blob = ByteBuffer.allocate((int) blobSize); BlobOutput outputData = getBlobRecordV2((int) metadataContentSize, BlobType.MetadataBlob, metadataContent, blob); Assert.assertEquals(outputData.getSize(), metadataContentSize); byte[] verify = new byte[(int) metadataContentSize]; outputData.getStream().read(verify); Assert.assertArrayEquals(verify, metadataContent.array()); metadataContent.flip(); List<String> outputList = deserializeMetadataContent(metadataContent); compareLists(outputList, keys); blob.flip(); byte currentRandomByte = blob.get(1); blob.put(1, (byte) (currentRandomByte + 1)); try { MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(blob)); <START> Assert.assertEquals(true, false); <END> } catch (MessageFormatException e) { Assert.assertEquals(e.getErrorCode(), MessageFormatErrorCodes.Unknown_Format_Version); } blob.rewind(); blob.put(1, currentRandomByte); currentRandomByte = blob.get(2); blob.put(2, (byte) (currentRandomByte + 1)); try { MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(blob)); Assert.assertEquals(true, false); } catch (MessageFormatException e) { Assert.assertEquals(e.getErrorCode(), MessageFormatErrorCodes.Data_Corrupt); } blob.rewind(); blob.put(2, currentRandomByte); currentRandomByte = blob.get(50); blob.put(50, (byte) (currentRandomByte + 1)); try { MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(blob)); Assert.assertEquals(true, false); } catch (MessageFormatException e) { Assert.assertEquals(e.getErrorCode(), MessageFormatErrorCodes.Data_Corrupt); } }</code><technical_language>places</technical_language>

Target:
public void testBlobRecordWithMetadataContent() throws IOException, MessageFormatException { List<StoreKey> keys = getKeys(60, 5); ByteBuffer metadataContent = getSerializedMetadataContent(keys); int metadataContentSize = MessageFormatRecord.Metadata_Content_Format_V1.getMetadataContentSize(keys.get(0).sizeInBytes(), keys.size()); long blobSize = MessageFormatRecord.Blob_Format_V2.getBlobRecordSize(metadataContentSize); ByteBuffer blob = ByteBuffer.allocate((int) blobSize); BlobData blobData = getBlobRecordV2(metadataContentSize, BlobType.MetadataBlob, metadataContent, blob); Assert.assertEquals(metadataContentSize, blobData.getSize()); byte[] verify = new byte[metadataContentSize]; blobData.getStream().read(verify); Assert.assertArrayEquals("Metadata content mismatch", metadataContent.array(), verify); metadataContent.rewind(); List<StoreKey> outputList = deserializeMetadataContent(metadataContent, new MockIdFactory()); Assert.assertEquals("List of keys dont match", keys, outputList); blob.rewind(); byte savedByte = blob.get(1); blob.put(1, (byte) (savedByte + 1)); try { MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(blob)); Assert.fail("Failed to detect corruption of Blob record version "); } catch (MessageFormatException e) { Assert.assertEquals("Error code mismatch", MessageFormatErrorCodes.Unknown_Format_Version, e.getErrorCode()); } blob.rewind(); blob.put(1, savedByte); savedByte = blob.get(2); blob.put(2, (byte) (savedByte + 1)); try { MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(blob)); Assert.fail("Failed to detect corruption of blob type"); } catch (MessageFormatException e) { Assert.assertEquals("Error code mismatch", MessageFormatErrorCodes.Data_Corrupt, e.getErrorCode()); } blob.rewind(); blob.put(2, savedByte); savedByte = blob.get((int) blobSize - metadataContentSize + 10); blob.put((int) blobSize - metadataContentSize + 10, (byte) (savedByte + 1)); try { MessageFormatRecord.deserializeBlob(new ByteBufferInputStream(blob)); Assert.fail("Failed to detect corruption of metadata content"); } catch (MessageFormatException e) { Assert.assertEquals("Error code mismatch", MessageFormatErrorCodes.Data_Corrupt, e.getErrorCode()); } }