Search in sources :

Example 1 with CompatibilityResult

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

the class AvroCompatibilityCheckerTest method testBackwardCompatibility.

@Test
public void testBackwardCompatibility() throws Exception {
    CompatibilityResult compatibilityResult = new AvroSchemaProvider().checkCompatibility(fetchResourceText("/avro/book-backward.avsc"), initialVersionSchema(), SchemaCompatibility.BACKWARD);
    Assert.assertTrue(compatibilityResult.isCompatible());
}
Also used : CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) Test(org.junit.Test)

Example 2 with CompatibilityResult

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

the class AvroCompatibilityCheckerTest method testNoneCompatibility.

@Test
public void testNoneCompatibility() throws Exception {
    CompatibilityResult compatibilityResult = new AvroSchemaProvider().checkCompatibility(fetchResourceText("/avro/user.avsc"), initialVersionSchema(), SchemaCompatibility.NONE);
    Assert.assertTrue(compatibilityResult.isCompatible());
}
Also used : CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) Test(org.junit.Test)

Example 3 with CompatibilityResult

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

the class AvroCompatibilityCheckerTest method testFullCompatibility.

@Test
public void testFullCompatibility() throws Exception {
    CompatibilityResult compatibilityResult = new AvroSchemaProvider().checkCompatibility(fetchResourceText("/avro/book-both.avsc"), initialVersionSchema(), SchemaCompatibility.BOTH);
    Assert.assertTrue(compatibilityResult.isCompatible());
}
Also used : CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) Test(org.junit.Test)

Example 4 with CompatibilityResult

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

the class SchemaRegistryResource method checkCompatibilityWithSchema.

@POST
@Path("/schemas/{name}/compatibility")
@ApiOperation(value = "Checks if the given schema text is compatible with all the versions of the schema identified by the name", response = CompatibilityResult.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response checkCompatibilityWithSchema(@QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "schema text", required = true) String schemaText) {
    Response response;
    try {
        CompatibilityResult compatibilityResult = schemaRegistry.checkCompatibility(schemaBranchName, schemaName, schemaText);
        response = WSUtils.respondEntity(compatibilityResult, Response.Status.OK);
    } catch (SchemaNotFoundException e) {
        LOG.error("No schemas found with schemakey: [{}]", schemaName, e);
        response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaName);
    } catch (SchemaBranchNotFoundException e) {
        return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
    } catch (Exception ex) {
        LOG.error("Encountered error while checking compatibility with versions of schema with [{}] for given schema text [{}]", schemaName, schemaText, ex);
        response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) FileNotFoundException(java.io.FileNotFoundException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with CompatibilityResult

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

the class AvroCompatibilityCheckerTest method testForwardCompatibility.

@Test
public void testForwardCompatibility() throws Exception {
    CompatibilityResult compatibilityResult = new AvroSchemaProvider().checkCompatibility(fetchResourceText("/avro/book-forward.avsc"), initialVersionSchema(), SchemaCompatibility.FORWARD);
    Assert.assertTrue(compatibilityResult.isCompatible());
}
Also used : CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) Test(org.junit.Test)

Aggregations

CompatibilityResult (com.hortonworks.registries.schemaregistry.CompatibilityResult)6 Test (org.junit.Test)5 Timed (com.codahale.metrics.annotation.Timed)1 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)1 UnitOfWork (com.hortonworks.registries.common.transaction.UnitOfWork)1 SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)1 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)1 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)1 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)1 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)1 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)1 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)1 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1