use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class PostgresSchemaIT method shouldLoadSchemaForExtensionPostgresTypes.
@Test
public void shouldLoadSchemaForExtensionPostgresTypes() throws Exception {
TestHelper.executeDDL("postgres_create_tables.ddl");
PostgresConnectorConfig config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(PostgresConnectorConfig.INCLUDE_UNKNOWN_DATATYPES, true).build());
schema = new PostgresSchema(config, TestHelper.getTypeRegistry(), TopicSelector.create(config));
try (PostgresConnection connection = TestHelper.create()) {
schema.refresh(connection, false);
assertTablesIncluded(TEST_TABLES);
assertTableSchema("public.custom_table", "lt, i", Schema.OPTIONAL_BYTES_SCHEMA, Schema.OPTIONAL_BYTES_SCHEMA);
}
}
use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.
the class PostgresConnector method validate.
@Override
public Config validate(Map<String, String> connectorConfigs) {
PostgresConnectorConfig config = new PostgresConnectorConfig(Configuration.from(connectorConfigs));
// First, validate all of the individual fields, which is easy since don't make any of the fields invisible ...
Map<String, ConfigValue> results = config.validate();
// Get the config values for each of the connection-related fields ...
ConfigValue hostnameValue = results.get(PostgresConnectorConfig.HOSTNAME.name());
ConfigValue portValue = results.get(PostgresConnectorConfig.PORT.name());
ConfigValue databaseValue = results.get(PostgresConnectorConfig.DATABASE_NAME.name());
ConfigValue userValue = results.get(PostgresConnectorConfig.USER.name());
ConfigValue passwordValue = results.get(PostgresConnectorConfig.PASSWORD.name());
// If there are no errors on any of these ...
if (hostnameValue.errorMessages().isEmpty() && portValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty() && databaseValue.errorMessages().isEmpty()) {
// Try to connect to the database ...
try (PostgresConnection connection = new PostgresConnection(config.jdbcConfig())) {
try {
connection.execute("SELECT version()");
logger.info("Successfully tested connection for {} with user '{}'", connection.connectionString(), connection.username());
} catch (SQLException e) {
logger.info("Failed testing connection for {} with user '{}'", connection.connectionString(), connection.username());
hostnameValue.addErrorMessage("Unable to connect: " + e.getMessage());
}
}
}
return new Config(new ArrayList<>(results.values()));
}
Aggregations