Package io.debezium.data
Class VerifyRecord
- java.lang.Object
-
- io.debezium.data.VerifyRecord
-
public class VerifyRecord extends Object
Test utility for checkingSourceRecord.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceVerifyRecord.RecordValueComparator
-
Field Summary
Fields Modifier and Type Field Description private static io.confluent.connect.avro.AvroConverteravroKeyConverterprivate static io.confluent.connect.avro.AvroConverteravroValueConverterprivate static org.apache.kafka.connect.json.JsonConverterkeyJsonConverterprivate static org.apache.kafka.connect.json.JsonDeserializerkeyJsonDeserializerprivate static io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClientschemaRegistryprivate static org.apache.kafka.connect.json.JsonConvertervalueJsonConverterprivate static org.apache.kafka.connect.json.JsonDeserializervalueJsonDeserializer
-
Constructor Summary
Constructors Constructor Description VerifyRecord()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleanareConnectSchemasEqual(org.apache.kafka.connect.data.Schema schema1, org.apache.kafka.connect.data.Schema schema2)private static booleanareFieldListsEqual(List<org.apache.kafka.connect.data.Field> fields1, List<org.apache.kafka.connect.data.Field> fields2)static voidassertConnectSchemasAreEqual(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 voidassertEquals(Object o1, Object o2)protected static voidassertEquals(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 voidassertEquals(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 voidassertSameValue(Object actual, Object expected)Utility method to validate that two givenSourceRecordvalues are identical.static voidassertValueField(org.apache.kafka.connect.source.SourceRecord record, String fieldPath, Object expectedValue)Verify the givenSourceRecordhas the expected value in the given fieldPath.static voiddebug(org.apache.kafka.connect.source.SourceRecord record)Print a debug message with the JSON representation of the SourceRecord.private static booleandeepEquals(Object[] a1, Object[] a2)private static booleandeepEquals0(Object e1, Object e2)protected static booleanequals(Object o1, Object o2)private static StringfieldName(String field, String suffix)static voidfieldsInSchema(org.apache.kafka.connect.data.Struct struct, org.apache.kafka.connect.data.Schema schema)Verify that the fields in the givenStructreference theFielddefinitions in the givenSchema.static voidhasNoSourceQuery(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordhas no source query value.static voidhasValidKey(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)Verify that the givenSourceRecordhas a valid non-null integer key that matches the expected integer value.static voidhasValidSourceQuery(org.apache.kafka.connect.source.SourceRecord record, String query)Verify that the givenSourceRecordhas the appropriate source query value.static voidisValid(org.apache.kafka.connect.source.SourceRecord record)Validate that aSourceRecord's key and value can each be converted to a byte[] and then back to an equivalentSourceRecord.static voidisValid(org.apache.kafka.connect.source.SourceRecord record, boolean ignoreAvro)Validate that aSourceRecord's key and value can each be converted to a byte[] and then back to an equivalentSourceRecord.static voidisValidDelete(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordis aDELETErecord without PK.static voidisValidDelete(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)Verify that the givenSourceRecordis aDELETErecord.static voidisValidDelete(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)Verify that the givenSourceRecordis aDELETErecord, and that the integer key matches the expected value.static voidisValidInsert(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordis aINSERT/CREATErecord without primary key.static voidisValidInsert(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)Verify that the givenSourceRecordis aINSERT/CREATErecord.static voidisValidInsert(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)Verify that the givenSourceRecordis aINSERT/CREATErecord, and that the integer key matches the expected value.static voidisValidRead(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordis aREADrecord.static voidisValidRead(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)Verify that the givenSourceRecordis aREADrecord, and that the integer key matches the expected value.static voidisValidTombstone(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordis a valid tombstone, meaning it has a non-null key and key schema but null value and value schema.static voidisValidTombstone(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)Verify that the givenSourceRecordis a valid tombstone, meaning it has a valid non-null key with key schema but null value and value schema.static voidisValidTruncate(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordis aTRUNCATErecord.static voidisValidUpdate(org.apache.kafka.connect.source.SourceRecord record)Verify that the givenSourceRecordis aUPDATErecord without PK.static voidisValidUpdate(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)Verify that the givenSourceRecordis aUPDATErecord.static voidisValidUpdate(org.apache.kafka.connect.source.SourceRecord record, String pkField, int pk)Verify that the givenSourceRecordis aUPDATErecord, and that the integer key matches the expected value.protected static StringnameOf(String keyOrValue, String field)protected static StringprettyJson(com.fasterxml.jackson.databind.JsonNode json)static voidprint(org.apache.kafka.connect.source.SourceRecord record)Print a message with the JSON representation of the SourceRecord.protected static voidprintJson(org.apache.kafka.connect.source.SourceRecord record)static voidschemaMatchesStruct(org.apache.kafka.connect.data.SchemaAndValue schemaAndValue)Assert that the suppliedStructisvalidand itsschemamatches that of the suppliedschema.static voidschemaMatchesStruct(org.apache.kafka.connect.data.Struct struct, org.apache.kafka.connect.data.Schema schema)Assert that the suppliedStructisvalidand itsschemamatches that of the suppliedschema.private static StringschemaName(org.apache.kafka.connect.data.Schema schema)private static org.apache.kafka.connect.data.SchemaAndValuesetVersion(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.SchemasetVersion(org.apache.kafka.connect.data.Schema schema, Integer version)Sets the version of a passed schema to a new value.protected static voidvalidateSchemaNames(org.apache.kafka.connect.data.Schema schema)protected static voidvalidateSubSchemaNames(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)
-
-
-
Field Detail
-
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
-
schemaRegistry
private static final io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient schemaRegistry
-
avroKeyConverter
private static final io.confluent.connect.avro.AvroConverter avroKeyConverter
-
avroValueConverter
private static final io.confluent.connect.avro.AvroConverter avroValueConverter
-
-
Method Detail
-
isValidInsert
public static void isValidInsert(org.apache.kafka.connect.source.SourceRecord record, boolean keyExpected)Verify that the givenSourceRecordis aINSERT/CREATErecord.- Parameters:
record- the source record; may not be null
-
isValidRead
public static void isValidRead(org.apache.kafka.connect.source.SourceRecord record)
Verify that the givenSourceRecordis aREADrecord.- 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 givenSourceRecordis aUPDATErecord.- 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 givenSourceRecordis aDELETErecord.- Parameters:
record- the source record; may not be null
-
isValidTombstone
public static void isValidTombstone(org.apache.kafka.connect.source.SourceRecord record)
Verify that the givenSourceRecordis 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 givenSourceRecordhas a valid non-null integer key that matches the expected integer value.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aINSERT/CREATErecord 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 givenSourceRecordis aINSERT/CREATErecord, and that the integer key matches the expected value.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aREADrecord, and that the integer key matches the expected value.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aUPDATErecord without PK.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aUPDATErecord, and that the integer key matches the expected value.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aDELETErecord without PK. matches the expected value.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aDELETErecord, and that the integer key matches the expected value.- Parameters:
record- the source record; may not be nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordis aTRUNCATErecord.- 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 givenSourceRecordis 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 nullpkField- the single field defining the primary key of the struct; may not be nullpk- 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 givenSourceRecordhas the appropriate source query value.- Parameters:
record- the source record; may not be nullquery- the expected sql query value.
-
hasNoSourceQuery
public static void hasNoSourceQuery(org.apache.kafka.connect.source.SourceRecord record)
Verify that the givenSourceRecordhas 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 givenSourceRecordhas the expected value in the given fieldPath.- Parameters:
record- the source record; may not be nullfieldPath- 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 givenSourceRecordvalues are identical.- Parameters:
actual- actual value stored on the source recordexpected- expected value stored on the source record
-
schemaMatchesStruct
public static void schemaMatchesStruct(org.apache.kafka.connect.data.SchemaAndValue schemaAndValue)
Assert that the suppliedStructisvalidand itsschemamatches that of the suppliedschema.- 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 suppliedStructisvalidand itsschemamatches that of the suppliedschema.- Parameters:
struct- theStructto validate; may not be nullschema- the expected schema of theStruct; 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 givenStructreference theFielddefinitions in the givenSchema.- Parameters:
struct- theStructinstance; may not be nullschema- theSchemadefining 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 schemaactual- the actual schemaexpected- the expected schema
-
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 aSourceRecord's key and value can each be converted to a byte[] and then back to an equivalentSourceRecord.- 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 aSourceRecord's key and value can each be converted to a byte[] and then back to an equivalentSourceRecord.- Parameters:
record- the record to validate; may not be nullignoreAvro- 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)
-
valuesFor
private static Object[] valuesFor(org.apache.kafka.connect.data.Struct struct)
-
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 updatedversion- 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 updatedversion- the target version value- Returns:
- the new value with the same schema but updated version
-
-