Search in sources :

Example 1 with Device

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);
}
Also used : Device(com.hortonworks.registries.serdes.Device) Test(org.junit.Test) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest)

Example 2 with Device

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);
}
Also used : Expectations(mockit.Expectations) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Device(com.hortonworks.registries.serdes.Device) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Test(org.junit.Test)

Example 3 with Device

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);
}
Also used : Expectations(mockit.Expectations) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Device(com.hortonworks.registries.serdes.Device) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) AvroSnapshotDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer) AvroSnapshotSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)

Aggregations

Device (com.hortonworks.registries.serdes.Device)3 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)2 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)2 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)2 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)2 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)2 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)2 Expectations (mockit.Expectations)2 Test (org.junit.Test)2 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)1 AvroSnapshotDeserializer (com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer)1 AvroSnapshotSerializer (com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1