Search in sources :

Example 6 with DbusEventFactory

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);
}
Also used : Field(java.lang.reflect.Field) DbusEventFactory(com.linkedin.databus.core.DbusEventFactory)

Example 7 with DbusEventFactory

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());
}
Also used : DbusEventFactory(com.linkedin.databus.core.DbusEventFactory) ByteBuffer(java.nio.ByteBuffer) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) IOException(java.io.IOException)

Aggregations

DbusEventFactory (com.linkedin.databus.core.DbusEventFactory)7 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)3 ByteBuffer (java.nio.ByteBuffer)3 DbusEventV1Factory (com.linkedin.databus.core.DbusEventV1Factory)2 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)2 IOException (java.io.IOException)2 Test (org.testng.annotations.Test)2 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)1 DbusEventInternalWritable (com.linkedin.databus.core.DbusEventInternalWritable)1 DbusEventKey (com.linkedin.databus.core.DbusEventKey)1 UnsupportedDbusEventVersionRuntimeException (com.linkedin.databus.core.UnsupportedDbusEventVersionRuntimeException)1 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)1 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)1 ExceptionListenerTestHandler (com.linkedin.databus2.test.container.ExceptionListenerTestHandler)1 SimpleTestClientConnection (com.linkedin.databus2.test.container.SimpleTestClientConnection)1 SimpleTestMessageReader (com.linkedin.databus2.test.container.SimpleTestMessageReader)1 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1