New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to handle version-specific integration tests #1037
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0782ebe
Fix to handle version-specific integration tests
jnmt 3133c8e
Fix service name and version threshold
jnmt 5feddc5
Use JDBC API to get database info
jnmt 7cb850a
Fix message
jnmt 7804a42
Merge branch 'master' into fix-version-specific-integration-tests
brfrn169 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,11 @@ | |
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.commons.dbcp2.BasicDataSource; | ||
|
||
public class JdbcAdminImportTestUtils { | ||
static final String SUPPORTED_TABLE_NAME = "supported_table"; | ||
static final List<String> UNSUPPORTED_DATA_TYPES_MYSQL = | ||
Arrays.asList( | ||
"BIGINT UNSIGNED", | ||
|
@@ -54,7 +56,6 @@ public class JdbcAdminImportTestUtils { | |
"numeric(8,2)", | ||
"path", | ||
"pg_lsn", | ||
"pg_snapshot", // after v14 | ||
"point", | ||
"polygon", | ||
"serial", | ||
|
@@ -68,6 +69,8 @@ public class JdbcAdminImportTestUtils { | |
"txid_snapshot", | ||
"uuid", | ||
"xml"); | ||
static final List<String> UNSUPPORTED_DATA_TYPES_PGSQL_V13_OR_LATER = | ||
Collections.singletonList("pg_snapshot"); | ||
static final List<String> UNSUPPORTED_DATA_TYPES_ORACLE = | ||
Arrays.asList( | ||
"BFILE", | ||
|
@@ -76,13 +79,14 @@ public class JdbcAdminImportTestUtils { | |
"INT", | ||
"INTERVAL YEAR(3) TO MONTH", | ||
"INTERVAL DAY(2) TO SECOND", | ||
"JSON", | ||
"NUMBER(16,0)", | ||
"ROWID", | ||
"TIMESTAMP", | ||
"TIMESTAMP WITH TIME ZONE", | ||
"TIMESTAMP WITH LOCAL TIME ZONE", | ||
"UROWID"); | ||
static final List<String> UNSUPPORTED_DATA_TYPES_ORACLE_V20_OR_LATER = | ||
Collections.singletonList("JSON"); | ||
static final List<String> UNSUPPORTED_DATA_TYPES_MSSQL = | ||
Arrays.asList( | ||
"date", | ||
|
@@ -103,73 +107,27 @@ public class JdbcAdminImportTestUtils { | |
|
||
private final JdbcConfig config; | ||
private final RdbEngineStrategy rdbEngine; | ||
private final int majorVersion; | ||
|
||
public JdbcAdminImportTestUtils(Properties properties) { | ||
config = new JdbcConfig(new DatabaseConfig(properties)); | ||
rdbEngine = RdbEngineFactory.create(config); | ||
majorVersion = getMajorVersion(); | ||
} | ||
|
||
public Map<String, TableMetadata> createExistingDatabaseWithAllDataTypes(String namespace) | ||
throws SQLException { | ||
Map<String, TableMetadata> results = new HashMap<>(); | ||
List<String> sqls = new ArrayList<>(); | ||
LinkedHashMap<String, String> goodTableColumns; | ||
TableMetadata goodTableMetadata; | ||
Map<String, String> badTables; | ||
if (rdbEngine instanceof RdbEngineMysql) { | ||
goodTableColumns = prepareColumnsForMysql(); | ||
goodTableMetadata = prepareTableMetadataForMysql(); | ||
if (JdbcEnv.isMariaDB()) { | ||
badTables = | ||
prepareCreateNonImportableTableSql( | ||
namespace, | ||
UNSUPPORTED_DATA_TYPES_MYSQL.stream() | ||
.filter(type -> !type.equalsIgnoreCase("JSON")) | ||
.collect(Collectors.toList())); | ||
} else { | ||
badTables = prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_MYSQL); | ||
} | ||
return createExistingMysqlDatabaseWithAllDataTypes(namespace); | ||
} else if (rdbEngine instanceof RdbEnginePostgresql) { | ||
goodTableColumns = prepareColumnsForPostgresql(); | ||
goodTableMetadata = prepareTableMetadataForPostgresql(); | ||
badTables = prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_PGSQL); | ||
return createExistingPostgresDatabaseWithAllDataTypes(namespace); | ||
} else if (rdbEngine instanceof RdbEngineOracle) { | ||
goodTableColumns = prepareColumnsForOracle(); | ||
goodTableMetadata = prepareTableMetadataForOracle(); | ||
badTables = prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_ORACLE); | ||
|
||
// LONG columns must be tested with separated tables since they cannot be coexisted | ||
TableMetadata longRawMetadata = prepareTableMetadataForOracleForLongRaw(); | ||
sqls.add( | ||
prepareCreateTableSql( | ||
namespace, | ||
"good_table_long_raw", | ||
prepareColumnsForOracleLongRaw(), | ||
longRawMetadata.getPartitionKeyNames())); | ||
results.put("good_table_long_raw", longRawMetadata); | ||
return createExistingOracleDatabaseWithAllDataTypes(namespace); | ||
} else if (rdbEngine instanceof RdbEngineSqlServer) { | ||
goodTableColumns = prepareColumnsForSqlServer(); | ||
goodTableMetadata = prepareTableMetadataForSqlServer(); | ||
badTables = prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_MSSQL); | ||
return createExistingSqlServerDatabaseWithAllDataTypes(namespace); | ||
} else { | ||
throw new RuntimeException(); | ||
} | ||
|
||
// table with all supported columns | ||
sqls.add( | ||
prepareCreateTableSql( | ||
namespace, "good_table", goodTableColumns, goodTableMetadata.getPartitionKeyNames())); | ||
results.put("good_table", goodTableMetadata); | ||
|
||
// tables with an unsupported column | ||
badTables.forEach( | ||
(table, sql) -> { | ||
sqls.add(sql); | ||
results.put(table, null); | ||
}); | ||
|
||
execute(sqls.toArray(new String[0])); | ||
return results; | ||
} | ||
|
||
public void dropTable(String namespace, String table) throws SQLException { | ||
|
@@ -216,7 +174,7 @@ private LinkedHashMap<String, String> prepareColumnsForMysql() { | |
columns.put("col19", "MEDIUMBLOB"); | ||
columns.put("col20", "LONGBLOB"); | ||
columns.put("col21", "BINARY(255)"); | ||
if (JdbcEnv.isMariaDB()) { | ||
if (isMariaDB()) { | ||
columns.put("col22", "JSON"); | ||
} | ||
return columns; | ||
|
@@ -250,7 +208,7 @@ private TableMetadata prepareTableMetadataForMysql() { | |
.addColumn("col21", DataType.BLOB) | ||
.addPartitionKey("pk1") | ||
.addPartitionKey("pk2"); | ||
if (JdbcEnv.isMariaDB()) { | ||
if (isMariaDB()) { | ||
builder.addColumn("col22", DataType.TEXT); | ||
} | ||
return builder.build(); | ||
|
@@ -435,4 +393,165 @@ private String prepareCreateTableSql( | |
+ primaryKeys.stream().map(rdbEngine::enclose).collect(Collectors.joining(",")) | ||
+ "))"; | ||
} | ||
|
||
private Map<String, TableMetadata> createExistingMysqlDatabaseWithAllDataTypes(String namespace) | ||
throws SQLException { | ||
TableMetadata tableMetadata = prepareTableMetadataForMysql(); | ||
Map<String, String> supportedTables = | ||
Collections.singletonMap( | ||
SUPPORTED_TABLE_NAME, | ||
prepareCreateTableSql( | ||
namespace, | ||
SUPPORTED_TABLE_NAME, | ||
prepareColumnsForMysql(), | ||
tableMetadata.getPartitionKeyNames())); | ||
Map<String, TableMetadata> supportedTableMetadata = | ||
Collections.singletonMap(SUPPORTED_TABLE_NAME, tableMetadata); | ||
|
||
Map<String, String> unsupportedTables; | ||
if (isMariaDB()) { | ||
unsupportedTables = | ||
prepareCreateNonImportableTableSql( | ||
namespace, | ||
UNSUPPORTED_DATA_TYPES_MYSQL.stream() | ||
.filter(type -> !type.equalsIgnoreCase("JSON")) | ||
.collect(Collectors.toList())); | ||
} else { | ||
unsupportedTables = | ||
prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_MYSQL); | ||
} | ||
|
||
return executeCreateTableSql(supportedTables, supportedTableMetadata, unsupportedTables); | ||
} | ||
|
||
private Map<String, TableMetadata> createExistingPostgresDatabaseWithAllDataTypes( | ||
String namespace) throws SQLException { | ||
TableMetadata tableMetadata = prepareTableMetadataForPostgresql(); | ||
Map<String, String> supportedTables = | ||
Collections.singletonMap( | ||
SUPPORTED_TABLE_NAME, | ||
prepareCreateTableSql( | ||
namespace, | ||
SUPPORTED_TABLE_NAME, | ||
prepareColumnsForPostgresql(), | ||
tableMetadata.getPartitionKeyNames())); | ||
Map<String, TableMetadata> supportedTableMetadata = | ||
Collections.singletonMap(SUPPORTED_TABLE_NAME, tableMetadata); | ||
|
||
Map<String, String> unsupportedTables = | ||
prepareCreateNonImportableTableSql( | ||
namespace, | ||
majorVersion >= 13 | ||
? Stream.concat( | ||
UNSUPPORTED_DATA_TYPES_PGSQL.stream(), | ||
UNSUPPORTED_DATA_TYPES_PGSQL_V13_OR_LATER.stream()) | ||
.collect(Collectors.toList()) | ||
: UNSUPPORTED_DATA_TYPES_PGSQL); | ||
|
||
return executeCreateTableSql(supportedTables, supportedTableMetadata, unsupportedTables); | ||
} | ||
|
||
private Map<String, TableMetadata> createExistingOracleDatabaseWithAllDataTypes(String namespace) | ||
throws SQLException { | ||
Map<String, String> supportedTables = new HashMap<>(); | ||
Map<String, TableMetadata> supportedTableMetadata = new HashMap<>(); | ||
|
||
TableMetadata tableMetadata = prepareTableMetadataForOracle(); | ||
supportedTables.put( | ||
SUPPORTED_TABLE_NAME, | ||
prepareCreateTableSql( | ||
namespace, | ||
SUPPORTED_TABLE_NAME, | ||
prepareColumnsForOracle(), | ||
tableMetadata.getPartitionKeyNames())); | ||
supportedTableMetadata.put(SUPPORTED_TABLE_NAME, tableMetadata); | ||
|
||
// LONG columns must be tested with separated tables since they cannot be coexisted | ||
TableMetadata longRawTableMetadata = prepareTableMetadataForOracleForLongRaw(); | ||
supportedTables.put( | ||
SUPPORTED_TABLE_NAME + "_long_raw", | ||
prepareCreateTableSql( | ||
namespace, | ||
SUPPORTED_TABLE_NAME + "_long_raw", | ||
prepareColumnsForOracleLongRaw(), | ||
longRawTableMetadata.getPartitionKeyNames())); | ||
supportedTableMetadata.put(SUPPORTED_TABLE_NAME + "_long_raw", longRawTableMetadata); | ||
|
||
Map<String, String> unsupportedTables = | ||
prepareCreateNonImportableTableSql( | ||
namespace, | ||
majorVersion >= 20 | ||
? Stream.concat( | ||
UNSUPPORTED_DATA_TYPES_ORACLE.stream(), | ||
UNSUPPORTED_DATA_TYPES_ORACLE_V20_OR_LATER.stream()) | ||
.collect(Collectors.toList()) | ||
: UNSUPPORTED_DATA_TYPES_ORACLE); | ||
|
||
return executeCreateTableSql(supportedTables, supportedTableMetadata, unsupportedTables); | ||
} | ||
|
||
private Map<String, TableMetadata> createExistingSqlServerDatabaseWithAllDataTypes( | ||
String namespace) throws SQLException { | ||
TableMetadata tableMetadata = prepareTableMetadataForSqlServer(); | ||
Map<String, String> supportedTables = | ||
Collections.singletonMap( | ||
SUPPORTED_TABLE_NAME, | ||
prepareCreateTableSql( | ||
namespace, | ||
SUPPORTED_TABLE_NAME, | ||
prepareColumnsForSqlServer(), | ||
tableMetadata.getPartitionKeyNames())); | ||
Map<String, TableMetadata> supportedTableMetadata = | ||
Collections.singletonMap(SUPPORTED_TABLE_NAME, tableMetadata); | ||
|
||
Map<String, String> unsupportedTables = | ||
prepareCreateNonImportableTableSql(namespace, UNSUPPORTED_DATA_TYPES_MSSQL); | ||
|
||
return executeCreateTableSql(supportedTables, supportedTableMetadata, unsupportedTables); | ||
} | ||
|
||
private Map<String, TableMetadata> executeCreateTableSql( | ||
Map<String, String> supportedTables, | ||
Map<String, TableMetadata> supportedTableMetadata, | ||
Map<String, String> unsupportedTables) | ||
throws SQLException { | ||
Map<String, TableMetadata> results = new HashMap<>(); | ||
List<String> sqls = new ArrayList<>(); | ||
|
||
// table with all supported columns | ||
supportedTables.forEach( | ||
(table, sql) -> { | ||
sqls.add(sql); | ||
results.put(table, supportedTableMetadata.get(table)); | ||
}); | ||
|
||
// tables with an unsupported column | ||
unsupportedTables.forEach( | ||
(table, sql) -> { | ||
sqls.add(sql); | ||
results.put(table, null); | ||
}); | ||
|
||
execute(sqls.toArray(new String[0])); | ||
return results; | ||
} | ||
|
||
private boolean isMariaDB() { | ||
try (BasicDataSource dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); | ||
Connection connection = dataSource.getConnection()) { | ||
String version = connection.getMetaData().getDatabaseProductVersion(); | ||
return version.contains("MariaDB"); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("Get database major version failed"); | ||
} | ||
} | ||
|
||
private int getMajorVersion() { | ||
try (BasicDataSource dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); | ||
Connection connection = dataSource.getConnection()) { | ||
return connection.getMetaData().getDatabaseMajorVersion(); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("Get database major version failed"); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Thank you! Fixed in 7cb850a.