Skip to content

Commit

Permalink
Merge pull request #1464 from cloudsufi/bqmt-hookchanges
Browse files Browse the repository at this point in the history
BQMT e2e fix
  • Loading branch information
psainics authored Nov 29, 2024
2 parents 692dfcd + dc14783 commit b49a189
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@BigQueryMultiTable_Sink
Feature: BigQueryMultiTable sink -Verification of BigQuery to BigQueryMultiTable successful data transfer

@BQ_TWO_SOURCE_BQMT_TEST @BQ_DELETE_TABLES_TEST
@BQ_TWO_SOURCE_BQMT_TEST @BQ_TWO_SINK_BQMT_TEST
Scenario: Verify data successfully transferred from BigQuery To BigQueryMultiTable in two new tables
Given Open Datafusion Project to configure pipeline
When Expand Plugin group in the LHS plugins list: "Source"
Expand Down Expand Up @@ -89,7 +89,7 @@ Feature: BigQueryMultiTable sink -Verification of BigQuery to BigQueryMultiTable
Then Verify the pipeline status is "Succeeded"
Then Validate data transferred from BigQuery To BigQueryMultiTable in one table is equal

@BQ_TWO_SOURCE_BQMT_TEST @BQ_EXISTING_TARGET_TEST @BQ_DELETE_TABLES_TEST
@BQ_TWO_SOURCE_BQMT_TEST @BQ_EXISTING_TARGET_TEST @BQ_TWO_SINK_BQMT_TEST
Scenario: Verify data successfully transferred from BigQuery To BigQueryMultiTable in two existing tables
Given Open Datafusion Project to configure pipeline
When Expand Plugin group in the LHS plugins list: "Source"
Expand Down Expand Up @@ -131,7 +131,7 @@ Feature: BigQueryMultiTable sink -Verification of BigQuery to BigQueryMultiTable
Then Verify the pipeline status is "Succeeded"
Then Validate data transferred from BigQuery To BigQueryMultiTable is equal

@BQ_TWO_SOURCE_BQMT_TEST @BQ_EXISTING_TARGET_TEST @BQ_DELETE_TABLES_TEST
@BQ_TWO_SOURCE_BQMT_TEST @BQ_EXISTING_TARGET_TEST @BQ_TWO_SINK_BQMT_TEST
Scenario: Verify data successfully transferred from BigQuery To BigQueryMultiTable in two existing tables using truncate
Given Open Datafusion Project to configure pipeline
When Expand Plugin group in the LHS plugins list: "Source"
Expand Down Expand Up @@ -174,7 +174,7 @@ Feature: BigQueryMultiTable sink -Verification of BigQuery to BigQueryMultiTable
Then Verify the pipeline status is "Succeeded"
Then Validate data transferred from BigQuery To BigQueryMultiTable is equal

@BQ_SOURCE_UPDATE_TEST @BQ_EXISTING_TARGET_TEST @BQ_DELETE_TABLES_TEST
@BQ_SOURCE_UPDATE_TEST @BQ_EXISTING_TARGET_TEST @BQ_TWO_SINK_BQMT_TEST
Scenario: Verify data successfully transferred from BigQuery To BigQueryMultiTable in two existing tables after updating schema
Given Open Datafusion Project to configure pipeline
When Expand Plugin group in the LHS plugins list: "Source"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.cdap.plugin.bigquery.stepsdesign;

import io.cdap.e2e.utils.PluginPropertyUtils;
import io.cdap.plugin.common.stepsdesign.TestSetupHooks;
import io.cucumber.java.en.Then;
import org.junit.Assert;

