Search in sources :

Example 31 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata 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);
        }
    }
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) AvroSnapshotDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer) Utf8(org.apache.avro.util.Utf8) AvroSnapshotSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer)

Example 32 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method doTestSchemaVersionLifeCycleStates.

private void doTestSchemaVersionLifeCycleStates(SchemaValidationLevel validationLevel) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, IOException, SchemaLifecycleException, SchemaBranchNotFoundException {
    SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(TEST_NAME_RULE.getMethodName() + "-schema").type(AvroSchemaProvider.TYPE).schemaGroup("group").compatibility(SchemaCompatibility.BOTH).validationLevel(validationLevel).build();
    String schemaName = schemaMetadata.getName();
    Long id = SCHEMA_REGISTRY_CLIENT.registerSchemaMetadata(schemaMetadata);
    SchemaIdVersion schemaIdVersion_1 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-1.avsc"), "Initial version of the schema"));
    SchemaIdVersion schemaIdVersion_2 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-2.avsc"), "Second version of the schema"));
    // disable version 2
    SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(schemaIdVersion_2.getSchemaVersionId());
    Assert.assertEquals(SchemaVersionLifecycleStates.DISABLED.getId(), SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2).getStateId());
    // add version 3
    SchemaIdVersion schemaIdVersion_3 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-3.avsc"), "Third version of the schema, removes name field"));
    // enable version 2
    SCHEMA_REGISTRY_CLIENT.enableSchemaVersion(schemaIdVersion_2.getSchemaVersionId());
    Assert.assertEquals(SchemaVersionLifecycleStates.ENABLED.getId(), SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2).getStateId());
    // disable version 3
    SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(schemaIdVersion_3.getSchemaVersionId());
    Assert.assertEquals(SchemaVersionLifecycleStates.DISABLED.getId(), SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_3).getStateId());
    // enable version 3
    SCHEMA_REGISTRY_CLIENT.enableSchemaVersion(schemaIdVersion_3.getSchemaVersionId());
    Assert.assertEquals(SchemaVersionLifecycleStates.ENABLED.getId(), SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_3).getStateId());
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion)

Example 33 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method doTestSchemaVersionEnableState.

public void doTestSchemaVersionEnableState(String schemaName) throws Exception {
    String schema = AvroSchemaRegistryClientUtil.getSchema("/device.avsc");
    String incompatSchema = AvroSchemaRegistryClientUtil.getSchema("/device-compat.avsc");
    SchemaMetadata schemaMetadata = createSchemaMetadata(schemaName, SchemaCompatibility.BACKWARD);
    // registering a new schema
    SchemaIdVersion schemaIdVersion_1 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema"));
    // adding a new version of the schema
    SchemaVersion incompatSchemaInfo = new SchemaVersion(incompatSchema, "second version");
    SchemaIdVersion schemaIdVersion_2 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, incompatSchemaInfo);
    Long schemaVersionId_2 = schemaIdVersion_2.getSchemaVersionId();
    SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(schemaVersionId_2);
    SchemaVersionInfo schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
    System.out.println("disable :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
    Assert.assertEquals(SchemaVersionLifecycleStates.DISABLED.getId(), schemaVersionInfo.getStateId());
    SCHEMA_REGISTRY_CLIENT.enableSchemaVersion(schemaVersionId_2);
    schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
    System.out.println("enable :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
    Assert.assertEquals(SchemaVersionLifecycleStates.ENABLED.getId(), schemaVersionInfo.getStateId());
    SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(schemaVersionId_2);
    schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
    System.out.println("disable :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
    Assert.assertEquals(SchemaVersionLifecycleStates.DISABLED.getId(), schemaVersionInfo.getStateId());
    SCHEMA_REGISTRY_CLIENT.archiveSchemaVersion(schemaVersionId_2);
    schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
    System.out.println("archive :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
    Assert.assertEquals(SchemaVersionLifecycleStates.ARCHIVED.getId(), schemaVersionInfo.getStateId());
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion)

Example 34 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method addAndDeleteSchemaVersion.

private SchemaVersionKey addAndDeleteSchemaVersion(String schemaName) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, IOException, SchemaBranchNotFoundException, SchemaLifecycleException {
    SchemaMetadata schemaMetadata = createSchemaMetadata(schemaName, SchemaCompatibility.BOTH);
    SchemaIdVersion schemaIdVersion = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/device.avsc"), "Initial version of the schema"));
    SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaMetadata.getName(), schemaIdVersion.getVersion());
    SCHEMA_REGISTRY_CLIENT.deleteSchemaVersion(schemaVersionKey);
    return schemaVersionKey;
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey)

Example 35 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testIncompatibleSchemas.

@Test(expected = IncompatibleSchemaException.class)
public void testIncompatibleSchemas() throws Exception {
    String schema = AvroSchemaRegistryClientUtil.getSchema("/device.avsc");
    String incompatSchema = AvroSchemaRegistryClientUtil.getSchema("/device-incompat.avsc");
    SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    // registering a new schema
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema"));
    // adding a new version of the schema
    SchemaVersion incompatSchemaInfo = new SchemaVersion(incompatSchema, "second version");
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, incompatSchemaInfo);
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Aggregations

SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)57 Test (org.junit.Test)35 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)33 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)31 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)21 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)17 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)15 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)11 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)11 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)9 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)8 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)7 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)6 SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)6 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)6 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)6 Collection (java.util.Collection)6 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)5