Search in sources :

Example 36 with SchemaIdVersion

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

the class SchemaBranchLifeCycleTest method addInvalidSchemaToBranch.

@Test(expected = InvalidSchemaException.class)
public void addInvalidSchemaToBranch() 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());
    String schema2 = "--- invalid schema ---";
    schemaRegistryClient.addSchemaVersion(schemaBranch1.getName(), schemaMetadata.getName(), new SchemaVersion(schema2, "second version"));
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 37 with SchemaIdVersion

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

the class SchemaBranchLifeCycleTest method deleteRootSchemaOfBranch.

@Test(expected = SchemaLifecycleException.class)
public void deleteRootSchemaOfBranch() throws InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, IOException, SchemaBranchAlreadyExistsException, SchemaLifecycleException {
    SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE);
    SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc");
    addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId());
    schemaRegistryClient.archiveSchemaVersion(masterSchemaIdVersion1.getSchemaVersionId());
    schemaRegistryClient.deleteSchemaVersion(masterSchemaIdVersion1.getSchemaVersionId());
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 38 with SchemaIdVersion

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

the class SchemaBranchLifeCycleTest method mergeSchemaWithDefaultMergeStrategy.

@Test
public void mergeSchemaWithDefaultMergeStrategy() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException {
    SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.toString(), 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");
    SchemaIdVersion schemaBranch1Version2 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc");
    schemaRegistryClient.mergeSchemaVersion(schemaBranch1Version2.getSchemaVersionId());
    Collection<SchemaVersionInfo> branchSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaBranch1.getName(), schemaMetadata.getName());
    Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaMetadata.getName());
    Assert.assertTrue(masterSchemaVersionInfos.size() == 2);
    Assert.assertTrue(branchSchemaVersionInfos.size() == 3);
    Long branchVersionsInInitiatedState = branchSchemaVersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.INITIATED.getId())).count();
    Long masterVersionsInEnabledState = masterSchemaVersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.ENABLED.getId())).count();
    Assert.assertTrue(branchVersionsInInitiatedState == 2);
    Assert.assertTrue(masterVersionsInEnabledState == 2);
}
Also used : Arrays(java.util.Arrays) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) SchemaRegistryTestProfileType(com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) RunWith(org.junit.runner.RunWith) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) AvroSchemaRegistryClientUtil(com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TestName(org.junit.rules.TestName) After(org.junit.After) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) Before(org.junit.Before) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SetUtils(org.apache.commons.collections.SetUtils) Collection(java.util.Collection) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) Set(java.util.Set) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) Rule(org.junit.Rule) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) CustomParameterizedRunner(com.hortonworks.registries.schemaregistry.avro.util.CustomParameterizedRunner) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) Assert(org.junit.Assert) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 39 with SchemaIdVersion

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

use of com.hortonworks.registries.schemaregistry.SchemaIdVersion 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)

Aggregations

SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)45 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)32 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)22 Test (org.junit.Test)21 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)15 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)15 IOException (java.io.IOException)11 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)10 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)10 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)9 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)9 Timed (com.codahale.metrics.annotation.Timed)5 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)5 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)5 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)5 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)5 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)5 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)5 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)5 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)4