use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class TestHelper method execute.
/**
* Executes a JDBC statement using the default jdbc config without autocommitting the connection
*
* @param statement an array of statement
*/
public static void execute(String statement) {
try (PostgresConnection connection = create()) {
connection.setAutoCommit(false);
connection.executeWithoutCommitting(statement);
Connection jdbcConn = connection.connection();
if (!statement.endsWith("ROLLBACK;")) {
jdbcConn.commit();
} else {
jdbcConn.rollback();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class TestHelper method executeDDL.
protected static void executeDDL(String ddlFile) throws Exception {
URL ddlTestFile = TestHelper.class.getClassLoader().getResource(ddlFile);
assertNotNull("Cannot locate " + ddlFile, ddlTestFile);
String statements = Files.readAllLines(Paths.get(ddlTestFile.toURI())).stream().collect(Collectors.joining(System.lineSeparator()));
try (PostgresConnection connection = create()) {
connection.executeWithoutCommitting(statements);
}
}
use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class PostgresSchemaIT method shouldApplyFilters.
@Test
public void shouldApplyFilters() throws Exception {
String statements = "CREATE SCHEMA s1; " + "CREATE SCHEMA s2; " + "DROP TABLE IF EXISTS s1.A;" + "DROP TABLE IF EXISTS s1.B;" + "DROP TABLE IF EXISTS s2.A;" + "DROP TABLE IF EXISTS s2.B;" + "CREATE TABLE s1.A (pk SERIAL, aa integer, PRIMARY KEY(pk));" + "CREATE TABLE s1.B (pk SERIAL, ba integer, PRIMARY KEY(pk));" + "CREATE TABLE s2.A (pk SERIAL, aa integer, PRIMARY KEY(pk));" + "CREATE TABLE s2.B (pk SERIAL, ba integer, PRIMARY KEY(pk));";
TestHelper.execute(statements);
PostgresConnectorConfig config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(SCHEMA_BLACKLIST, "s1").build());
final TypeRegistry typeRegistry = TestHelper.getTypeRegistry();
schema = new PostgresSchema(config, typeRegistry, TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesIncluded("s2.a", "s2.b");
assertTablesExcluded("s1.a", "s1.b");
}
config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(SCHEMA_BLACKLIST, "s.*").build());
schema = new PostgresSchema(config, typeRegistry, TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesExcluded("s1.a", "s2.a", "s1.b", "s2.b");
}
config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(PostgresConnectorConfig.TABLE_BLACKLIST, "s1.A,s2.A").build());
schema = new PostgresSchema(config, typeRegistry, TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesIncluded("s1.b", "s2.b");
assertTablesExcluded("s1.a", "s2.a");
}
config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(SCHEMA_BLACKLIST, "s2").with(PostgresConnectorConfig.TABLE_BLACKLIST, "s1.A").build());
schema = new PostgresSchema(config, typeRegistry, TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesIncluded("s1.b");
assertTablesExcluded("s1.a", "s2.a", "s2.b");
}
config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(PostgresConnectorConfig.COLUMN_BLACKLIST, ".*aa").build());
schema = new PostgresSchema(config, typeRegistry, TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertColumnsExcluded("s1.a.aa", "s2.a.aa");
}
}
use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class PostgresSchemaIT method shouldLoadSchemaForPostgisTypes.
@Test
public void shouldLoadSchemaForPostgisTypes() throws Exception {
TestHelper.executeDDL("init_postgis.ddl");
TestHelper.executeDDL("postgis_create_tables.ddl");
PostgresConnectorConfig config = new PostgresConnectorConfig(TestHelper.defaultConfig().build());
schema = new PostgresSchema(config, TestHelper.getTypeRegistry(), TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
final String[] testTables = new String[] { "public.postgis_table" };
assertTablesIncluded(testTables);
Arrays.stream(testTables).forEach(tableId -> assertKeySchema(tableId, "pk", Schema.INT32_SCHEMA));
assertTableSchema("public.postgis_table", "p, ml", Geometry.builder().optional().build(), Geography.builder().optional().build());
}
}
use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class PostgresSchemaIT method shouldDetectNewChangesAfterRefreshing.
@Test
public void shouldDetectNewChangesAfterRefreshing() throws Exception {
String statements = "CREATE SCHEMA IF NOT EXISTS public;" + "DROP TABLE IF EXISTS table1;" + "CREATE TABLE table1 (pk SERIAL, PRIMARY KEY(pk));";
TestHelper.execute(statements);
PostgresConnectorConfig config = new PostgresConnectorConfig(TestHelper.defaultConfig().build());
schema = new PostgresSchema(config, TestHelper.getTypeRegistry(), TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesIncluded("public.table1");
}
statements = "DROP TABLE IF EXISTS table1;" + "DROP TABLE IF EXISTS table2;" + "CREATE TABLE table2 (pk SERIAL, strcol VARCHAR, PRIMARY KEY(pk));";
TestHelper.execute(statements);
String tableId = "public.table2";
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesIncluded(tableId);
assertTablesExcluded("public.table1");
assertTableSchema(tableId, "strcol", Schema.OPTIONAL_STRING_SCHEMA);
}
statements = "ALTER TABLE table2 ADD COLUMN vc VARCHAR(2);" + "ALTER TABLE table2 ADD COLUMN si SMALLINT;" + "ALTER TABLE table2 DROP COLUMN strcol;";
TestHelper.execute(statements);
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, TableId.parse(tableId, false));
assertTablesIncluded(tableId);
assertTablesExcluded("public.table1");
assertTableSchema(tableId, "vc, si", Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_INT16_SCHEMA);
assertColumnsExcluded(tableId + ".strcol");
}
}
Aggregations