Search in sources :

Example 46 with SchemaMetadata

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

the class SchemaBranchLifeCycleTest method mergeSchemaWhenRootVersionIsNotLatest.

@Test
public void mergeSchemaWhenRootVersionIsNotLatest() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException {
    SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE);
    SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc");
    SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId());
    SchemaIdVersion schemaBranch1Version1 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
    addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device-compat.avsc");
    schemaRegistryClient.mergeSchemaVersion(schemaBranch1Version1.getSchemaVersionId());
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 47 with SchemaMetadata

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

the class SchemaBranchLifeCycleTest method addIncompatibleSchemaToBranch.

@Test(expected = IncompatibleSchemaException.class)
public void addIncompatibleSchemaToBranch() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException {
    SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.BACKWARD);
    SchemaIdVersion masterSchemaIdVersion = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc");
    SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion.getSchemaVersionId());
    addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 48 with SchemaMetadata

use of com.hortonworks.registries.schemaregistry.SchemaMetadata 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 49 with SchemaMetadata

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

the class AvroSchemaRegistryTest method testSchemaTextAsEmpty.

@Test(expected = InvalidSchemaException.class)
public void testSchemaTextAsEmpty() throws Exception {
    SchemaMetadata schemaMetadataInfo = createSchemaInfo(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    // registering a new schema
    Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadataInfo, new SchemaVersion("", "Initial version of the schema")).getVersion();
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Test(org.junit.Test)

Example 50 with SchemaMetadata

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

the class AvroSchemaRegistryTest method testInvalidSchema.

@Test(expected = InvalidSchemaException.class)
public void testInvalidSchema() throws Exception {
    String schema = "--- random invalid schema ---" + new Date();
    SchemaMetadata schemaMetadataInfo = createSchemaInfo(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    // registering a new schema
    Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadataInfo, new SchemaVersion(schema, "Initial version of the schema")).getVersion();
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)56 Test (org.junit.Test)35 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)33 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)30 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