use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer in project registry by hortonworks.
the class AvroSerDesInitClosureTest method testSerClosedSer.
@Test(expected = IllegalStateException.class)
public void testSerClosedSer() throws Exception {
AvroSnapshotSerializer serializer = new AvroSnapshotSerializer();
serializer.init(Collections.emptyMap());
serializer.close();
serializer.serialize(new Object(), schemaMetadata);
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer 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);
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer in project registry by hortonworks.
the class AvroSchemaRegistryClientTest method _testAvroSerDesGenericObj.
private void _testAvroSerDesGenericObj(Byte protocolId) throws IOException, InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {
Map<String, Object> config = Maps.newHashMap();
config.putAll(SCHEMA_REGISTRY_CLIENT_CONF);
config.put(SERDES_PROTOCOL_VERSION, protocolId);
AvroSnapshotSerializer avroSnapshotSerializer = new AvroSnapshotSerializer();
avroSnapshotSerializer.init(config);
AvroSnapshotDeserializer avroSnapshotDeserializer = new AvroSnapshotDeserializer();
avroSnapshotDeserializer.init(config);
String deviceSchema = AvroSchemaRegistryClientUtil.getSchema("/device.avsc");
SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BOTH);
SchemaIdVersion v1 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(deviceSchema, "Initial version of the schema"));
Assert.assertNotNull(v1);
Object deviceObject = AvroSchemaRegistryClientUtil.createGenericRecordForDevice();
byte[] serializedData = avroSnapshotSerializer.serialize(deviceObject, schemaMetadata);
Object deserializedObj = avroSnapshotDeserializer.deserialize(new ByteArrayInputStream(serializedData), null);
Assert.assertEquals(deviceObject, deserializedObj);
}
Aggregations