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());
}
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());
}
Aggregations