-
Notifications
You must be signed in to change notification settings - Fork 3
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
e2e Tests for cloudSQL-MySQL #7
base: develop
Are you sure you want to change the base?
Conversation
Then Navigate to the properties page of plugin: "CloudSQL MySQL" | ||
Then Select dropdown plugin property: "select-jdbcPluginName" with option value: "cloudsql-mysql" | ||
Then Select radio button plugin property: "instanceType" with value: "public" | ||
Then Enter input plugin property: "connectionName" with value: "cdf-athena:us-central1:sql-automation-test-instance" |
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.
cdf-athena:us-central1:sql-automation-test-instance
These values shouldn't be hardcoded use them from PluginParameter.properties file. (Update all the test cases.)
@CloudMySql | ||
Feature: CloudMySql sink- Verify CloudMySql sink plugin design time scenarios | ||
|
||
Scenario: To verify CloudMySql sink plugin validation with mandatory properties |
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.
There are more scenarios in the RTM where we are validating the plugin with different properties present in the plugin. Create more Design Time scenarios .
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.
I don't see this one addressed.
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.
done
Then Navigate to the properties page of plugin: "BigQuery" | ||
Then Replace input plugin property: "project" with value: "projectId" | ||
Then Enter input plugin property: "datasetProject" with value: "projectId" | ||
Then Override Service account details if set in environment variables |
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.
No need to use this step, remove wherever used.
Then Click on the Macro button of Property: "user" and set the value to: "username" | ||
Then Click on the Macro button of Property: "password" and set the value to: "password" | ||
Then Select radio button plugin property: "instanceType" with value: "public" | ||
Then Enter input plugin property: "connectionName" with value: "cdf-athena:us-central1:sql-automation-test-instance" |
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.
Same comment don't hardcode this value, use PluginParameter.properties file.
# Conflicts: # cloudsql-mysql-plugin/src/e2e-test/java/io/cdap/plugin/CloudMySqlClient.java # cloudsql-mysql-plugin/src/e2e-test/resources/pluginParameters.properties
@@ -0,0 +1,4 @@ | |||
package io.cdap.plugin.CloudMySql.runners; | |||
|
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.
If you are creating this class use it properly define the cucumber options and use the tag in the tests which can be run as required tests.
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.
resolved
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.
Add the link of commit whenever you mark a comment as resolved.
private static final String database = PluginPropertyUtils.pluginProp("DatabaseName"); | ||
private static final String connectionName = PluginPropertyUtils.pluginProp("ConnectionName"); | ||
|
||
public static void main(String[] args) throws SQLException, ClassNotFoundException { |
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.
Remove the main method from here we don't need this in production code.
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.
resolved
String instanceConnectionName = "cdf-athena:us-central1:sql-automation-test-instance"; | ||
String databaseName = "TestDatabase"; | ||
String Username = "v"; | ||
String Password = "v@123"; |
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.
Use all these credentials by creating environment variables
String Username = "v"; | ||
String Password = "v@123"; | ||
String jdbcUrl = String.format("jdbc:mysql:///%s?cloudSqlInstance=%s&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=%s&password=%s", databaseName, instanceConnectionName, Username, Password); | ||
Connection conn = DriverManager.getConnection(jdbcUrl); |
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.
Don't hardcode this string here. Add it in the plugin parameter properties file and pick it from there.
String Password = "v@123"; | ||
String jdbcUrl = String.format("jdbc:mysql:///%s?cloudSqlInstance=%s&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=%s&password=%s", databaseName, instanceConnectionName, Username, Password); | ||
Connection conn = DriverManager.getConnection(jdbcUrl); | ||
System.out.println("connected to database"); |
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.
remove system.out
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.
resolved
return conn; | ||
} | ||
|
||
public static int countRecord(String table) throws SQLException, ClassNotFoundException { |
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.
Add java doc to all the newly created methods defining what they are doing.
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.
resolved
*/ | ||
|
||
public class TestSetupHooks { | ||
public static void main(String[] args) throws SQLException, ClassNotFoundException { |
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.
Remove main method.
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.
resolved
Then Validate "CloudSQL MySQL" plugin properties | ||
Then Close the Plugin Properties page | ||
|
||
|
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.
Remove the extra spaces just leave one line at last.
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.
resolved
Then Enter input plugin property: "referenceName" with value: "RefName" | ||
Then Enter input plugin property: "database" with value: "TestDatabase" | ||
Then Enter textarea plugin property: "importQuery" with value: "insertQuery" | ||
# Then Click on the Get Schema button |
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.
Uncomment all the steps.
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.
resolved
Feature: CloudMySql Sink - Run time scenarios | ||
|
||
@BQ_SOURCE_TEST @CLOUDMYSQL_TEST_TABLE | ||
Scenario: To verify data is getting transferred from BigQuery source to CloudMySql sink successfully |
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.
Add more run time test scenarios
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.
resolved
Then Open and capture logs | ||
Then Verify the pipeline status is "Succeeded" | ||
Then Close the pipeline logs | ||
|
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.
Create a scenario to use macro argument in Advanced section
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.
RESOLVED
Then Close the pipeline logs | ||
|
||
@BQ_SOURCE_TEST @CLOUDMYSQL_TEST_TABLE | ||
Scenario: Verify pipeline failure message in logs when user provides invalid Table Name of plugin with Macros |
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.
For these negative tests add step to validate error message on log level.
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.
resolved
Then Click on the Validate button | ||
Then Close the Plugin Properties page | ||
|
||
|
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.
Remove extra lines.
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.
resolved
Then Verify the pipeline status is "Succeeded" | ||
|
||
@CLOUDMYSQL_SOURCE_DATATYPES_TEST | ||
Scenario: Verify user should not be able to deploy and run the pipeline when plugin is configured with invalid bounding query |
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.
Add step to validate the log message.
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.
resolved
|
||
public class BQValidation { | ||
public static void main(String[] args) { | ||
// validateBQAndDBRecordValues(String schema, String sourceTable, String targetTable) |
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.
Remove the main method.
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.
resolved
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.
I don't see any commits. How should I make sure its resolved ?
Push the changes first then when marking them as resolved add the commit link in the comment.
To do :
|
@priyabhatnagar25 @Ishakaushik-cloud Squash all the commits for final review as asked. |
Then Close the pipeline logs | ||
Then Validate the values of records transferred to target CloudSQLMySql table is equal to the values from source BigQuery table | ||
|
||
|
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.
remove extra space just one line space is enough
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.
done
commit link- b037661
|
||
|
||
public static boolean validateBQAndDBRecordValues(String sourceTable, String targetTable) | ||
throws SQLException, ClassNotFoundException, IOException, InterruptedException, ParseException { |
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.
fix the indentation/spacing.
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.
done
commit link- b037661
throws SQLException, ClassNotFoundException, IOException, InterruptedException, ParseException { | ||
getBigQueryTableData(sourceTable, bigQueryRows); | ||
for (Object rows : bigQueryRows) { | ||
JsonObject json = new Gson().fromJson(String.valueOf(rows), JsonObject.class); |
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.
Create a global Gson object and re-use it in both the methods.
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.
done
commit link- b037661
*/ | ||
|
||
private static void getBigQueryTableData(String table, List<Object> bigQueryRows) | ||
throws IOException, InterruptedException { |
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.
fix spacing, We are using 2 space indentation.
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.
done
commit link- b037661
String dataset = PluginPropertyUtils.pluginProp("dataset"); | ||
String selectQuery = "SELECT TO_JSON(t) FROM `" + projectId + "." + dataset + "." + table + "` AS t"; | ||
TableResult result = BigQueryClient.getQueryResult(selectQuery); | ||
result.iterateAll().forEach(value -> bigQueryRows.add(value.get(0).getValue())); |
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.
fix spacing.
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.
done
commit link- b037661
case Types.DECIMAL: | ||
org.apache.spark.sql.types.Decimal sourceDecimal = org.apache.spark.sql.types.Decimal.fromDecimal(rsSource.getBigDecimal(currentColumnCount)); | ||
org.apache.spark.sql.types.Decimal targetDecimal = org.apache.spark.sql.types.Decimal.fromDecimal(bigQueryData.get(jsonObjectIdx).get(columnName).getAsBigDecimal()); | ||
Assert.assertEquals("Different values found for column : %s", sourceDecimal, targetDecimal); |
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.
Don't directly import it here.
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.
done
commit link- b037661
* CloudSqlMySql Plugin related step design. | ||
*/ | ||
public class CloudMysql implements CdfHelper { | ||
@Then("Validate the values of records transferred to target table is equal to the values from source table") |
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.
Why do we have 3 validation Steps here ? keep the 2 we are using and delete the unused one.
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.
done
commit link- b037661
|
||
String jdbcUrl = String.format( | ||
PluginPropertyUtils.pluginProp("jdbcURL"), | ||
database, instanceConnectionName, username, password); |
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.
fixing spacing in above lines.
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.
done
commit link- b037661
|
||
@Before(order = 2, value = "@CLOUDMYSQL_TEST_TABLE") | ||
public static void createCloudMysqlTestTable() throws SQLException, ClassNotFoundException { | ||
// BeforeActions.scenario.write("SQL Target table name - " + sqlTargetTableName); |
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.
Remove the comments
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.
done
commit link- b037661
} | ||
System.out.println(bqSourceTable); | ||
PluginPropertyUtils.addPluginProp("bqSourceTable", bqSourceTable); | ||
// BeforeActions.scenario.write("BQ Source Table " + bqSourceTable + " created successfully"); |
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.
Remove comment
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.
done
commit link- b037661
PluginPropertyUtils.addPluginProp("bqSourceTable", bqSourceTable); | ||
// BeforeActions.scenario.write("BQ Source Table " + bqSourceTable + " created successfully"); | ||
} | ||
|
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.
Remove the space.
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.
done
commit link- b037661
*/ | ||
|
||
public class TestSetupHooks { | ||
public static void setTableName() { |
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.
If you are using a formatter then set 2 space indentation in it. We use the same indentation in all the files and here in this project 2 spaces one is used.
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.
done
commit link- b037661
@@ -35,6 +35,7 @@ public class OracleSourceSchemaReader extends CommonSchemaReader { | |||
* Oracle type constants, from Oracle JDBC Implementation. | |||
*/ | |||
public static final int INTERVAL_YM = -103; | |||
public static final int TINY_BLOB = -3; |
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.
Why do we need these changes here, to handle tiny blob type in validation logic ?
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.
done
commit link- b037661
// Insert query does not return any record. | ||
// Iterator on TableResult values in getSoleQueryResult method throws NoSuchElementException | ||
} | ||
System.out.println(bqSourceTable); |
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.
Remove this
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.
done
commit link- b6c555b
PluginPropertyUtils.addPluginProp("sourceTable", sourceTableName); | ||
PluginPropertyUtils.addPluginProp("targetTable", targetTableName); | ||
PluginPropertyUtils.addPluginProp("selectQuery", String.format("select * from %s", sourceTableName)); | ||
System.out.println(sourceTableName); |
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.
Remove this as well.
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.
done
commit link- b6c555b
String datatypesColumns = PluginPropertyUtils.pluginProp("CloudMySqlDatatypesColumns"); | ||
String createTargetTableQuery = "CREATE TABLE " + targetTable + " " + datatypesColumns; | ||
statement.executeUpdate(createTargetTableQuery); | ||
System.out.println(createTargetTableQuery); |
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.
Remove this.
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.
done
commit link- b6c555b
String datatypesColumns = PluginPropertyUtils.pluginProp("datatypesColumns"); | ||
String createTargetTableQuery = "CREATE TABLE " + targetTable + " " + datatypesColumns; | ||
statement.executeUpdate(createTargetTableQuery); | ||
System.out.println(createTargetTableQuery); |
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.
Remove this
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.
done
commit link- b6c555b
String datatypesColumns = PluginPropertyUtils.pluginProp("datatypesColumns"); | ||
String createSourceTableQuery = "CREATE TABLE " + sourceTable + " " + datatypesColumns; | ||
statement.executeUpdate(createSourceTableQuery); | ||
System.out.println(createSourceTableQuery); |
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.
Remove this.
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.
done
commit link- b6c555b
@bharatgulati Do a dry run of the data validation logic and if everything is good raise an external PR after cherry picking. Changes LGTM. |
// Insert dummy data. | ||
statement.executeUpdate("INSERT INTO " + sourceTable + " (id, lastName)" + "VALUES (1, 'Priya')"); | ||
statement.executeUpdate("INSERT INTO " + sourceTable + " (id, lastName)" + "VALUES (2, 'Shubhangi')"); | ||
statement.executeUpdate("INSERT INTO " + sourceTable + " (id, lastName)" + "VALUES (3, 'Shorya')"); |
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.
@priyabhatnagar25 @IshaCS This PR was supposed to be raised externally are we planning to raise this ?
|
||
public static void createSourceTable(String sourceTable) throws SQLException, ClassNotFoundException { | ||
try (Connection connect = getCloudSqlConnection(); Statement statement = connect.createStatement()) { | ||
String createSourceTableQuery = "CREATE TABLE IF NOT EXISTS " + sourceTable + "(id int, lastName varchar(255), PRIMARY KEY (id))"; |
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.
Same here, I know these things should be flagged in review but (@priyabhatnagar25 & @IshaCS ) you both have been working on this and didn't see this is wrong it shouldn't be hardcoded.
@Ishakaushik-cloud @AnkitCLI @priyabhatnagar25