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

Added e2e tests with snapshot and cdc- Draft PR #103

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
123 changes: 123 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,129 @@
</plugins>
</build>
</profile>
<profile>
<id>e2e-tests</id>
<properties>
<testSourceLocation>src/e2e-test/java</testSourceLocation>
<TEST_RUNNER>TestRunner.java</TEST_RUNNER>
</properties>
<build>
<testResources>
<testResource>
<directory>src/e2e-test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>${TEST_RUNNER}</include>
</includes>
<!--Start configuration to run TestRunners in parallel-->
<parallel>classes</parallel> <!--Running TestRunner classes in parallel-->
<threadCount>2</threadCount> <!--Number of classes to run in parallel-->
<forkCount>2</forkCount> <!--Number of JVM processes -->
<reuseForks>true</reuseForks>
<!--End configuration to run TestRunners in parallel-->
<environmentVariables>
<GOOGLE_APPLICATION_CREDENTIALS>
${GOOGLE_APPLICATION_CREDENTIALS}
</GOOGLE_APPLICATION_CREDENTIALS>
<SERVICE_ACCOUNT_TYPE>
${SERVICE_ACCOUNT_TYPE}
</SERVICE_ACCOUNT_TYPE>
<SERVICE_ACCOUNT_FILE_PATH>
${SERVICE_ACCOUNT_FILE_PATH}
</SERVICE_ACCOUNT_FILE_PATH>
<SERVICE_ACCOUNT_JSON>
${SERVICE_ACCOUNT_JSON}
</SERVICE_ACCOUNT_JSON>
</environmentVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.5.0</version>

<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Cucumber Reports</projectName> <!-- Replace with project name -->
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<buildNumber>1</buildNumber>
<skip>false</skip>
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory>
<jsonFiles> <!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles> <!-- optional, defaults to outputDirectory if not specified -->
<classificationDirectory>${project.build.directory}/cucumber-reports</classificationDirectory>
<checkBuildResult>true</checkBuildResult>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.tests.e2e</groupId>
<artifactId>cdap-e2e-framework</artifactId>
<version>0.3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.8</version>
<scope>runtime</scope>
</dependency>
</dependencies>

</profile>

</profiles>

</project>
Expand Down
78 changes: 78 additions & 0 deletions src/e2e-test/features/Pipeline.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to rename the file to SanityTests.feature to reflect the intent

# Copyright © 2023 Cask Data, Inc.
#
# 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.
#

Feature: Oracle - Verify Oracle source data transfer

# Scenario: Sanity test from Oracle to Big Query
# Given Open DataFusion Project with replication to configure pipeline
# When Enter input plugin property: "name" with value: "pipelineName"
# And Click on the Next button
# And Select Oracle as Source
# Then Replace input plugin property: "host" with value: "host" for Credentials and Authorization related fields
# Then Replace input plugin property: "port" with value: "port" for Credentials and Authorization related fields
# Then Click plugin property: "region"
# Then Click plugin property: "regionOption"
# Then Replace input plugin property: "user" with value: "username" for Credentials and Authorization related fields
# Then Replace input plugin property: "password" with value: "password" for Credentials and Authorization related fields
# Then Replace input plugin property: "sid" with value: "database" for Credentials and Authorization related fields
# Then Click on the Next button
# Then Replace input plugin property: "loadInterval" with value: "loadInterval"
# Then Click on the Next button
# Then Validate Table is available and can be selected "ABC.E2E-sanity"
# And Click on the Next button
# And Click on the Next button
# And Click on the Next button
# Then Deploy the replication pipeline
# And Run the replication Pipeline
# Then Open the logs
# And Wait till pipeline is in running state and check if no errors occurred
# Then Verify expected Oracle records in target BigQuery table
# And Capture raw logs
# Then Close the pipeline logs and stop the pipeline
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this comment block be removed?


# @ORACLE_SOURCE
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the significance of this annotation? Why is it commented out?

Scenario: To verify snapshot and cdc from Oracle to Big Query successfully
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Scenario: To verify snapshot and cdc from Oracle to Big Query successfully
Scenario: To verify replication of snapshot and cdc data from Oracle to Big Query successfully

