diff --git a/src/test/java/io/debezium/connector/vitess/AbstractVitessConnectorTest.java b/src/test/java/io/debezium/connector/vitess/AbstractVitessConnectorTest.java index 91e64398..cebc9af8 100644 --- a/src/test/java/io/debezium/connector/vitess/AbstractVitessConnectorTest.java +++ b/src/test/java/io/debezium/connector/vitess/AbstractVitessConnectorTest.java @@ -110,8 +110,9 @@ public abstract class AbstractVitessConnectorTest extends AbstractConnectorTest + "binary_col," + "varbinary_col," + "blob_col," - + "mediumblob_col)" - + " VALUES ('d', 'ef', 'op', 'qs');"; + + "mediumblob_col," + + "longblob_col)" + + " VALUES ('d', 'ef', 'op', 'qs', 'th');"; protected static final String INSERT_ENUM_TYPE_STMT = "INSERT INTO enum_table (enum_col)" + " VALUES ('large');"; protected static final String INSERT_ENUM_AMBIGUOUS_TYPE_STMT = "INSERT INTO enum_ambiguous_table (enum_col)" + " VALUES ('2');"; @@ -209,6 +210,29 @@ protected List schemasAndValuesForStringTypesTruncated() { return fields; } + protected List schemasAndValuesForStringTypesTruncatedBlob() { + final List fields = new ArrayList<>(); + ByteBuffer byteBufferTruncated = ByteBuffer.wrap(Arrays.copyOfRange("op".getBytes(), 0, 1)); + ByteBuffer byteBufferTruncatedMedium = ByteBuffer.wrap(Arrays.copyOfRange("qs".getBytes(), 0, 1)); + ByteBuffer byteBufferTruncatedLong = ByteBuffer.wrap(Arrays.copyOfRange("th".getBytes(), 0, 1)); + ByteBuffer byteBufferTruncatedBinary = ByteBuffer.wrap(Arrays.copyOfRange("d".getBytes(), 0, 1)); + ByteBuffer byteBufferTruncatedVarBinary = ByteBuffer.wrap(Arrays.copyOfRange("ef".getBytes(), 0, 1)); + fields.addAll( + Arrays.asList( + new SchemaAndValueField("blob_col", SchemaBuilder.bytes().optional() + .parameter("truncateLength", "1").build(), byteBufferTruncated), + new SchemaAndValueField("mediumblob_col", SchemaBuilder.bytes().optional() + .parameter("truncateLength", "1").build(), byteBufferTruncatedMedium), + new SchemaAndValueField("longblob_col", SchemaBuilder.bytes().optional() + .parameter("truncateLength", "1").build(), byteBufferTruncatedLong), + new SchemaAndValueField("binary_col", SchemaBuilder.bytes().optional() + .parameter("truncateLength", "1").build(), byteBufferTruncatedBinary), + new SchemaAndValueField("varbinary_col", SchemaBuilder.bytes().optional() + .parameter("truncateLength", "1").build(), byteBufferTruncatedVarBinary) + )); + return fields; + } + protected List schemasAndValuesForStringTypesExcludedColumn() { final List fields = new ArrayList<>(); fields.addAll( diff --git a/src/test/java/io/debezium/connector/vitess/VitessConnectorIT.java b/src/test/java/io/debezium/connector/vitess/VitessConnectorIT.java index 57627723..c3302dff 100644 --- a/src/test/java/io/debezium/connector/vitess/VitessConnectorIT.java +++ b/src/test/java/io/debezium/connector/vitess/VitessConnectorIT.java @@ -250,6 +250,29 @@ public void shouldConsumeEventsWithTruncatedColumn() throws Exception { assertInsert(INSERT_STRING_TYPES_STMT, schemasAndValuesForStringTypesTruncated(), TestHelper.PK_FIELD); } + @Test + public void shouldTruncateByteArray() throws Exception { + + TestHelper.executeDDL("vitess_create_tables.ddl"); + startConnector(builder -> builder.with( + "column.truncate.to.1.chars", + TEST_UNSHARDED_KEYSPACE + ".string_table.blob_col," + + TEST_UNSHARDED_KEYSPACE + ".string_table.mediumblob_col," + + TEST_UNSHARDED_KEYSPACE + ".string_table.longblob_col," + + TEST_UNSHARDED_KEYSPACE + ".string_table.varbinary_col," + + TEST_UNSHARDED_KEYSPACE + ".string_table.binary_col" + ), false, + false, 1, -1, -1, null, + VitessConnectorConfig.SnapshotMode.NEVER, ""); + assertConnectorIsRunning(); + + int expectedRecordsCount = 1; + consumer = testConsumer(expectedRecordsCount); + + consumer.expects(expectedRecordsCount); + assertInsert(INSERT_BYTES_TYPES_STMT, schemasAndValuesForStringTypesTruncatedBlob(), TestHelper.PK_FIELD); + } + @Test public void shouldConsumeEventsWithExcludedColumn() throws Exception { String columnToExlude = "mediumtext_col"; diff --git a/src/test/resources/vitess_create_tables.ddl b/src/test/resources/vitess_create_tables.ddl index b46fe8bd..c79212e4 100644 --- a/src/test/resources/vitess_create_tables.ddl +++ b/src/test/resources/vitess_create_tables.ddl @@ -36,6 +36,7 @@ CREATE TABLE string_table longtext_col LONGTEXT, blob_col BLOB, mediumblob_col MEDIUMBLOB, + longblob_col LONGBLOB, json_col JSON, PRIMARY KEY (id) );