DBZ-8027 Added test
This commit is contained in:
parent
3706f8a4c2
commit
478c95f042
@ -22,6 +22,7 @@
|
||||
import io.debezium.data.Envelope;
|
||||
import io.debezium.doc.FixFor;
|
||||
import io.debezium.embedded.async.AbstractAsyncEngineConnectorTest;
|
||||
import io.debezium.relational.RelationalDatabaseConnectorConfig.DecimalHandlingMode;
|
||||
|
||||
/**
|
||||
* Integration test to verify postgres money types defined in public schema.
|
||||
@ -144,6 +145,45 @@ public void shouldReceiveChangesForInsertNullAndZeroMoney() throws Exception {
|
||||
assertThat(after.get("m")).isEqualTo(BigDecimal.ZERO.setScale(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@FixFor("DBZ-8027")
|
||||
public void shouldReceiveCorrectDefaultValueForHandlingMode() throws Exception {
|
||||
createTableWithNotNull();
|
||||
TestHelper.execute("insert into post_money.debezium_test(id, m) values(10, '3.14'::money);");
|
||||
|
||||
var config = TestHelper.defaultConfig()
|
||||
.with(PostgresConnectorConfig.SNAPSHOT_MODE, PostgresConnectorConfig.SnapshotMode.ALWAYS)
|
||||
.with(PostgresConnectorConfig.DECIMAL_HANDLING_MODE, DecimalHandlingMode.STRING)
|
||||
.with(PostgresConnectorConfig.SNAPSHOT_SELECT_STATEMENT_OVERRIDES_BY_TABLE, "post_money.debezium_test")
|
||||
.with(PostgresConnectorConfig.SNAPSHOT_SELECT_STATEMENT_OVERRIDES_BY_TABLE + ".post_money.debezium_test",
|
||||
"SELECT id, null AS m FROM post_money.debezium_test")
|
||||
.build();
|
||||
start(PostgresConnector.class, config);
|
||||
|
||||
var records = consumeRecordsByTopic(1);
|
||||
var recordsForTopic = records.recordsForTopic(topicName("post_money.debezium_test"));
|
||||
|
||||
assertThat(recordsForTopic).hasSize(1);
|
||||
assertThat(((Struct) recordsForTopic.get(0).value()).getStruct("after").getString("m")).isEqualTo("0.00");
|
||||
|
||||
stopConnector();
|
||||
|
||||
config = TestHelper.defaultConfig()
|
||||
.with(PostgresConnectorConfig.SNAPSHOT_MODE, PostgresConnectorConfig.SnapshotMode.ALWAYS)
|
||||
.with(PostgresConnectorConfig.DECIMAL_HANDLING_MODE, DecimalHandlingMode.DOUBLE)
|
||||
.with(PostgresConnectorConfig.SNAPSHOT_SELECT_STATEMENT_OVERRIDES_BY_TABLE, "post_money.debezium_test")
|
||||
.with(PostgresConnectorConfig.SNAPSHOT_SELECT_STATEMENT_OVERRIDES_BY_TABLE + ".post_money.debezium_test",
|
||||
"SELECT id, null AS m FROM post_money.debezium_test")
|
||||
.build();
|
||||
start(PostgresConnector.class, config);
|
||||
|
||||
records = consumeRecordsByTopic(1);
|
||||
recordsForTopic = records.recordsForTopic(topicName("post_money.debezium_test"));
|
||||
|
||||
assertThat(recordsForTopic).hasSize(1);
|
||||
assertThat(((Struct) recordsForTopic.get(0).value()).getStruct("after").getFloat64("m")).isEqualTo(0.0);
|
||||
}
|
||||
|
||||
private void createTable() {
|
||||
TestHelper.execute(
|
||||
"DROP SCHEMA IF EXISTS post_money CASCADE;",
|
||||
@ -151,6 +191,13 @@ private void createTable() {
|
||||
"CREATE TABLE post_money.debezium_test (id int4 NOT NULL, m money, CONSTRAINT dbz_test_pkey PRIMARY KEY (id));");
|
||||
}
|
||||
|
||||
private void createTableWithNotNull() {
|
||||
TestHelper.execute(
|
||||
"DROP SCHEMA IF EXISTS post_money CASCADE;",
|
||||
"CREATE SCHEMA post_money;",
|
||||
"CREATE TABLE post_money.debezium_test (id int4 NOT NULL, m money NOT NULL, CONSTRAINT dbz_test_pkey PRIMARY KEY (id));");
|
||||
}
|
||||
|
||||
private void insertTwoRecords() {
|
||||
TestHelper.execute("insert into post_money.debezium_test(id, m) values(8, -92233720368547758.08),(9, 92233720368547758.07);");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user