Skip to content

Commit

Permalink
DBZ-7265 Add integration test for byte buffer truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
twthorn authored and jpechane committed Jun 6, 2024
1 parent 8f12dfe commit 1caaa89
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');";
Expand Down Expand Up @@ -209,6 +210,29 @@ protected List<SchemaAndValueField> schemasAndValuesForStringTypesTruncated() {
return fields;
}

protected List<SchemaAndValueField> schemasAndValuesForStringTypesTruncatedBlob() {
final List<SchemaAndValueField> 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<SchemaAndValueField> schemasAndValuesForStringTypesExcludedColumn() {
final List<SchemaAndValueField> fields = new ArrayList<>();
fields.addAll(
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/io/debezium/connector/vitess/VitessConnectorIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/vitess_create_tables.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down

0 comments on commit 1caaa89

Please sign in to comment.