use of com.hortonworks.registries.serdes.Device in project registry by hortonworks.
the class KafkaAvroSerDesTest method testAvroRecordsSerDes.
@Test
public void testAvroRecordsSerDes() throws Exception {
String topicPrefix = TEST_NAME_RULE.getMethodName() + "-" + System.currentTimeMillis();
String genericRecordTopic = topicPrefix + "-generic";
Object genericRecordForDevice = AvroSchemaRegistryClientUtil.createGenericRecordForDevice();
_testKafkaSerDes(genericRecordTopic, true, genericRecordForDevice);
_testKafkaSerDes(genericRecordTopic, true, genericRecordForDevice);
Device specificRecord = AvroSchemaRegistryClientUtil.createSpecificRecord();
String specificRecordTopic = topicPrefix + "-specific";
_testKafkaSerDes(specificRecordTopic, true, specificRecord);
_testKafkaSerDes(specificRecordTopic, false, specificRecord);
}
use of com.hortonworks.registries.serdes.Device in project registry by hortonworks.
the class MessageContextBasedAvroSerDesTest method testSerDes.
@Test
public void testSerDes() throws Exception {
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder("msgCtx-" + System.currentTimeMillis()).schemaGroup("custom").type(AvroSchemaProvider.TYPE).compatibility(SchemaCompatibility.BACKWARD).build();
SchemaIdVersion schemaIdVersion = new SchemaIdVersion(1L, 1, 1L);
Device input = new Device(1L, "device", 1, System.currentTimeMillis());
SchemaVersionInfo schemaVersionInfo = new SchemaVersionInfo(1l, input.getName().toString(), schemaIdVersion.getVersion(), input.getSchema().toString(), System.currentTimeMillis(), "");
new Expectations() {
{
mockSchemaRegistryClient.addSchemaVersion(withInstanceOf(SchemaMetadata.class), withInstanceOf(SchemaVersion.class));
result = schemaIdVersion;
mockSchemaRegistryClient.getSchemaMetadataInfo(anyString);
result = new SchemaMetadataInfo(schemaMetadata);
mockSchemaRegistryClient.getSchemaVersionInfo(withInstanceOf(SchemaVersionKey.class));
result = schemaVersionInfo;
}
};
MessageContextBasedAvroSerializer serializer = new MessageContextBasedAvroSerializer();
serializer.init(Collections.emptyMap());
MessageContext messageContext = serializer.serialize(input, schemaMetadata);
MessageContextBasedAvroDeserializer deserializer = new MessageContextBasedAvroDeserializer();
deserializer.init(Collections.emptyMap());
Object deserializedObject = deserializer.deserialize(messageContext, null);
Assert.assertTrue(SpecificData.get().compare(input, deserializedObject, input.getSchema()) == 0);
}
use of com.hortonworks.registries.serdes.Device in project registry by hortonworks.
the class SchemaVersionProtocolHandlerTest method _testSerDes.
private void _testSerDes(Long id, Number serdesProtocolVersion) throws Exception {
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder("random-" + System.currentTimeMillis()).schemaGroup("custom").type(AvroSchemaProvider.TYPE).compatibility(SchemaCompatibility.BACKWARD).build();
SchemaIdVersion schemaIdVersion = new SchemaIdVersion(1L, 1, id);
Device input = new Device(1L, "device", 1, System.currentTimeMillis());
SchemaVersionInfo schemaVersionInfo = new SchemaVersionInfo(id, input.getName().toString(), schemaIdVersion.getVersion(), input.getSchema().toString(), System.currentTimeMillis(), "some device");
new Expectations() {
{
mockSchemaRegistryClient.getSchemaMetadataInfo(anyString);
result = new SchemaMetadataInfo(schemaMetadata);
minTimes = 0;
maxTimes = 1;
mockSchemaRegistryClient.addSchemaVersion(withInstanceOf(SchemaMetadata.class), withInstanceOf(SchemaVersion.class));
result = schemaIdVersion;
minTimes = 0;
maxTimes = 1;
mockSchemaRegistryClient.getSchemaVersionInfo(withInstanceOf(SchemaVersionKey.class));
result = schemaVersionInfo;
minTimes = 0;
maxTimes = 1;
}
};
AvroSnapshotSerializer serializer = new AvroSnapshotSerializer();
serializer.init(Collections.singletonMap(SERDES_PROTOCOL_VERSION, serdesProtocolVersion));
AvroSnapshotDeserializer deserializer = new AvroSnapshotDeserializer();
deserializer.init(Collections.emptyMap());
byte[] serializedData = serializer.serialize(input, schemaMetadata);
Object deserializedObj = deserializer.deserialize(new ByteArrayInputStream(serializedData), null);
Assert.assertTrue(SpecificData.get().compare(input, deserializedObj, input.getSchema()) == 0);
}
Aggregations