Search in sources :

Example 1 with SchemaCompatibility

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

the class AvroSchemaRegistryTest method testRegistrySchemaOps.

@Test
public void testRegistrySchemaOps() throws Exception {
    SchemaCompatibility compatibility = SchemaCompatibility.BOTH;
    SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(schemaName).type(AvroSchemaProvider.TYPE).description("devices schema").compatibility(compatibility).schemaGroup(SCHEMA_GROUP).build();
    Long schemaMetadataId = schemaRegistry.registerSchemaMetadata(schemaMetadata);
    SchemaMetadata schemaMetadataReturned = schemaRegistry.getSchemaMetadataInfo(schemaMetadataId).getSchemaMetadata();
    Assert.assertEquals(schemaMetadata, schemaMetadataReturned);
    Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(schema1, "initial version of the schema")).getVersion();
    Integer v2 = schemaRegistry.addSchemaVersion(schemaName, new SchemaVersion(schema2, "second version of the the schema")).getVersion();
    Assert.assertTrue(v2 == v1 + 1);
    Collection<SchemaVersionInfo> allSchemaVersions = schemaRegistry.getAllVersions(schemaName);
    Assert.assertTrue(allSchemaVersions.size() == 2);
    SchemaMetadataInfo schemaMetadataInfo = schemaRegistry.getSchemaMetadataInfo(schemaName);
    Assert.assertEquals(schemaMetadata, schemaMetadataInfo.getSchemaMetadata());
    Integer schemaVersion = schemaRegistry.getSchemaVersionInfo(schemaName, schema1).getVersion();
    Assert.assertEquals(v1, schemaVersion);
    SchemaVersionInfo schemaVersionInfo1 = schemaRegistry.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v1));
    Assert.assertEquals(schemaVersionInfo1.getSchemaText(), schema1);
    SchemaVersionInfo schemaVersionInfo2 = schemaRegistry.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v2));
    Assert.assertEquals(schemaVersionInfo2.getSchemaText(), schema2);
    // receive the same version as earlier without adding a new schema entry as it exists in the same schema group.
    Integer version = schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(schema1, "already added schema")).getVersion();
    Assert.assertEquals(version, v1);
    // aggregate apis
    AggregatedSchemaMetadataInfo aggregatedSchemaMetadata = schemaRegistry.getAggregatedSchemaMetadataInfo(schemaName);
    Assert.assertEquals(allSchemaVersions.size(), aggregatedSchemaMetadata.getSchemaBranches().iterator().next().getSchemaVersionInfos().size());
    Assert.assertTrue(aggregatedSchemaMetadata.getSerDesInfos().isEmpty());
    Collection<AggregatedSchemaMetadataInfo> aggregatedSchemaMetadataCollection = schemaRegistry.findAggregatedSchemaMetadata(Collections.emptyMap());
    Assert.assertEquals(1, aggregatedSchemaMetadataCollection.size());
    // Serializing and deserializing AggregatedSchemaMetadataInfo should not throw any errors
    String aggregateSchemaMetadataStr = new ObjectMapper().writeValueAsString(aggregatedSchemaMetadataCollection);
    Collection<AggregatedSchemaMetadataInfo> returnedResult = new ObjectMapper().readValue(aggregateSchemaMetadataStr, new TypeReference<Collection<AggregatedSchemaMetadataInfo>>() {
    });
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) Collection(java.util.Collection) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Test(org.junit.Test)

Example 2 with SchemaCompatibility

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

the class AvroSchemaRegistryTest method testSchemaMetadataOps.

@Test
public void testSchemaMetadataOps() throws Exception {
    for (SchemaCompatibility schemaCompatibility : SchemaCompatibility.values()) {
        SchemaMetadata schemaMetadata = new SchemaMetadata.Builder("compatibility-" + schemaCompatibility).type(AvroSchemaProvider.TYPE).description("devices schema").compatibility(schemaCompatibility).schemaGroup(SCHEMA_GROUP).build();
        Long schemaMetadataId = schemaRegistry.registerSchemaMetadata(schemaMetadata);
        SchemaMetadata schemaMetadataReturned = schemaRegistry.getSchemaMetadataInfo(schemaMetadataId).getSchemaMetadata();
        Assert.assertEquals(schemaMetadata, schemaMetadataReturned);
    }
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) Test(org.junit.Test)

Example 3 with SchemaCompatibility

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

the class AvroCompatibilityCheckerTest method testInvalidCompatibilities.

@Test
public void testInvalidCompatibilities() throws Exception {
    SchemaCompatibility[] compatibilities = { SchemaCompatibility.BACKWARD, SchemaCompatibility.FORWARD, SchemaCompatibility.BOTH };
    for (SchemaCompatibility compatibility : compatibilities) {
        CompatibilityResult compatibilityResult = new AvroSchemaProvider().checkCompatibility(fetchResourceText("/avro/book-invalid-compat.avsc"), initialVersionSchema(), compatibility);
        Assert.assertFalse(compatibilityResult.isCompatible());
    }
}
Also used : SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) Test(org.junit.Test)

Aggregations

SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)3 Test (org.junit.Test)3 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AggregatedSchemaMetadataInfo (com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo)1 CompatibilityResult (com.hortonworks.registries.schemaregistry.CompatibilityResult)1 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)1 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)1 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)1 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)1 Collection (java.util.Collection)1