use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer in project registry by hortonworks.
the class AvroSerDesInitClosureTest method testDeserWihtoutInit.
@Test(expected = IllegalStateException.class)
public void testDeserWihtoutInit() throws Exception {
AvroSnapshotDeserializer deserializer = new AvroSnapshotDeserializer();
deserializer.deserialize(new ByteArrayInputStream(new byte[] {}), 1);
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer in project registry by hortonworks.
the class SampleSchemaRegistryClientApp method runAvroSerDesApis.
public void runAvroSerDesApis() throws IOException {
// using builtin avro serializer/deserializer
AvroSnapshotSerializer avroSnapshotSerializer = new AvroSnapshotSerializer();
avroSnapshotSerializer.init(config);
AvroSnapshotDeserializer avroSnapshotDeserializer = new AvroSnapshotDeserializer();
avroSnapshotDeserializer.init(config);
Object deviceObject = createGenericRecordForDevice("/device.avsc");
SchemaMetadata schemaMetadata = createSchemaMetadata("avro-serializer-schema-" + System.currentTimeMillis());
byte[] serializedData = avroSnapshotSerializer.serialize(deviceObject, schemaMetadata);
Object deserializedObj = avroSnapshotDeserializer.deserialize(new ByteArrayInputStream(serializedData), null);
LOG.info("Serialized and deserialized objects are equal: [{}] ", deviceObject.equals(deserializedObj));
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer in project registry by hortonworks.
the class SampleSchemaRegistryClientApp method runDefaultSerDesApi.
public void runDefaultSerDesApi() throws Exception {
String type = AvroSchemaProvider.TYPE;
AvroSnapshotSerializer serializer = schemaRegistryClient.getDefaultSerializer(type);
serializer.init(config);
AvroSnapshotDeserializer deserializer = schemaRegistryClient.getDefaultDeserializer(type);
deserializer.init(config);
Object deviceObject = createGenericRecordForDevice("/device.avsc");
SchemaMetadata schemaMetadata = createSchemaMetadata("avro-serializer-schema-" + System.currentTimeMillis());
byte[] serializedData = serializer.serialize(deviceObject, schemaMetadata);
Object deserializedObj = deserializer.deserialize(new ByteArrayInputStream(serializedData), null);
LOG.info("Serialized and deserialized objects are equal: [{}] ", deviceObject.equals(deserializedObj));
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer in project registry by hortonworks.
the class AvroSchemaRegistryClientTest method _testAvroSerDesPrimitives.
private void _testAvroSerDesPrimitives(Byte protocolId) {
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);
Object[] objects = AvroSchemaRegistryClientUtil.generatePrimitivePayloads();
for (Object obj : objects) {
String name = obj != null ? obj.getClass().getName() : Void.TYPE.getName();
SchemaMetadata schemaMetadata = createSchemaMetadata(name, SchemaCompatibility.BOTH);
byte[] serializedData = avroSnapshotSerializer.serialize(obj, schemaMetadata);
Object deserializedObj = avroSnapshotDeserializer.deserialize(new ByteArrayInputStream(serializedData), null);
if (obj instanceof byte[]) {
Assert.assertArrayEquals((byte[]) obj, (byte[]) deserializedObj);
} else if (deserializedObj instanceof Utf8) {
Assert.assertEquals(obj, deserializedObj.toString());
} else {
Assert.assertEquals(obj, deserializedObj);
}
}
}
use of com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer in project registry by hortonworks.
the class AvroSerDesInitClosureTest method testDeserClosedSer.
@Test(expected = IllegalStateException.class)
public void testDeserClosedSer() throws Exception {
AvroSnapshotDeserializer deserializer = new AvroSnapshotDeserializer();
deserializer.init(Collections.emptyMap());
deserializer.close();
deserializer.deserialize(new ByteArrayInputStream(new byte[] {}), 1);
}
Aggregations