use of com.linkedin.databus.core.DbusEventFactory in project databus by linkedin.
the class DbusEventBufferReflector method setEventFactory.
private DbusEventFactory setEventFactory() throws NoSuchFieldException, IllegalAccessException {
Field field = DbusEventBuffer.class.getDeclaredField("_eventFactory");
field.setAccessible(true);
return (DbusEventFactory) field.get(_evb);
}
use of com.linkedin.databus.core.DbusEventFactory in project databus by linkedin.
the class TestDbusEvent method convertV2toV1EOP.
public void convertV2toV1EOP(DbusEventKey dbusKey) {
// both versions share same _byteOrder var
final DbusEventFactory eventV2Factory = new DbusEventV2Factory();
ByteBuffer serializationBuffer = ByteBuffer.allocate(1000).order(eventV2Factory.getByteOrder());
try {
DbusEventInfo eventInfo = new DbusEventInfo(null, 0L, partitionId, partitionId, System.nanoTime(), DbusEventInternalWritable.EOPMarkerSrcId, DbusEventInternalWritable.emptyMd5, new byte[0], // enable tracing
false, // autocommit
true, DbusEventFactory.DBUS_EVENT_V2, // payload schema version
(short) 0, // Metadata
null);
// create v2 event
DbusEventFactory.serializeEvent(dbusKey, serializationBuffer, eventInfo);
} catch (KeyTypeNotImplementedException e2) {
fail(e2.getLocalizedMessage());
}
DbusEventInternalReadable e = null;
try {
e = DbusEventFactoryForTesting.createReadOnlyDbusEventFromBuffer(serializationBuffer, 0, 200L, DbusEventFactory.DBUS_EVENT_V2);
} catch (Exception e1) {
fail("Not supposed to throw exception");
}
assertTrue("event V2 is invalid", e.isValid());
// now let's convert the event
DbusEventV2 eV2 = (DbusEventV2) e;
DbusEventV1 eV1 = null;
try {
eV1 = (DbusEventV1) eV2.convertToV1();
} catch (KeyTypeNotImplementedException e1) {
fail(e1.getLocalizedMessage());
}
LOG.info("ev1 =" + eV1);
// let's compare the fields
assertTrue("event v1 is invalid", eV1.isValid(true));
assertEquals(eV1.getVersion(), DbusEventFactory.DBUS_EVENT_V1);
assertEquals(eV2.getVersion(), DbusEventFactory.DBUS_EVENT_V2);
if (dbusKey.getKeyType() == KeyType.LONG)
assertEquals(eV2.key(), eV1.key());
else if (dbusKey.getKeyType() == KeyType.STRING) {
assertTrue(Arrays.equals(eV2.keyBytes(), eV1.keyBytes()));
assertEquals(eV2.keyBytesLength(), eV1.keyBytesLength());
}
assertEquals(eV2.getPartitionId(), eV1.getPartitionId());
assertEquals(eV2.srcId(), eV1.srcId());
assertEquals(eV2.isTraceEnabled(), eV1.isTraceEnabled());
assertEquals(eV2.timestampInNanos(), eV1.timestampInNanos());
assertEquals(eV1.valueLength(), 0);
assertEquals(eV2.bodyCrc(), eV1.bodyCrc());
// and these fields should be the same
assertFalse(eV2.headerCrc() == eV1.headerCrc());
assertFalse(eV2.size() == eV1.size());
}
Aggregations