Given Open DataFusion Project with replication to configure pipeline
When Enter input plugin property: "name" with value: "pipelineName"
And Click on the Next button
And Select Oracle as Source
Then Replace input plugin property: "host" with value: "host" for Credentials and Authorization related fields
Then Replace input plugin property: "port" with value: "port" for Credentials and Authorization related fields
Then Click plugin property: "region"
Then Click plugin property: "regionOption"
Then Replace input plugin property: "user" with value: "username" for Credentials and Authorization related fields
Then Replace input plugin property: "password" with value: "password" for Credentials and Authorization related fields
Then Replace input plugin property: "sid" with value: "database" for Credentials and Authorization related fields
Then Click on the Next button
Then Replace input plugin property: "loadInterval" with value: "loadInterval"
Then Click on the Next button
Then Validate Table is available and can be selected "ABC.E2E1"
And Click on the Next button
And Click on the Next button
And Click on the Next button
Then Deploy the replication pipeline
And Run the replication Pipeline
Then Open the logs
And Wait till pipeline is in running state and check if no errors occurred
Then Verify expected Oracle records in target BigQuery table
And Insert a record in the source table and wait for replication
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we seperate out wait for replication part so that we can compose a scenario where multiple operations can be performed in one go and then we can wait once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we then separate wait for every operation i.e., insert,update and delete or shall we combine operations ?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can combine too as that achieves the same thing

Then Verify expected Oracle records in target BigQuery table
And Delete a record in the source table and wait for replication
Then Verify expected Oracle records in target BigQuery table
And Update a record in the source table and wait for replication
Then Verify expected Oracle records in target BigQuery table
And Capture raw logs
Then Close the pipeline logs and stop the pipeline
154 changes: 154 additions & 0 deletions src/e2e-test/java/io.cdap.plugin/actions/ReplicationActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright (c) 2023.
*
* 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 io.cdap.plugin.actions;

