Search in sources :

Example 6 with CompatibilityChecker

use of io.confluent.kafka.schemaregistry.CompatibilityChecker in project schema-registry by confluentinc.

the class AvroCompatibilityTest method testBasicBackwardsCompatibility.

/*
   * Backward compatibility: A new schema is backward compatible if it can be used to read the data
   * written in the previous schema.
   */
@Test
public void testBasicBackwardsCompatibility() {
    CompatibilityChecker checker = CompatibilityChecker.BACKWARD_CHECKER;
    assertTrue("adding a field with default is a backward compatible change", checker.isCompatible(schema2, Collections.singletonList(schema1)).isEmpty());
    assertFalse("adding a field w/o default is not a backward compatible change", checker.isCompatible(schema3, Collections.singletonList(schema1)).isEmpty());
    assertTrue("changing field name with alias is a backward compatible change", checker.isCompatible(schema4, Collections.singletonList(schema1)).isEmpty());
    assertTrue("evolving a field type to a union is a backward compatible change", checker.isCompatible(schema6, Collections.singletonList(schema1)).isEmpty());
    assertFalse("removing a type from a union is not a backward compatible change", checker.isCompatible(schema1, Collections.singletonList(schema6)).isEmpty());
    assertTrue("adding a new type in union is a backward compatible change", checker.isCompatible(schema7, Collections.singletonList(schema6)).isEmpty());
    assertFalse("removing a type from a union is not a backward compatible change", checker.isCompatible(schema6, Collections.singletonList(schema7)).isEmpty());
    // Only schema 2 is checked
    assertTrue("removing a default is not a transitively compatible change", checker.isCompatible(schema3, Arrays.asList(schema1, schema2)).isEmpty());
}
Also used : CompatibilityChecker(io.confluent.kafka.schemaregistry.CompatibilityChecker) Test(org.junit.Test)

Example 7 with CompatibilityChecker

use of io.confluent.kafka.schemaregistry.CompatibilityChecker in project schema-registry by confluentinc.

the class AvroCompatibilityTest method testBasicBackwardsTransitiveCompatibility.

/*
   * Backward transitive compatibility: A new schema is backward compatible if it can be used to read the data
   * written in all previous schemas.
   */
@Test
public void testBasicBackwardsTransitiveCompatibility() {
    CompatibilityChecker checker = CompatibilityChecker.BACKWARD_TRANSITIVE_CHECKER;
    // All compatible
    assertTrue("iteratively adding fields with defaults is a compatible change", checker.isCompatible(schema8, Arrays.asList(schema1, schema2)).isEmpty());
    // 1 == 2, 2 == 3, 3 != 1
    assertTrue("adding a field with default is a backward compatible change", checker.isCompatible(schema2, Collections.singletonList(schema1)).isEmpty());
    assertTrue("removing a default is a compatible change, but not transitively", checker.isCompatible(schema3, Arrays.asList(schema2)).isEmpty());
    assertFalse("removing a default is not a transitively compatible change", checker.isCompatible(schema3, Arrays.asList(schema2, schema1)).isEmpty());
}
Also used : CompatibilityChecker(io.confluent.kafka.schemaregistry.CompatibilityChecker) Test(org.junit.Test)

Aggregations

CompatibilityChecker (io.confluent.kafka.schemaregistry.CompatibilityChecker)7 Test (org.junit.Test)6 CompatibilityLevel (io.confluent.kafka.schemaregistry.CompatibilityLevel)1 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)1 SchemaReference (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaReference)1 File (java.io.File)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 AbstractMojo (org.apache.maven.plugin.AbstractMojo)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Mojo (org.apache.maven.plugins.annotations.Mojo)1 Parameter (org.apache.maven.plugins.annotations.Parameter)1