Class VerifyRecord

java.lang.Object
io.debezium.data.VerifyRecord

public class VerifyRecord extends Object
Test utility for checking SourceRecord.
Author:
Randall Hauch
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
    private static org.apache.kafka.connect.storage.Converter
     
    private static org.apache.kafka.connect.storage.Converter
     
    private static final org.apache.kafka.connect.json.JsonConverter
     
    private static final org.apache.kafka.connect.json.JsonDeserializer
     
    private static final boolean
     
    private static final org.apache.kafka.connect.json.JsonConverter
     
    private static final org.apache.kafka.connect.json.JsonDeserializer
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static boolean
    areConnectSchemasEqual(org.apache.kafka.connect.data.Schema schema1, org.apache.kafka.connect.data.Schema schema2)
     
    private static boolean
    areFieldListsEqual(List<org.apache.kafka.connect.data.Field> fields1, List<org.apache.kafka.connect.data.Field> fields2)
     
    static void
    assertConnectSchemasAreEqual(String fieldName, org.apache.kafka.connect.data.Schema actual, org.apache.kafka.connect.data.Schema expected)
    Asserts that the two given schemas are equal.
    protected static void
     
    protected static void
    assertEquals(org.apache.kafka.connect.data.Schema schema, Object o1, Object o2, String keyOrValue, String field, Predicate<String> ignoreFields, Map<String,VerifyRecord.RecordValueComparator> comparatorsByName, Map<String,VerifyRecord.RecordValueComparator> comparatorsBySchemaName)
     
    static void
    assertEquals(org.apache.kafka.connect.source.SourceRecord actual, org.apache.kafka.connect.source.SourceRecord expected, Predicate<String> ignoreFields, Map<String,VerifyRecord.RecordValueComparator> comparatorsByName, Map<String,VerifyRecord.RecordValueComparator> comparatorsBySchemaName)
     
    static void
    assertSameValue(Object actual, Object expected)
    Utility method to validate that two given SourceRecord values are identical.
    static void
    assertValueField(org.apache.kafka.connect.source.SourceRecord record, String fieldPath, Object expectedValue)
    Verify the given SourceRecord has the expected value in the given fieldPath.
    static void
    debug(org.apache.kafka.connect.source.SourceRecord record)
    Print a debug message with the JSON representation of the SourceRecord.
    private static boolean
    deepEquals(Object[] a1, Object[] a2)
     
    private static boolean
     
    protected static boolean
    equals(Object o1, Object o2)
     
    private static String
    fieldName(String field, String suffix)
     
    static void
    fieldsInSchema(org.apache.kafka.connect.data.Struct struct, org.apache.kafka.connect.data.Schema schema)
    Verify that the fields in the given Struct reference the Field definitions in the given Schema.
    static void
    hasNoSourceQuery(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord has no source query value.
    static void
    hasValidKey(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
    Verify that the given SourceRecord has a valid non-null integer key that matches the expected integer value.
    static void
    hasValidSourceQuery(org.apache.kafka.connect.source.SourceRecord record, String query)
    Verify that the given SourceRecord has the appropriate source query value.
    static boolean
     
    static void
    isValid(org.apache.kafka.connect.source.SourceRecord record)
    Validate that a SourceRecord's key and value can each be converted to a byte[] and then back to an equivalent SourceRecord.
    static void
    isValid(org.apache.kafka.connect.source.SourceRecord record, boolean ignoreAvro)
    Validate that a SourceRecord's key and value can each be converted to a byte[] and then back to an equivalent SourceRecord.
    static void
    isValidDelete(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord is a DELETE record without PK.
    static void
    isValidDelete(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)
    Verify that the given SourceRecord is a DELETE record.
    static void
    isValidDelete(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
    Verify that the given SourceRecord is a DELETE record, and that the integer key matches the expected value.
    static void
    isValidInsert(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord is a INSERT/CREATE record without primary key.
    static void
    isValidInsert(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)
    Verify that the given SourceRecord is a INSERT/CREATE record.
    static void
    isValidInsert(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
    Verify that the given SourceRecord is a INSERT/CREATE record, and that the integer key matches the expected value.
    static void
    isValidRead(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord is a READ record.
    static void
    isValidRead(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
    Verify that the given SourceRecord is a READ record, and that the integer key matches the expected value.
    static void
    isValidTombstone(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord is a valid tombstone, meaning it has a non-null key and key schema but null value and value schema.
    static void
    isValidTombstone(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
    Verify that the given SourceRecord is a valid tombstone, meaning it has a valid non-null key with key schema but null value and value schema.
    static void
    isValidTruncate(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord is a TRUNCATE record.
    static void
    isValidUpdate(org.apache.kafka.connect.source.SourceRecord record)
    Verify that the given SourceRecord is a UPDATE record without PK.
    static void
    isValidUpdate(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)
    Verify that the given SourceRecord is a UPDATE record.
    static void
    isValidUpdate(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
    Verify that the given SourceRecord is a UPDATE record, and that the integer key matches the expected value.
    protected static String
    nameOf(String keyOrValue, String field)
     
    protected static String
    prettyJson(com.fasterxml.jackson.databind.JsonNode json)
     
    static void
    print(org.apache.kafka.connect.source.SourceRecord record)
    Print a message with the JSON representation of the SourceRecord.
    protected static void
    printJson(org.apache.kafka.connect.source.SourceRecord record)
     
    static void
    schemaMatchesStruct(org.apache.kafka.connect.data.SchemaAndValue schemaAndValue)
    Assert that the supplied Struct is valid and its schema matches that of the supplied schema.
    static void
    schemaMatchesStruct(org.apache.kafka.connect.data.Struct struct, org.apache.kafka.connect.data.Schema schema)
    Assert that the supplied Struct is valid and its schema matches that of the supplied schema.
    private static String
    schemaName(org.apache.kafka.connect.data.Schema schema)
     
    private static Object
    setVersion(Object obj, Integer version)
    Sets the version of a passed schema to a new value.
    private static org.apache.kafka.connect.data.SchemaAndValue
    setVersion(org.apache.kafka.connect.data.SchemaAndValue value, Integer version)
    Sets the version of a passed schema to a new value.
    private static org.apache.kafka.connect.data.Schema
    setVersion(org.apache.kafka.connect.data.Schema schema, Integer version)
    Sets the version of a passed schema to a new value.
    protected static void
    validateSchemaNames(org.apache.kafka.connect.data.Schema schema)
     
    protected static void
    validateSubSchemaNames(org.apache.kafka.connect.data.Schema parentSchema, org.apache.kafka.connect.data.Field field)
     
    private static Object[]
    valuesFor(org.apache.kafka.connect.data.Struct struct)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • APICURIO_URL

      private static final String APICURIO_URL
      See Also:
    • keyJsonConverter

      private static final org.apache.kafka.connect.json.JsonConverter keyJsonConverter
    • valueJsonConverter

      private static final org.apache.kafka.connect.json.JsonConverter valueJsonConverter
    • keyJsonDeserializer

      private static final org.apache.kafka.connect.json.JsonDeserializer keyJsonDeserializer
    • valueJsonDeserializer

      private static final org.apache.kafka.connect.json.JsonDeserializer valueJsonDeserializer
    • useApicurio

      private static final boolean useApicurio
    • avroKeyConverter

      private static org.apache.kafka.connect.storage.Converter avroKeyConverter
    • avroValueConverter

      private static org.apache.kafka.connect.storage.Converter avroValueConverter
  • Constructor Details

    • VerifyRecord

      public VerifyRecord()
  • Method Details

    • isValidInsert

      public static void isValidInsert(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)
      Verify that the given SourceRecord is a INSERT/CREATE record.
      Parameters:
      record - the source record; may not be null
    • isValidRead

      public static void isValidRead(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord is a READ record.
      Parameters:
      record - the source record; may not be null
    • isValidUpdate

      public static void isValidUpdate(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)
      Verify that the given SourceRecord is a UPDATE record.
      Parameters:
      record - the source record; may not be null
    • isValidDelete

      public static void isValidDelete(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)
      Verify that the given SourceRecord is a DELETE record.
      Parameters:
      record - the source record; may not be null
    • isValidTombstone

      public static void isValidTombstone(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord is a valid tombstone, meaning it has a non-null key and key schema but null value and value schema.
      Parameters:
      record - the source record; may not be null
    • hasValidKey

      public static void hasValidKey(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
      Verify that the given SourceRecord has a valid non-null integer key that matches the expected integer value.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidInsert

      public static void isValidInsert(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord is a INSERT/CREATE record without primary key.
      Parameters:
      record - the source record; may not be null
    • isValidInsert

      public static void isValidInsert(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
      Verify that the given SourceRecord is a INSERT/CREATE record, and that the integer key matches the expected value.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidRead

      public static void isValidRead(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
      Verify that the given SourceRecord is a READ record, and that the integer key matches the expected value.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidUpdate

      public static void isValidUpdate(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord is a UPDATE record without PK.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidUpdate

      public static void isValidUpdate(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
      Verify that the given SourceRecord is a UPDATE record, and that the integer key matches the expected value.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidDelete

      public static void isValidDelete(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord is a DELETE record without PK. matches the expected value.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidDelete

      public static void isValidDelete(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
      Verify that the given SourceRecord is a DELETE record, and that the integer key matches the expected value.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • isValidTruncate

      public static void isValidTruncate(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord is a TRUNCATE record.
      Parameters:
      record - the source record; may not be null
    • isValidTombstone

      public static void isValidTombstone(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)
      Verify that the given SourceRecord is a valid tombstone, meaning it has a valid non-null key with key schema but null value and value schema.
      Parameters:
      record - the source record; may not be null
      pkField - the single field defining the primary key of the struct; may not be null
      pk - the expected integer value of the primary key in the struct
    • hasValidSourceQuery

      public static void hasValidSourceQuery(org.apache.kafka.connect.source.SourceRecord record, String query)
      Verify that the given SourceRecord has the appropriate source query value.
      Parameters:
      record - the source record; may not be null
      query - the expected sql query value.
    • hasNoSourceQuery

      public static void hasNoSourceQuery(org.apache.kafka.connect.source.SourceRecord record)
      Verify that the given SourceRecord has no source query value.
      Parameters:
      record - the source record; may not be null
    • assertValueField

      public static void assertValueField(org.apache.kafka.connect.source.SourceRecord record, String fieldPath, Object expectedValue)
      Verify the given SourceRecord has the expected value in the given fieldPath.
      Parameters:
      record - the source record; may not be null
      fieldPath - the field path to validate, separated by '/'
      expectedValue - the expected value in the source records field path.
    • assertSameValue

      public static void assertSameValue(Object actual, Object expected)
      Utility method to validate that two given SourceRecord values are identical.
      Parameters:
      actual - actual value stored on the source record
      expected - expected value stored on the source record
    • schemaMatchesStruct

      public static void schemaMatchesStruct(org.apache.kafka.connect.data.SchemaAndValue schemaAndValue)
      Assert that the supplied Struct is valid and its schema matches that of the supplied schema.
      Parameters:
      schemaAndValue - the value with a schema; may not be null
    • schemaMatchesStruct

      public static void schemaMatchesStruct(org.apache.kafka.connect.data.Struct struct, org.apache.kafka.connect.data.Schema schema)
      Assert that the supplied Struct is valid and its schema matches that of the supplied schema.
      Parameters:
      struct - the Struct to validate; may not be null
      schema - the expected schema of the Struct; may not be null
    • fieldsInSchema

      public static void fieldsInSchema(org.apache.kafka.connect.data.Struct struct, org.apache.kafka.connect.data.Schema schema)
      Verify that the fields in the given Struct reference the Field definitions in the given Schema.
      Parameters:
      struct - the Struct instance; may not be null
      schema - the Schema defining the fields in the Struct; may not be null
    • print

      public static void print(org.apache.kafka.connect.source.SourceRecord record)
      Print a message with the JSON representation of the SourceRecord.
      Parameters:
      record - the source record; may not be null
    • debug

      public static void debug(org.apache.kafka.connect.source.SourceRecord record)
      Print a debug message with the JSON representation of the SourceRecord.
      Parameters:
      record - the source record; may not be null
    • assertEquals

      public static void assertEquals(org.apache.kafka.connect.source.SourceRecord actual, org.apache.kafka.connect.source.SourceRecord expected, Predicate<String> ignoreFields, Map<String,VerifyRecord.RecordValueComparator> comparatorsByName, Map<String,VerifyRecord.RecordValueComparator> comparatorsBySchemaName)
    • assertConnectSchemasAreEqual

      public static void assertConnectSchemasAreEqual(String fieldName, org.apache.kafka.connect.data.Schema actual, org.apache.kafka.connect.data.Schema expected)
      Asserts that the two given schemas are equal.
      Parameters:
      fieldName - name of the field owning that schema, if it's not a top-level schema
      actual - the actual schema
      expected - the expected schema
    • nameOf

      protected static String nameOf(String keyOrValue, String field)
    • fieldName

      private static String fieldName(String field, String suffix)
    • schemaName

      private static String schemaName(org.apache.kafka.connect.data.Schema schema)
    • assertEquals

      protected static void assertEquals(org.apache.kafka.connect.data.Schema schema, Object o1, Object o2, String keyOrValue, String field, Predicate<String> ignoreFields, Map<String,VerifyRecord.RecordValueComparator> comparatorsByName, Map<String,VerifyRecord.RecordValueComparator> comparatorsBySchemaName)
    • isValid

      public static void isValid(org.apache.kafka.connect.source.SourceRecord record)
      Validate that a SourceRecord's key and value can each be converted to a byte[] and then back to an equivalent SourceRecord.
      Parameters:
      record - the record to validate; may not be null
    • isValid

      public static void isValid(org.apache.kafka.connect.source.SourceRecord record, boolean ignoreAvro)
      Validate that a SourceRecord's key and value can each be converted to a byte[] and then back to an equivalent SourceRecord.
      Parameters:
      record - the record to validate; may not be null
      ignoreAvro - true when Avro check should not be executed
    • validateSchemaNames

      protected static void validateSchemaNames(org.apache.kafka.connect.data.Schema schema)
    • validateSubSchemaNames

      protected static void validateSubSchemaNames(org.apache.kafka.connect.data.Schema parentSchema, org.apache.kafka.connect.data.Field field)
    • printJson

      protected static void printJson(org.apache.kafka.connect.source.SourceRecord record)
    • prettyJson

      protected static String prettyJson(com.fasterxml.jackson.databind.JsonNode json)
    • assertEquals

      protected static void assertEquals(Object o1, Object o2)
    • equals

      protected static boolean equals(Object o1, Object o2)
    • valuesFor

      private static Object[] valuesFor(org.apache.kafka.connect.data.Struct struct)
    • deepEquals

      private static boolean deepEquals(Object[] a1, Object[] a2)
    • deepEquals0

      private static boolean deepEquals0(Object e1, Object e2)
    • areConnectSchemasEqual

      private static boolean areConnectSchemasEqual(org.apache.kafka.connect.data.Schema schema1, org.apache.kafka.connect.data.Schema schema2)
    • areFieldListsEqual

      private static boolean areFieldListsEqual(List<org.apache.kafka.connect.data.Field> fields1, List<org.apache.kafka.connect.data.Field> fields2)
    • setVersion

      private static org.apache.kafka.connect.data.Schema setVersion(org.apache.kafka.connect.data.Schema schema, Integer version)
      Sets the version of a passed schema to a new value.
      Parameters:
      schema - the schema to be updated
      version - the target version value
      Returns:
      the new schema with the same structure but updated version
    • setVersion

      private static org.apache.kafka.connect.data.SchemaAndValue setVersion(org.apache.kafka.connect.data.SchemaAndValue value, Integer version)
      Sets the version of a passed schema to a new value.
      Parameters:
      value - the value with schema to be updated
      version - the target version value
      Returns:
      the new value with the same schema but updated version
    • setVersion

      private static Object setVersion(Object obj, Integer version)
      Sets the version of a passed schema to a new value.
      Parameters:
      object - the value with schema to be updated
      version - the target version value
      Returns:
      the new value with the same schema but updated version
    • isApucurioAvailable

      public static boolean isApucurioAvailable()