use of com.linkedin.databus.core.DbusEventPart in project databus by linkedin.
the class TestInternalMetadata method testGetMetadata_HappyPath.
/**
* Verifies that getMetadata() returns the expected GenericRecord for the event's
* metadata and that it has the expected fields and values in it.
*/
@Test
public void testGetMetadata_HappyPath() throws Exception {
LOG.info("starting testGetMetadata_HappyPath()");
// build the event's metadata and then the event
DbusEventPart metadataPart = createMetadataPart();
DbusEvent event = createEvent(metadataPart);
// create a metadata schema set that correctly corresponds to the metadata
VersionedSchemaSet metadataSchemaSet = new VersionedSchemaSet();
metadataSchemaSet.add(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE, // METADATA_SCHEMA_VERSION
metadataPart.getSchemaVersion(), // METADATA_SCHEMA_CHECKSUM
new SchemaId(metadataPart.getSchemaDigest()), CORRECT_METADATA_SCHEMA, // preserve original string
true);
// now create the decoder and use it to extract and decode the event's metadata
DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
try {
GenericRecord reuse = null;
GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
Assert.assertNotNull(decodedMetadata, "getMetadata() returned null GenericRecord;");
Utf8 etag = (Utf8) decodedMetadata.get("etag");
Assert.assertEquals(etag.toString(), "dunno what an etag is");
Integer flags = (Integer) decodedMetadata.get("flags");
Assert.assertEquals(flags, null, "expected flags to be null");
Long expires = (Long) decodedMetadata.get("expires");
Assert.assertNotNull(expires, "expected expires to have a value;");
Assert.assertEquals(expires.longValue(), 1366150681);
Utf8 nonexistentField = (Utf8) decodedMetadata.get("nonexistentField");
Assert.assertNull(nonexistentField, "unexpected value for 'nonexistentField';");
} catch (Exception ex) {
Assert.fail("unexpected error decoding metadata: " + ex);
}
LOG.info("leaving testGetMetadata_HappyPath()");
}
use of com.linkedin.databus.core.DbusEventPart in project databus by linkedin.
the class DbusEventAvroDecoder method getMetadataSchema.
/**
* Returns the single version of the metadata schema specified in the given event's header.
* For INTERNAL USE ONLY (by Espresso and Databus). This is not a stable API and may change
* without warning!
*
* @param e DbusEvent
* @return {AvroSchema, "metadata-source", version} tuple for given event 'e' with
* metadata-schema-id; null if event contains no metadata
* @throws DatabusRuntimeException if event contains metadata but schema to decode it is missing
*/
public VersionedSchema getMetadataSchema(DbusEvent e) {
DbusEventPart metadataPart = e.getPayloadMetadataPart();
if (null == metadataPart) {
LOG.debug("No metadata for event " + e);
return null;
}
VersionedSchema schema = getMetadataSchema(metadataPart);
if (null == schema) {
throw new DatabusRuntimeException("No schema available to decode metadata for event " + e);
}
return schema;
}
Aggregations