Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Conversation

Vipinofficial11
Copy link
Collaborator

@Vipinofficial11 Vipinofficial11 commented May 9, 2023

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"
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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 .

Copy link
Collaborator Author

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.

Copy link
Collaborator

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
Copy link
Collaborator Author

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"
Copy link
Collaborator Author

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.

Ishakaushik-cloud and others added 5 commits May 15, 2023 11:28
# 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;

Copy link
Collaborator Author

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.

Choose a reason for hiding this comment

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

resolved

Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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.

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";
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

remove system.out

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 {
Copy link
Collaborator Author

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.

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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove main method.

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


Copy link
Collaborator Author

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.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Uncomment all the steps.

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
Copy link
Collaborator Author

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

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

Copy link
Collaborator Author

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

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
Copy link
Collaborator Author

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.

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


Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove extra lines.

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
Copy link
Collaborator Author

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.

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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the main method.

Choose a reason for hiding this comment

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

resolved

Copy link
Collaborator Author

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.

@Vipinofficial11
Copy link
Collaborator Author

To do :

  1. @priyabhatnagar25 @Ishakaushik-cloud Squash all the commits.
  2. For me - Do a final review.

@Vipinofficial11
Copy link
Collaborator Author

@priyabhatnagar25 @Ishakaushik-cloud Squash all the commits for final review as asked.

@IshaCS IshaCS closed this Jun 5, 2023
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


Copy link
Collaborator Author

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

Copy link
Collaborator

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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix the indentation/spacing.

Copy link
Collaborator

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);
Copy link
Collaborator Author

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.

Copy link
Collaborator

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 {
Copy link
Collaborator Author

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.

Copy link
Collaborator

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()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix spacing.

Copy link
Collaborator

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);
Copy link
Collaborator Author

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.

Copy link
Collaborator

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")
Copy link
Collaborator Author

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.

Copy link
Collaborator

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);
Copy link
Collaborator Author

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.

Copy link
Collaborator

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the comments

Copy link
Collaborator

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");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove comment

Copy link
Collaborator

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");
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the space.

Copy link
Collaborator

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() {
Copy link
Collaborator Author

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.

Copy link
Collaborator

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;
Copy link
Collaborator Author

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 ?

Copy link
Collaborator

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this

Copy link
Collaborator

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this as well.

Copy link
Collaborator

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this.

Copy link
Collaborator

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this

Copy link
Collaborator

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

done
commit link- b6c555b

@Vipinofficial11
Copy link
Collaborator Author

Vipinofficial11 commented Jun 9, 2023

@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')");
Copy link
Collaborator Author

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))";
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants