-
Notifications
You must be signed in to change notification settings - Fork 1.1k
tests: Bulk IT Tests #2005
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
Merged
Merged
tests: Bulk IT Tests #2005
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dc29a71
tests
asthamohta 6cc7803
changes
asthamohta e7fb2f8
Merge branch 'main' into bulk-it
asthamohta 511a49f
change
asthamohta 8ca9fd0
change
asthamohta 5105a36
change
asthamohta 5a2f546
change
asthamohta d53175f
change
asthamohta 869a4c7
change
asthamohta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
v2/sourcedb-to-spanner/src/test/java/com/google/cloud/teleport/v2/templates/MySQLDDLIT.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright (C) 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package com.google.cloud.teleport.v2.templates; | ||
|
|
||
| import com.google.cloud.spanner.Struct; | ||
| import com.google.cloud.teleport.metadata.SkipDirectRunnerTest; | ||
| import com.google.cloud.teleport.metadata.TemplateIntegrationTest; | ||
| import com.google.common.collect.ImmutableList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.beam.it.common.PipelineLauncher; | ||
| import org.apache.beam.it.common.PipelineOperator; | ||
| import org.apache.beam.it.common.utils.ResourceManagerUtils; | ||
| import org.apache.beam.it.gcp.spanner.SpannerResourceManager; | ||
| import org.apache.beam.it.gcp.spanner.matchers.SpannerAsserts; | ||
| import org.apache.beam.it.jdbc.MySQLResourceManager; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| /** | ||
| * An integration test for {@link SourceDbToSpanner} Flex template which tests a migration with DDL | ||
| * changes to schema. Changes include Index changes, Primary key transformations and Generated | ||
| * columns migration. | ||
| */ | ||
| @Category({TemplateIntegrationTest.class, SkipDirectRunnerTest.class}) | ||
| @TemplateIntegrationTest(SourceDbToSpanner.class) | ||
| @RunWith(JUnit4.class) | ||
| public class MySQLDDLIT extends SourceDbToSpannerITBase { | ||
| private static PipelineLauncher.LaunchInfo jobInfo; | ||
|
|
||
| public static MySQLResourceManager mySQLResourceManager; | ||
| public static SpannerResourceManager spannerResourceManager; | ||
|
|
||
| private static final String SESSION_FILE_RESOURCE = "DDLIT/company-session.json"; | ||
| private static final String MYSQL_DDL_RESOURCE = "DDLIT/company-mysql-schema.sql"; | ||
| private static final String SPANNER_DDL_RESOURCE = "DDLIT/company-spanner-schema.sql"; | ||
|
|
||
| /** | ||
| * Setup resource managers and Launch dataflow job once during the execution of this test class. \ | ||
| */ | ||
| @Before | ||
| public void setUp() { | ||
| mySQLResourceManager = setUpMySQLResourceManager(); | ||
| spannerResourceManager = setUpSpannerResourceManager(); | ||
| } | ||
|
|
||
| /** Cleanup dataflow job and all the resources and resource managers. */ | ||
| @After | ||
| public void cleanUp() { | ||
| ResourceManagerUtils.cleanResources(spannerResourceManager, mySQLResourceManager); | ||
| } | ||
|
|
||
| @Test | ||
| public void ddlModificationTest() throws Exception { | ||
| loadSQLFileResource(mySQLResourceManager, MYSQL_DDL_RESOURCE); | ||
| createSpannerDDL(spannerResourceManager, SPANNER_DDL_RESOURCE); | ||
| jobInfo = | ||
| launchDataflowJob( | ||
| getClass().getSimpleName(), | ||
| SESSION_FILE_RESOURCE, | ||
| "mapper", | ||
| mySQLResourceManager, | ||
| spannerResourceManager, | ||
| null, | ||
| null); | ||
| PipelineOperator.Result result = pipelineOperator().waitUntilDone(createConfig(jobInfo)); | ||
|
|
||
| List<Map<String, Object>> companyMySQL = | ||
| mySQLResourceManager.runSQLQuery("SELECT company_id, company_name FROM company"); | ||
| ImmutableList<Struct> companySpanner = | ||
| spannerResourceManager.readTableRecords("company", "company_id", "company_name"); | ||
|
|
||
| SpannerAsserts.assertThatStructs(companySpanner) | ||
| .hasRecordsUnorderedCaseInsensitiveColumns(companyMySQL); | ||
|
|
||
| List<Map<String, Object>> employeeMySQL = | ||
| mySQLResourceManager.runSQLQuery( | ||
| "SELECT employee_id, company_id, employee_name, employee_address FROM employee"); | ||
| ImmutableList<Struct> employeeSpanner = | ||
| spannerResourceManager.readTableRecords( | ||
| "employee", "employee_id", "company_id", "employee_name", "employee_address"); | ||
|
|
||
| SpannerAsserts.assertThatStructs(employeeSpanner) | ||
| .hasRecordsUnorderedCaseInsensitiveColumns(employeeMySQL); | ||
|
|
||
| ImmutableList<Struct> employeeAttribute = | ||
| spannerResourceManager.readTableRecords( | ||
| "employee_attribute", "employee_id", "attribute_name", "value"); | ||
|
|
||
| SpannerAsserts.assertThatStructs(employeeAttribute).hasRows(4); // Supports composite keys | ||
asthamohta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ImmutableList<Struct> vendor = | ||
| spannerResourceManager.readTableRecords("vendor", "vendor_id", "full_name"); | ||
|
|
||
| SpannerAsserts.assertThatStructs(vendor).hasRows(3); | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
v2/sourcedb-to-spanner/src/test/resources/DDLIT/company-mysql-schema.sql
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| CREATE TABLE `company` ( | ||
| `company_id` int(11) PRIMARY KEY NOT NULL, | ||
| `company_name` varchar(100) DEFAULT NULL, | ||
| `created_on` date | ||
| ); | ||
|
|
||
| INSERT INTO `company` VALUES | ||
| (1,'gog','1998-09-04'), | ||
| (2,'app','1976-04-01'), | ||
| (3,'ama','1994-07-05'); | ||
|
|
||
| CREATE TABLE `employee` ( | ||
| `employee_id` int(11) PRIMARY KEY NOT NULL, | ||
| `company_id` int(11) DEFAULT NULL, | ||
| `employee_name` varchar(100) DEFAULT NULL, | ||
| `employee_address` varchar(100) DEFAULT NULL, | ||
| `created_on` date | ||
| ); | ||
|
|
||
| INSERT INTO `employee` VALUES | ||
| (100,1,'emp1','add1','1996-01-01'), | ||
| (101,1,'emp2','add2','1999-01-01'), | ||
| (102,1,'emp3','add3','2012-01-01'), | ||
| (300,3,'emp300','add300','1996-01-01'); | ||
|
|
||
| CREATE TABLE `employee_attribute` ( | ||
| `employee_id` int(11) NOT NULL, | ||
| `attribute_name` varchar(100) NOT NULL, | ||
| `value` varchar(100) DEFAULT NULL, | ||
| `updated_on` date, | ||
| PRIMARY KEY (`employee_id`,`attribute_name`) | ||
| ); | ||
|
|
||
| INSERT INTO `employee_attribute` VALUES | ||
| (100,'iq','150','2024-06-10'), | ||
| (101,'iq','120','2024-06-10'), | ||
| (102,'iq','20','2024-06-10'), | ||
| (300,'endurance','20','2024-06-10'); | ||
|
|
||
| CREATE TABLE `vendor` ( | ||
| `vendor_id` INT AUTO_INCREMENT PRIMARY KEY, | ||
| `first_name` VARCHAR(255) NOT NULL, | ||
| `last_name` VARCHAR(255) NOT NULL, | ||
| `email` VARCHAR(255) UNIQUE NOT NULL, | ||
| `full_name` VARCHAR(512) GENERATED ALWAYS AS (CONCAT(first_name, ' ', last_name)), | ||
| INDEX full_name_idx (full_name) | ||
| ); | ||
|
|
||
| INSERT INTO vendor (vendor_id, first_name, last_name, email) VALUES | ||
| (1, 'David', 'Lee', 'david.lee@example.com'), | ||
| (2, 'Sarah', 'Jones', 'sarah.jones@example.com'), | ||
| (3, 'Michael', 'Brown', 'michael.brown@example.com'); | ||
|
|
||
| CREATE TABLE `mysql_extra` ( | ||
| `test_id` int(11) PRIMARY KEY NOT NULL, | ||
| `test_name` varchar(100) DEFAULT NULL | ||
| ); | ||
|
|
||
| CREATE VIEW company_view AS SELECT company_id FROM company; |
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.
Uh oh!
There was an error while loading. Please reload this page.