Skip to content

Add Oracle Reverse ITs - #4177

Open
dhwanilpatel wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
dhwanilpatel:oracle_reverse_it
Open

Add Oracle Reverse ITs#4177
dhwanilpatel wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
dhwanilpatel:oracle_reverse_it

Conversation

@dhwanilpatel

Copy link
Copy Markdown
Contributor

Adding Oracle ITs for Reverse template.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust testing framework for Oracle as a target database in the Spanner-to-SourceDB migration template. It adds multiple integration tests covering various scenarios such as data type compatibility, handling of reserved keywords, wide row support, and complex schema mapping via overrides. Additionally, it improves the reliability of Oracle-based integration tests by providing better resource management and DLQ retry validation.

Highlights

  • Oracle Integration Tests: Added a comprehensive suite of integration tests for Oracle as a target database, including support for custom shards, data types, reserved keywords, and wide rows.
  • Oracle Resource Management: Introduced SharedOracleReverseITContainer and OracleGeneratedColumnUtils to handle Oracle-specific resource lifecycle, schema creation, and data validation.
  • Schema Overrides: Implemented support for both file-based and string-based schema mapping overrides to handle table and column renaming during migration.
  • DLQ Handling: Added robust integration tests for retryDLQ and retryAllDLQ modes, ensuring proper handling of retriable and severe errors in sharded topologies.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive integration tests and utility classes to support reverse replication from Spanner to Oracle databases, including sharded topologies, dead-letter queue (DLQ) retries, custom transformations, and various datatype mappings. Feedback on these changes highlights several important areas for improvement: addressing potential SQL injection vulnerabilities caused by dynamic SQL string concatenation in the test base and shared container classes, resolving a resource leak where the singleton Oracle resource manager is never closed, replacing magic strings with existing constants, removing or implementing placeholder empty methods, and fixing a state leakage bug in the test cleanup method by ensuring shard-specific test usernames are properly reset.

"REV_" +
java.util.UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase();
LOG.info("Creating isolated Oracle user: {}", username);
jdbcResourceManager.runSQLUpdate("CREATE USER " + username + " IDENTIFIED BY password");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

This SQL statement is constructed using string concatenation with the username variable, which is a potential SQL injection vulnerability. Although username is generated from a UUID in this context and is likely safe, it's a security best practice to avoid building queries this way. Please consider using PreparedStatement for executing queries with parameters, or at least sanitizing the input. This concern also applies to the GRANT statements below, and to similar dynamic SQL in runIsolatedSQLQuery (line 622) and createOracleSchema (line 649).

Comment on lines +15 to +30
public static synchronized OracleResourceManager getInstance() {
if (instance == null) {
instance = OracleResourceManager.builder("oracle-rev-bulk-db").build();
try {
try (Connection systemConn =
DriverManager.getConnection(instance.getUri(), "SYSTEM", instance.getPassword());
Statement stmt = systemConn.createStatement()) {
stmt.execute("GRANT DBA TO " + instance.getUsername());
LOG.info("Successfully granted DBA to Testcontainers Oracle app user!");
}
} catch (Exception e) {
LOG.warn("Failed to grant DBA using SYSTEM. CREATE USER might fail.", e);
}
}
return instance;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The singleton OracleResourceManager instance created here is never cleaned up. This can lead to resource leaks, as the underlying test container might not be shut down properly after tests complete.

Please consider adding a shutdown hook or a static cleanup method that can be called from a test suite's @AfterAll hook to ensure instance.close() is called.

try (Connection systemConn =
DriverManager.getConnection(instance.getUri(), "SYSTEM", instance.getPassword());
Statement stmt = systemConn.createStatement()) {
stmt.execute("GRANT DBA TO " + instance.getUsername());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

This GRANT statement is constructed using string concatenation, which is a potential SQL injection vulnerability. While instance.getUsername() is likely safe in this test context as it's generated by the resource manager, it is a security best practice to use parameterized queries or sanitize inputs to prevent SQL injection.

com.google.cloud.teleport.v2.templates.constants.Constants
.SOURCE_POSTGRESQL))
.SOURCE_POSTGRESQL)
&& !Objects.equals(sourceType, "oracle"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The magic string "oracle" is used here. For consistency and maintainability, please use the existing constant ORACLE_SOURCE_TYPE from com.google.cloud.teleport.v2.spanner.migrations.constants.Constants.

Comment on lines +665 to +669
protected void createOracleTableWithNColumns(
org.apache.beam.it.jdbc.OracleResourceManager jdbcResourceManager,
String arg1,
int arg2,
String arg3) {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This method createOracleTableWithNColumns is empty. It seems to be a placeholder. Please either implement it or remove it to avoid confusion.

Comment on lines +684 to +686
public static void clearIsolatedUser() {
testUsername = null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The clearIsolatedUser method only resets testUsername. It should also reset testUsernameShardA and testUsernameShardB to prevent state from leaking between tests using different shards.

public static void clearIsolatedUser() {
  testUsername = null;
  testUsernameShardA = null;
  testUsernameShardB = null;
}

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.10%. Comparing base (65ea26d) to head (8bd93bd).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##               main    #4177       +/-   ##
=============================================
+ Coverage     35.83%   63.10%   +27.26%     
- Complexity      711     2784     +2073     
=============================================
  Files           250      562      +312     
  Lines         17131    32614    +15483     
  Branches       1750     3645     +1895     
=============================================
+ Hits           6139    20580    +14441     
- Misses        10479    10991      +512     
- Partials        513     1043      +530     
Components Coverage Δ
spanner-templates 84.64% <ø> (∅)
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 88.66% <ø> (∅)
spanner-live-reverse-replication 81.27% <ø> (∅)
spanner-bulk-migration 89.06% <ø> (∅)
gcs-spanner-dv 87.87% <ø> (∅)
see 448 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant