[SpannerToSourceDb] Fixing flaky UT and also improving coverage#3874
[SpannerToSourceDb] Fixing flaky UT and also improving coverage#3874darshan-sj wants to merge 3 commits into
Conversation
Summary of ChangesHello, 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 focuses on improving the robustness of the SpannerToSourceDb migration tool by enhancing error handling in DML generation and refactoring factory initialization. Additionally, it significantly increases test coverage by adding comprehensive unit tests for various edge cases in DML generation, type handling, and shadow table creation, ensuring more stable and predictable behavior. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors SourceProcessorFactory to use immutable maps for generators, connection helpers, and connection URLs, and updates column mapping logic in CassandraDMLGenerator and DMLGeneratorUtils to log warnings and return null upon mapping failures. It also adds several unit tests for edge cases. However, making connectionHelperMap final and removing its setter prevents tests from mocking connection helpers, resulting in unused local variables in SourceProcessorFactoryTest and potential test flakiness from real connection attempts. Additionally, a duplicate mock setup line was identified in CassandraDMLGeneratorTest.
d19b1e6 to
e647fa5
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves error handling and robustness in the Spanner-to-SourceDB template by returning null and logging warnings when Spanner column mappings are missing in CassandraDMLGenerator and DMLGeneratorUtils. It also introduces comprehensive unit tests for these edge cases, type-handling failures, and shadow table creation exceptions, while removing some ignored tests in SourceWriterFnTest. The feedback points out a critical mismatch in the mock timeout duration within the new ShadowTableCreatorTest exception test, which could prevent the mock from being triggered and cause the test to fail.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3874 +/- ##
============================================
+ Coverage 55.53% 55.58% +0.04%
- Complexity 6576 6584 +8
============================================
Files 1103 1103
Lines 67570 67573 +3
Branches 7581 7581
============================================
+ Hits 37527 37561 +34
+ Misses 27627 27603 -24
+ Partials 2416 2409 -7
🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves error handling in CassandraDMLGenerator and DMLGeneratorUtils by logging warnings and returning null when Spanner columns are missing from the schema mapping. It also adds extensive unit tests covering these edge cases, type handling exceptions, and shadow table creation errors, while cleaning up unused imports and ignored tests. The review feedback suggests dynamically backing up and restoring the connection helper map in SourceProcessorFactoryTest instead of hardcoding it, which prevents the tests from becoming fragile when new database types are introduced.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves error handling in CassandraDMLGenerator and DMLGeneratorUtils by logging warnings and returning null when a Spanner column name is not found in the schema mapping. It also introduces a package-private getter in SourceProcessorFactory to facilitate saving and restoring static state in tests, cleans up unused imports and ignored tests in SourceWriterFnTest, and adds comprehensive unit tests across several test files. Feedback is provided on SourceProcessorFactory to return an unmodifiable map from getConnectionHelperMap() to prevent accidental modifications of internal static state.
| PreparedStatementGeneratedResponse prepResponse = (PreparedStatementGeneratedResponse) response; | ||
|
|
||
| assertTrue(prepResponse.getDmlStatement().contains("\"LastName\"")); | ||
| assertTrue(!prepResponse.getDmlStatement().contains("\"MissingCol\"")); |
There was a problem hiding this comment.
better to use assertFalse here for readbility
| spannerColName = schemaMapper.getSpannerColumnName("", sourceTable.name(), sourceColName); | ||
| } catch (NoSuchElementException e) { | ||
| continue; | ||
| LOG.warn( |
There was a problem hiding this comment.
I think we should restore this change , what if there are 2 pks in mysql , 1 in spanner and the 2nd one in mysql has default set , then the insert statement would be perfectly valid, i tested:
create table test1(id int, id1 int default 1, name varchar(1000), PRIMARY key (id,id1));
insert into test1(id) values (1);
| when(sourceTable.name()).thenReturn("src_table"); | ||
|
|
||
| when(schemaMapper.getSpannerColumnName("", "src_table", "col1")) | ||
| .thenThrow(new java.util.NoSuchElementException("Not found")); |
There was a problem hiding this comment.
please use imports: java.util.NoSuchElementException
| } | ||
|
|
||
| @Test | ||
| public void testGetPkColumnValues_SpannerColDefNull() { |
There was a problem hiding this comment.
actually when the column definition null it should be treated same as NoSuchElementException which means we should skip this column. Thoughts?
Context - #3830 (comment)