@Test
public void testValueCrc()
throws Exception
{

  String randomValue = RngUtils.randomString(20);
  ByteBuffer directBuffer = ByteBuffer.allocateDirect(5000).order(_eventV1Factory.getByteOrder());
  DbusEventInfo eventInfo = new DbusEventInfo(DbusOpcode.UPSERT, 0L, (short)0, partitionId, timeStamp, srcId,
                                              schemaId, randomValue.getBytes(Charset.defaultCharset()), false, false);
  eventInfo.setEventSerializationVersion(DbusEventFactory.DBUS_EVENT_V1);  // make this explicit
  DbusEventFactory.serializeEvent(new DbusEventKey(key), directBuffer, eventInfo);
  DbusEventInternalReadable e = _eventV1Factory.createReadOnlyDbusEventFromBuffer(directBuffer, 0);
  DbusEventInternalWritable writableEvent = DbusEventCorrupter.makeWritable(e);  // for testing only!
  writableEvent.setSequence(200L);
  // Test case 1: Set the value CRC correctly and ensure it passes
  long calcValueCRC = 0;
  try
  {
    // Set the value CRC, then reset the header CRC since it covers the value CRC:
    calcValueCRC = e.getCalculatedValueCrc();
    writableEvent.setValueCrc(calcValueCRC);
    writableEvent.applyCrc();
  }
  catch (Exception e1)
  {
    fail("Not supposed to throw exception");
  }
  assertTrue(e.isValid());
  long actualValueCRC = e.bodyCrc();
  assertEquals("value CRCs should match", calcValueCRC, actualValueCRC);
  // Test case 2: Set the value CRC incorrectly
  try
  {
    writableEvent.setValueCrc(calcValueCRC + 1);
    writableEvent.applyCrc();
  }
  catch (Exception e1)
  {
    fail("Not supposed to throw exception");
  }
  actualValueCRC = e.bodyCrc();
  assertEquals("value CRCs should match", calcValueCRC+1, actualValueCRC);
  assertTrue(!e.isValid());
}