Skip to content

Add oracle live ITs [Batch 1] - #4272

Open
dhwanilpatel wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
dhwanilpatel:oracle_live_it_PR
Open

dhwanilpatel wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
dhwanilpatel:oracle_live_it_PR

Conversation

@dhwanilpatel

Copy link
Copy Markdown
Contributor

Adding First batch of Oracle Live template ITs.

List of ITs:

  • DataStreamToSpannerOracleDDLIT
  • DataStreamToSpannerOracleStringOverridesIT
  • DatastreamToSpannerReservedKeywordsOracleIT
  • OracleDataStreamToSpannerSessionIT
  • OracleDataStreamToSpannerTimezoneIT
  • OracleDatastreamToSpannerDataTypesIT
  • OracleDataStreamToSpannerFileOverridesIT
  • OracleDataStreamToSpannerEventsIT

@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 the first batch of integration tests for the DataStream to Spanner template, specifically targeting Oracle source databases. These tests ensure robust handling of various Oracle data types, schema overrides, and complex scenarios like reserved keywords and timezone conversions. Additionally, the PR updates the CI/CD infrastructure to support necessary database authentication and provides improved utilities for managing Oracle resources during test execution.

Highlights

  • Integration Test Suite Expansion: Added a comprehensive first batch of Oracle Live template integration tests, covering DDL, string overrides, reserved keywords, session management, timezone handling, and data type conversions.
  • Infrastructure Updates: Updated CI/CD scripts and flags to support static Oracle database authentication, including the addition of an application password flag.
  • Utility Enhancements: Introduced helper methods in DataStreamToSpannerITBase to facilitate the execution of Oracle SQL scripts and improved Oracle resource management for integration tests.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/spanner-pr.yml
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 adds comprehensive integration tests and resource management support for Oracle database migrations to Spanner using Datastream. It introduces several new integration test classes covering DDL, datatype conversions, string and file overrides, reserved keywords, timezone handling, and session configurations, alongside a shared Oracle instance manager and a custom resource manager. The feedback suggests addressing a few critical issues: fixing the cleanup order in SpannerOracleResourceManager to prevent executing queries on a closed connection pool, removing an unused empty method, avoiding modifying the global JVM timezone in tests, using standard JDBC execution instead of fragile manual SQL parsing, ensuring consistent default passwords, and properly restoring the thread interrupted status when catching InterruptedException across multiple test files.

Comment on lines +45 to +66
public void cleanupAll() {
super.cleanupAll();

String userToDrop = this.getUsername();
if (userToDrop != null
&& !userToDrop.equalsIgnoreCase("system")
&& !userToDrop.contains("sysdba")) {
LOG.info("Attempting to dynamically drop isolated Oracle user: {}", userToDrop);
try {
if (userToDrop.toUpperCase().startsWith("C##")) {
SharedOracleLiveITInstance.getInstance()
.runSQLUpdate("DROP USER " + userToDrop + " CASCADE");
} else {
SharedOracleLiveITInstance.getInstance()
.runSQLUpdate("DROP USER " + userToDrop + " CASCADE");
}
LOG.info("Successfully dropped Oracle schema: {}", userToDrop);
} catch (Exception e) {
LOG.warn("Failed to drop schema: " + userToDrop, e);
}
}
}

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

There are multiple issues with the current implementation of cleanupAll():

  1. super.cleanupAll() is called first, which closes the connection pool of this instance. If this is the same instance returned by SharedOracleLiveITInstance.getInstance(), then calling runSQLUpdate on it will fail because the pool is already closed.
  2. The if-else block on lines 54-60 has identical branches.

We can simplify and fix this by dropping the user before calling super.cleanupAll(), using this.runSQLUpdate(...) directly.

  @Override
  public void cleanupAll() {
    String userToDrop = this.getUsername();
    if (userToDrop != null
        && !userToDrop.equalsIgnoreCase("system")
        && !userToDrop.contains("sysdba")) {
      LOG.info("Attempting to dynamically drop isolated Oracle user: {}", userToDrop);
      try {
        this.runSQLUpdate("DROP USER " + userToDrop + " CASCADE");
        LOG.info("Successfully dropped Oracle schema: {}", userToDrop);
      } catch (Exception e) {
        LOG.warn("Failed to drop schema: " + userToDrop, e);
      }
    }
    super.cleanupAll();
  }