import io.cdap.e2e.pages.actions.CdfPipelineRunAction;
import io.cdap.e2e.pages.locators.CdfPipelineRunLocators;
import io.cdap.e2e.utils.*;
import io.cdap.plugin.locators.ReplicationLocators;
import io.cdap.plugin.utils.OracleClient;
import io.cdap.plugin.utils.ValidationHelper;
import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
import stepsdesign.BeforeActions;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class ReplicationActions {
private static String parentWindow = StringUtils.EMPTY;
private static final String projectId = PluginPropertyUtils.pluginProp("projectId");
private static final String database = PluginPropertyUtils.pluginProp("database");
public static String tableName = PluginPropertyUtils.pluginProp("sourceTable");
public static String schemaName = PluginPropertyUtils.pluginProp("schema");
public static String datatypeColumnNames = PluginPropertyUtils.pluginProp("datatypeColumnNames");
public static String datatypeValues = PluginPropertyUtils.pluginProp("datatypeValuesForInsertOperation");
public static String deleteCondition = PluginPropertyUtils.pluginProp("deleteRowCondition");
public static String updateCondition = PluginPropertyUtils.pluginProp("updateRowCondition");
public static String updatedValue = PluginPropertyUtils.pluginProp("updatedRow");

static {
SeleniumHelper.getPropertiesLocators(ReplicationLocators.class);
}
public static void clickNextButton() throws InterruptedException {
TimeUnit time = TimeUnit.SECONDS;
time.sleep(1);
Comment on lines +62 to +63
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Why is sleep required here?
  • Combine these two statements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It helps view what's happening in ui, otherwise it shifts across pages so quickly.

ElementHelper.clickOnElement(ReplicationLocators.next);
}
public static void clickOnOraclePlugin() {
ElementHelper.clickOnElement(ReplicationLocators.oraclePlugin);
}

public static void selectTable(String tableName) {
WaitHelper.waitForElementToBeDisplayed(ReplicationLocators.selectTable(tableName));
AssertionHelper.verifyElementDisplayed(ReplicationLocators.selectTable(tableName));
ElementHelper.clickOnElement(ReplicationLocators.selectTable(tableName));
}

public static void deployPipeline() {
ElementHelper.clickOnElement(ReplicationLocators.deployPipeline);
}

public static void startPipeline() {
ElementHelper.clickIfDisplayed(ReplicationLocators.start, ConstantsUtil.DEFAULT_TIMEOUT_SECONDS);
}

public static void runThePipeline() {
startPipeline();
WaitHelper.waitForElementToBeDisplayed(ReplicationLocators.running);
}

public static void openAdvanceLogs() {
ReplicationLocators.logs.click();
parentWindow = SeleniumDriver.getDriver().getWindowHandle();
ArrayList<String> tabs = new ArrayList(SeleniumDriver.getDriver().getWindowHandles());
SeleniumDriver.getDriver().switchTo().window(tabs.get(tabs.indexOf(parentWindow) + 1));
ReplicationLocators.advancedLogs.click();
}

public static void captureRawLog() {
//Capturing raw logs.
try {
String rawLogs = getRawLogs();
String logsSeparatorMessage = ConstantsUtil.LOGS_SEPARATOR_MESSAGE
.replace("MESSAGE", "DEPLOYED PIPELINE RUNTIME LOGS");
BeforeActions.scenario.write(rawLogs);
CdfPipelineRunAction.writeRawLogsToFile(BeforeActions.file, logsSeparatorMessage, rawLogs);
} catch (Exception e) {
BeforeActions.scenario.write("Exception in capturing logs : " + e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the error ignored?

}
}

public static String getRawLogs() {
CdfPipelineRunAction.viewRawLogs();
ArrayList<String> tabs = new ArrayList(SeleniumDriver.getDriver().getWindowHandles());
PageHelper.switchToWindow(tabs.indexOf(parentWindow) + 2);
String logs = CdfPipelineRunLocators.logsTextbox.getText();
Assert.assertNotNull(logs);
PageHelper.closeCurrentWindow();
return logs;
}

public static void waitTillPipelineIsRunningAndCheckForErrors() throws InterruptedException {
//wait for datastream to startup
int defaultTimeout = Integer.parseInt(PluginPropertyUtils.pluginProp("datastream.timeout"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename it to more general term like pipeline initialization time instead of datastream.timeout

TimeUnit time = TimeUnit.SECONDS;
time.sleep(defaultTimeout);
// Checking if an error message is displayed.
Assert.assertFalse(ElementHelper.isElementDisplayed(ReplicationLocators.error));
}

public static void closeTheLogsAndClickOnStopButton() {
//As the logs get opened in a new window in this plugin so after closing them we have to switch to parent window.
SeleniumDriver.getDriver().switchTo().window(parentWindow);
//Stopping the pipeline
ElementHelper.clickOnElement(ReplicationLocators.stop);
WaitHelper.waitForElementToBeDisplayed(ReplicationLocators.stopped);
}
public static void verifyTargetBigQueryRecordMatchesExpectedOracleRecord()
throws IOException, InterruptedException, SQLException, ClassNotFoundException {
// Checking if an error message is displayed.
Assert.assertFalse(ElementHelper.isElementDisplayed(ReplicationLocators.error));

List<Map<String, Object>> sourceOracleRecords = OracleClient.getOracleRecordsAsMap(tableName, schemaName);
List<Map<String, Object>> targetBigQueryRecords = ValidationHelper.getBigQueryRecordsAsMap(projectId, database, tableName); //+ "_v1`"
ValidationHelper.validateRecords(sourceOracleRecords, targetBigQueryRecords);
}

public static void insertRecordAndWait()
throws IOException, InterruptedException, SQLException, ClassNotFoundException { //JCoException,
OracleClient.insertRow(tableName,schemaName, datatypeColumnNames,datatypeValues);
OracleClient.forceFlushCDC();
ValidationHelper.waitForFlush();
}

public static void deleteRecordAndWait() throws SQLException, ClassNotFoundException, IOException, InterruptedException {
OracleClient.deleteRow(tableName,schemaName, deleteCondition);
OracleClient.forceFlushCDC();
ValidationHelper.waitForFlush();
}

public static void updateRecordAndWait() throws SQLException, ClassNotFoundException, IOException, InterruptedException {
OracleClient.updateRow(tableName,schemaName, updateCondition, updatedValue );
OracleClient.forceFlushCDC();
ValidationHelper.waitForFlush();
}
}
17 changes: 17 additions & 0 deletions src/e2e-test/java/io.cdap.plugin/actions/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023.
*
* 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 io.cdap.plugin.actions;