Skip to content

Commit

Permalink
Fixing CloudSQL MySQL Build Failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatgulati committed Jul 21, 2023
1 parent cb5e3ee commit fbcda3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class CloudMySqlClient {

private static final String DATATYPES_COLUMNS = PluginPropertyUtils.pluginProp("datatypesColumns");
private static String dataTypesColumns = PluginPropertyUtils.pluginProp("datatypesColumns");

public static Connection getCloudSqlConnection() throws ClassNotFoundException, SQLException {
Class.forName("com.google.cloud.sql.mysql.SocketFactory");
Expand Down Expand Up @@ -158,8 +158,7 @@ public static void createSourceDatatypesTable(String sourceTable) throws SQLExce

public static void createTargetDatatypesTable(String targetTable) throws SQLException, ClassNotFoundException {
try (Connection connect = getCloudSqlConnection(); Statement statement = connect.createStatement()) {
String datatypesColumns = DATATYPES_COLUMNS;
String createTargetTableQuery = "CREATE TABLE " + targetTable + " " + datatypesColumns;
String createTargetTableQuery = "CREATE TABLE " + targetTable + " " + dataTypesColumns;
statement.executeUpdate(createTargetTableQuery);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,35 @@
*/
public class CloudMysql implements CdfHelper {

private static final String TARGET_TABLE = PluginPropertyUtils.pluginProp("targetTable");
private static final String BQ_SOURCE_TABLE = PluginPropertyUtils.pluginProp("bqSourceTable");
private static String targetTable = PluginPropertyUtils.pluginProp("targetTable");

private static String bqSourceTable = PluginPropertyUtils.pluginProp("bqSourceTable");

private static String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");

private static String bqTargetTable = PluginPropertyUtils.pluginProp("bqTargetTable");

@Then("Validate the values of records transferred to target table is equal to the values from source table")
public void validateTheValuesOfRecordsTransferredToTargetTableIsEqualToTheValuesFromSourceTable()
throws SQLException, ClassNotFoundException {
int countRecords = CloudMySqlClient.countRecord(TARGET_TABLE);
int countRecords = CloudMySqlClient.countRecord(targetTable);
Assert.assertEquals("Number of records transferred should be equal to records out ",
countRecords, recordOut());
BeforeActions.scenario.write(" ******** Number of records transferred ********:" + countRecords);
boolean recordsMatched = CloudMySqlClient.validateRecordValues(PluginPropertyUtils.pluginProp("sourceTable")
, TARGET_TABLE);
boolean recordsMatched = CloudMySqlClient.validateRecordValues(sourceTable, targetTable);
Assert.assertTrue("Value of records transferred to the target table should be equal to the value " +
"of the records in the source table", recordsMatched);
}

@Then("Validate the values of records transferred to target Big Query table is equal to the values from source table")
public void validateTheValuesOfRecordsTransferredToTargetBigQueryTableIsEqualToTheValuesFromSourceTable()
throws InterruptedException, IOException, SQLException, ClassNotFoundException {
int targetBQRecordsCount = BigQueryClient.countBqQuery(PluginPropertyUtils.pluginProp("bqTargetTable"));
int targetBQRecordsCount = BigQueryClient.countBqQuery(bqTargetTable);
BeforeActions.scenario.write("No of Records Transferred to BigQuery:" + targetBQRecordsCount);
Assert.assertEquals("Out records should match with target BigQuery table records count",
CdfPipelineRunAction.getCountDisplayedOnSourcePluginAsRecordsOut(), targetBQRecordsCount);

boolean recordsMatched = BQValidation.validateDBAndBQRecordValues(PluginPropertyUtils.pluginProp
("sourceTable"), PluginPropertyUtils.pluginProp("bqTargetTable"));
boolean recordsMatched = BQValidation.validateDBAndBQRecordValues(sourceTable, bqTargetTable);
Assert.assertTrue("Value of records transferred to the target table should be equal to the value " +
"of the records in the source table", recordsMatched);
}
Expand All @@ -67,12 +70,12 @@ public void validateTheValuesOfRecordsTransferredToTargetBigQueryTableIsEqualToT
"BigQuery table")
public void validateTheValuesOfRecordsTransferredToTargetCloudSQLMySqlTableIsEqualToTheValuesFromSourceBigQueryTable()
throws InterruptedException, IOException, SQLException, ClassNotFoundException {
int sourceBQRecordsCount = BigQueryClient.countBqQuery(BQ_SOURCE_TABLE);
int sourceBQRecordsCount = BigQueryClient.countBqQuery(bqSourceTable);
BeforeActions.scenario.write("No of Records from source BigQuery table:" + sourceBQRecordsCount);
Assert.assertEquals("Out records should match with target PostgreSQL table records count",
CdfPipelineRunAction.getCountDisplayedOnSourcePluginAsRecordsOut(), sourceBQRecordsCount);

boolean recordsMatched = BQValidation.validateBQAndDBRecordValues(BQ_SOURCE_TABLE, TARGET_TABLE);
boolean recordsMatched = BQValidation.validateBQAndDBRecordValues(bqSourceTable, targetTable);
Assert.assertTrue("Value of records transferred to the target table should be equal to the value " +
"of the records in the source table", recordsMatched);
}
Expand Down

0 comments on commit fbcda3f

Please sign in to comment.