Expand All @@ -32,11 +33,10 @@ public class BigQueryMultiTable {
@Then("Validate data transferred from BigQuery To BigQueryMultiTable is equal")
public void validateDataTransferredFromBigQueryToBigQueryMultiTableIsEqual()
throws IOException, InterruptedException {
List<String> sourceTables = Arrays.asList(PluginPropertyUtils.pluginProp("bqSourceTable"),
PluginPropertyUtils.pluginProp("bqSourceTable2"));
List<String> sourceTables = Arrays.asList(TestSetupHooks.bqSourceTable, TestSetupHooks.bqSourceTable2);

List<String> targetTables = Arrays.asList(PluginPropertyUtils.pluginProp("bqTargetTable"),
PluginPropertyUtils.pluginProp("bqTargetTable2"));
List<String> targetTables = Arrays.asList(PluginPropertyUtils.pluginProp("bqmtTargetTable"),
PluginPropertyUtils.pluginProp("bqmtTargetTable2"));
boolean recordsMatched = BigQueryMultiTableValidation.validateBQToBigQueryMultiTable(sourceTables, targetTables);
Assert.assertTrue("Value of records transferred to the BQ sink should be equal to the value " +
"of the records in the source table", recordsMatched);
Expand All @@ -46,8 +46,8 @@ public void validateDataTransferredFromBigQueryToBigQueryMultiTableIsEqual()
public void validateDataTransferredFromBigQueryToBigQueryMultiTableInOneTableIsEqual()
throws IOException, InterruptedException {
boolean recordsMatched = BigQueryMultiTableValidation.
validateBQToBigQueryMultiTable(Collections.singletonList(PluginPropertyUtils.pluginProp("bqSourceTable")),
Collections.singletonList(PluginPropertyUtils.pluginProp("bqTargetTable")));
validateBQToBigQueryMultiTable(Collections.singletonList(TestSetupHooks.bqSourceTable),
Collections.singletonList(TestSetupHooks.bqmtTargetTable));
Assert.assertTrue("Value of records transferred to the BQ sink should be equal to the value " +
"of the records in the source table", recordsMatched);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class TestSetupHooks {
public static String gcsSourceBucketName = StringUtils.EMPTY;
public static String gcsTargetBucketName = StringUtils.EMPTY;
public static String bqTargetTable = StringUtils.EMPTY;
public static String bqmtTargetTable = StringUtils.EMPTY;
public static String bqmtTargetTable2 = StringUtils.EMPTY;
public static String bqSourceTable = StringUtils.EMPTY;
public static String bqSourceTable2 = StringUtils.EMPTY;
public static String bqTargetTable2 = StringUtils.EMPTY;
Expand Down Expand Up @@ -298,7 +300,8 @@ public static void createTempSourceBQTable() throws IOException, InterruptedExce
"@BQ_INSERT_SOURCE_TEST or @BQ_UPDATE_SINK_TEST or @BQ_EXISTING_SOURCE_TEST or @BQ_EXISTING_SINK_TEST or " +
"@BQ_EXISTING_SOURCE_DATATYPE_TEST or @BQ_EXISTING_SINK_DATATYPE_TEST or @BQ_UPSERT_SOURCE_TEST or " +
"@BQ_NULL_MODE_SOURCE_TEST or @BQ_UPDATE_SOURCE_DEDUPE_TEST or @BQ_INSERT_INT_SOURCE_TEST or " +
"@BQ_TIME_SOURCE_TEST or @BQ_UPSERT_DEDUPE_SOURCE_TEST or @BQ_PRIMARY_RECORD_SOURCE_TEST")
"@BQ_TIME_SOURCE_TEST or @BQ_UPSERT_DEDUPE_SOURCE_TEST or @BQ_PRIMARY_RECORD_SOURCE_TEST or " +
"@BQ_SINGLE_SOURCE_BQMT_TEST")
public static void deleteTempSourceBQTable() throws IOException, InterruptedException {
BigQueryClient.dropBqQuery(bqSourceTable);
PluginPropertyUtils.removePluginProp("bqSourceTable");
Expand Down Expand Up @@ -1554,20 +1557,22 @@ public static void emptyExistingBigTableInstanceAndTableName() {
bigtableExistingTargetTable = StringUtils.EMPTY;
}

@Before(order = 1, value = "@BQ_EXISTING_TARGET_TEST")
@Before(order = 2, value = "@BQ_EXISTING_TARGET_TEST")
public static void createSinkTables() throws IOException, InterruptedException {
bqTargetTable = PluginPropertyUtils.pluginProp("bqTargetTable");
bqTargetTable2 = PluginPropertyUtils.pluginProp("bqTargetTable2");
io.cdap.e2e.utils.BigQueryClient.getSoleQueryResult("create table `" + datasetName + "." + bqTargetTable + "` " +
bqmtTargetTable = PluginPropertyUtils.pluginProp("bqmtTargetTable");
bqmtTargetTable2 = PluginPropertyUtils.pluginProp("bqmtTargetTable2");
io.cdap.e2e.utils.BigQueryClient.getSoleQueryResult("create table `" + datasetName + "." + bqmtTargetTable + "` " +
"(ID INT64, tablename STRING," +
"Price FLOAT64, Customer_Exists BOOL ) ");

io.cdap.e2e.utils.BigQueryClient.getSoleQueryResult("create table `" + datasetName + "." + bqTargetTable2 + "` " +
io.cdap.e2e.utils.BigQueryClient.getSoleQueryResult("create table `" + datasetName + "." + bqmtTargetTable2 + "` " +
"(ID INT64, tablename STRING," +
"Price FLOAT64, Customer_Exists BOOL ) ");

PluginPropertyUtils.addPluginProp("bqTargetTable", bqTargetTable);
PluginPropertyUtils.addPluginProp("bqTargetTable2", bqTargetTable2);
PluginPropertyUtils.addPluginProp("bqmtTargetTable", bqmtTargetTable);
PluginPropertyUtils.addPluginProp("bqmtTargetTable2", bqmtTargetTable2);
BeforeActions.scenario.write("BQ Target table - " + bqmtTargetTable + " created successfully");
BeforeActions.scenario.write("BQ Target table2 - " + bqmtTargetTable2 + " created successfully");
}
@Before(order = 1, value = "@BQ_SOURCE_UPDATE_TEST")
public static void createSourceTables() throws IOException, InterruptedException {
Expand Down Expand Up @@ -1602,48 +1607,70 @@ public static void createSourceTables() throws IOException, InterruptedException

PluginPropertyUtils.addPluginProp("bqSourceTable", bqSourceTable);
PluginPropertyUtils.addPluginProp("bqSourceTable2", bqSourceTable2);
BeforeActions.scenario.write("BQ Source table - " + bqSourceTable + " created successfully");
BeforeActions.scenario.write("BQ Source table2 - " + bqSourceTable2 + " created successfully");
}

@After(order = 1, value = "@BQ_DELETE_TABLES_TEST")
public static void deleteAllBqTables() throws IOException, InterruptedException {
BigQueryClient.dropBqQuery(bqSourceTable);
@After(order = 2, value = "@BQ_SINK_BQMT_TEST")
public static void deleteTargetBqmtTable() throws IOException, InterruptedException {
try {
bqmtTargetTable = PluginPropertyUtils.pluginProp("bqmtTargetTable");
BigQueryClient.dropBqQuery(bqmtTargetTable);
BeforeActions.scenario.write("BQ Target table - " + bqmtTargetTable + " deleted successfully");
} catch (BigQueryException e) {
if (e.getMessage().contains("Not found: Table")) {
BeforeActions.scenario.write("BQ Target Table " + bqmtTargetTable + " does not exist");
} else {
Assert.fail(e.getMessage());
}
}
}

@After(order = 1, value = "@BQ_SECONDARY_RECORD_SOURCE_TEST")
public static void deleteTempSource2BQTable() throws IOException, InterruptedException {
BigQueryClient.dropBqQuery(bqSourceTable2);
bqTargetTable = PluginPropertyUtils.pluginProp("bqTargetTable");
bqTargetTable2 = PluginPropertyUtils.pluginProp("bqTargetTable2");
BigQueryClient.dropBqQuery(bqTargetTable);
BigQueryClient.dropBqQuery(bqTargetTable2);
PluginPropertyUtils.removePluginProp("bqSourceTable");
bqSourceTable2 = PluginPropertyUtils.pluginProp("bqSourceTable2");
PluginPropertyUtils.removePluginProp("bqSourceTable2");
BeforeActions.scenario.write("BQ source Table " + bqSourceTable + " deleted successfully");
BeforeActions.scenario.write("BQ source Table2 " + bqSourceTable2 + " deleted successfully");
BeforeActions.scenario.write("BQ target Table " + bqTargetTable + " deleted successfully");
BeforeActions.scenario.write("BQ target Table2 " + bqTargetTable2 + " deleted successfully");
}

@After(order = 1, value = "@BQ_SINK_BQMT_TEST")
public static void deleteTargetBqmtTable() throws IOException, InterruptedException {
@After(order = 2, value = "@BQ_TWO_SOURCE_BQMT_TEST or @BQ_SOURCE_UPDATE_TEST")
public static void deleteTwoSourceTables() throws IOException, InterruptedException {
try {
bqTargetTable = PluginPropertyUtils.pluginProp("bqTargetTable");
BigQueryClient.dropBqQuery(bqTargetTable);
BigQueryClient.dropBqQuery(bqSourceTable);
BeforeActions.scenario.write("BQ Target table - " + bqTargetTable + " deleted successfully");
BigQueryClient.dropBqQuery(bqSourceTable2);
BeforeActions.scenario.write("BQ Source table - " + bqSourceTable + " deleted successfully");
bqTargetTable = StringUtils.EMPTY;
BeforeActions.scenario.write("BQ Source table2 - " + bqSourceTable2 + " deleted successfully");
PluginPropertyUtils.removePluginProp("bqSourceTable");
PluginPropertyUtils.removePluginProp("bqSourceTable2");

} catch (BigQueryException e) {
if (e.getMessage().contains("Not found: Table")) {
BeforeActions.scenario.write("BQ Target Table " + bqTargetTable + " does not exist");
BeforeActions.scenario.write("BQ Source Table " + bqSourceTable + " does not exist");
BeforeActions.scenario.write("BQ Source Table2 " + bqSourceTable2 + " does not exist");
} else {
Assert.fail(e.getMessage());
}
}
}

@After(order = 1, value = "@BQ_SECONDARY_RECORD_SOURCE_TEST")
public static void deleteTempSource2BQTable() throws IOException, InterruptedException {
BigQueryClient.dropBqQuery(bqSourceTable2);
bqSourceTable2 = PluginPropertyUtils.pluginProp("bqSourceTable2");
PluginPropertyUtils.removePluginProp("bqSourceTable2");
BeforeActions.scenario.write("BQ source Table2 " + bqSourceTable2 + " deleted successfully");
@After(order = 2, value = "@BQ_TWO_SINK_BQMT_TEST")
public static void deleteTwoTargetTables() throws IOException, InterruptedException {
try {
bqmtTargetTable = PluginPropertyUtils.pluginProp("bqmtTargetTable");
bqmtTargetTable2 = PluginPropertyUtils.pluginProp("bqmtTargetTable2");
BigQueryClient.dropBqQuery(bqmtTargetTable);
BigQueryClient.dropBqQuery(bqmtTargetTable2);
BeforeActions.scenario.write("BQ Target table - " + bqmtTargetTable + " deleted successfully");
BeforeActions.scenario.write("BQ Target table2 - " + bqmtTargetTable2 + " deleted successfully");

} catch (BigQueryException e) {
if (e.getMessage().contains("Not found: Table")) {
BeforeActions.scenario.write("BQ Target Table " + bqmtTargetTable + " does not exist");
BeforeActions.scenario.write("BQ Target Table2 " + bqmtTargetTable2 + " does not exist");
} else {
Assert.fail(e.getMessage());
}
}
}
}
8 changes: 5 additions & 3 deletions src/e2e-test/resources/pluginParameters.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
projectId=cdf-athena
datasetprojectId=cdf-athena
dataset=testing_bqmt
dataset=testbq_bqmt
wrongSourcePath=gs://00000000-e2e-0014a44f-81be-4501-8360-0ddca192492
serviceAccountType=filePath
serviceAccount=auto-detect
Expand Down Expand Up @@ -350,8 +350,10 @@ dsExpectedFile=testdata/BQValidationExpectedFiles/datastoreexpectedfile
## BQMT-PLUGIN-PROPERTIES-START
bqmtCreateTableQueryFile=testdata/BigQuery/BqmtCreateTableQuery.txt
bqmtInsertDataQueryFile=testdata/BigQuery/BqmtInsertDataQuery.txt
bqTargetTable=tabA
bqTargetTable2=tabB
bqTargetTable=dummy
bqTargetTable2=dummy
bqmtTargetTable=tabA
bqmtTargetTable2=tabB
## BQMT-PLUGIN-PROPERTIES-END

##CLOUDBIGTABLE-PLUGIN-PROPERTIES-START
Expand Down

0 comments on commit b49a189

Please sign in to comment.