@Before
public void setUp() throws Exception {
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("UTC"));
skipBaseCleanup = true;

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

Modifying the global JVM default timezone via TimeZone.setDefault is a known anti-pattern in shared JVM test execution. It can cause flakiness or unexpected failures in other timezone-sensitive tests running in the same JVM. If absolutely necessary, please store the original timezone in a static field and restore it in the @AfterClass cleanup method, or configure the timezone explicitly on the timezone-sensitive components.

Comment on lines +659 to +663
if (stmt.toLowerCase().trim().startsWith("select")) {
statement.executeQuery(stmt);
} else {
statement.executeUpdate(stmt);
}

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

Instead of manually parsing the SQL string to check if it starts with "select" (which can be fragile if there are comments or leading whitespace), you can use the standard JDBC statement.execute(stmt) method. It automatically handles both query and update/DDL statements.

            statement.execute(stmt);

Comment on lines +95 to +97
String url = "jdbc:oracle:thin:@//" + System.getProperty("cloudOracleHost") + ":1521/XE";
String user = System.getProperty("cloudOracleUsername", "system");
String pass = System.getProperty("cloudOraclePassword", "Test@Password123");

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 default password here ("Test@Password123") is inconsistent with the default password used elsewhere in this class ("TestPassword123" on line 36). Additionally, cloudOracleHost should default to "localhost" to prevent a null host in the JDBC URL if the system property is not set.

Suggested change
String url = "jdbc:oracle:thin:@//" + System.getProperty("cloudOracleHost") + ":1521/XE";
String user = System.getProperty("cloudOracleUsername", "system");
String pass = System.getProperty("cloudOraclePassword", "Test@Password123");
String url = "jdbc:oracle:thin:@//" + System.getProperty("cloudOracleHost", "localhost") + ":1521/XE";
String user = System.getProperty("cloudOracleUsername", "system");
String pass = System.getProperty("cloudOraclePassword", "TestPassword123");

getJDBCPrefix(), this.getHost(), this.getPort(getJDBCPort()), this.getDatabaseName());
}

public void runSQLUpdate(String sql, String user) {}

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 is empty and is not used anywhere in the codebase. It should be removed to keep the code clean.

Comment on lines +174 to +177
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
}

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

When catching InterruptedException, you should restore the interrupted status of the thread by calling Thread.currentThread().interrupt(). Ignoring it can prevent thread pools or frameworks from correctly managing the thread's lifecycle.

Suggested change
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
}
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

Comment on lines +250 to +253
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
}

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

When catching InterruptedException, you should restore the interrupted status of the thread by calling Thread.currentThread().interrupt(). Ignoring it can prevent thread pools or frameworks from correctly managing the thread's lifecycle.

Suggested change
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
}
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

Comment on lines +215 to +218
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
}

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

When catching InterruptedException, you should restore the interrupted status of the thread by calling Thread.currentThread().interrupt(). Ignoring it can prevent thread pools or frameworks from correctly managing the thread's lifecycle.

Suggested change
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
}
try {
Thread.sleep(CUTOVER_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.50%. Comparing base (6e68e20) to head (b9465e6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4272      +/-   ##
============================================
+ Coverage     56.35%   62.50%   +6.14%     
+ Complexity     7858     3671    -4187     
============================================
  Files          1154      594     -560     
  Lines         73194    35945   -37249     
  Branches       8580     4033    -4547     
============================================
- Hits          41252    22467   -18785     
+ Misses        29158    12330   -16828     
+ Partials       2784     1148    -1636     
Components Coverage Δ
spanner-templates 84.47% <ø> (-0.02%) ⬇️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 88.94% <ø> (-0.04%) ⬇️
spanner-live-reverse-replication 80.84% <ø> (-0.03%) ⬇️
spanner-bulk-migration 88.98% <ø> (-0.02%) ⬇️
gcs-spanner-dv 88.06% <ø> (-0.04%) ⬇️
see 577 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