-
Notifications
You must be signed in to change notification settings - Fork 46
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
CVV_COLUMNS table integration test #16
Open
dmorokov
wants to merge
1
commit into
dev
Choose a base branch
from
dev-cvv-columns-test
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestBase.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
...tion-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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 com.google.edwmigration.dumper.base; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
import com.google.common.collect.LinkedHashMultiset; | ||
import com.google.common.collect.Multiset; | ||
import com.google.common.collect.Multisets; | ||
import org.junit.Assert; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** Base class with general values for all TestNG test suites */ | ||
public abstract class TestBase { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class); | ||
|
||
/** | ||
* @param dbMultiset List of extracted from DB items. | ||
* @param csvMultiset List of uploaded from Avro items. | ||
* <p>This custom method exists due to Java out of heap memory error in | ||
* Truth.assertThat(dbMultiset).containsExactlyElementsIn(csvMultiset); It probably happens | ||
* because .containsExactlyElementsIn() tries to print out not only the diff, let's say 1 | ||
* element, but entire collections. | ||
*/ | ||
public static void assertDbCsvDataEqual( | ||
LinkedHashMultiset<?> dbMultiset, LinkedHashMultiset<?> csvMultiset) { | ||
Multiset<?> dbReducedOnCsv = Multisets.difference(dbMultiset, csvMultiset); | ||
Multiset<?> csvReducedOnDb = Multisets.difference(csvMultiset, dbMultiset); | ||
|
||
String dbDiffEntries = | ||
dbReducedOnCsv.stream().map(e -> e.toString() + "\n").collect(toList()).toString(); | ||
String csvDiffEntries = | ||
csvReducedOnDb.stream().map(e -> e.toString() + "\n").collect(toList()).toString(); | ||
|
||
if (dbReducedOnCsv.isEmpty() && csvReducedOnDb.isEmpty()) { | ||
LOGGER.info("DB view and CSV file are equal"); | ||
} else if (!dbReducedOnCsv.isEmpty() && !csvReducedOnDb.isEmpty()) { | ||
Assert.fail( | ||
format( | ||
"DB view and CSV file have mutually exclusive row(s)%n" | ||
+ "DB view has %d different row(s): %s%n" | ||
+ "CSV file has %d different row(s): %s", | ||
dbReducedOnCsv.size(), dbDiffEntries, csvReducedOnDb.size(), csvDiffEntries)); | ||
} else if (!dbReducedOnCsv.isEmpty()) { | ||
Assert.fail(format("DB view has %d extra row(s):%n%s", dbReducedOnCsv.size(), dbDiffEntries)); | ||
} else if (!csvReducedOnDb.isEmpty()) { | ||
Assert.fail( | ||
format("CSV file has %d extra row(s):%n%s", csvReducedOnDb.size(), csvDiffEntries)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...tion-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/jdbc/JdbcUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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 com.google.edwmigration.dumper.jdbc; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A helper class for checking Null values returned by executing SELECT request against a database. | ||
*/ | ||
public final class JdbcUtil { | ||
|
||
private JdbcUtil() {} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param column Database column name. | ||
* @return String or an empty string if null. | ||
*/ | ||
public static String getStringNotNull(ResultSet rs, String column) throws SQLException { | ||
String string = rs.getString(column); | ||
return rs.wasNull() ? "" : string; | ||
} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param columnIndex Database column index. | ||
* @return String or an empty string if null. | ||
*/ | ||
public static String getStringNotNull(ResultSet rs, int columnIndex) throws SQLException { | ||
String string = rs.getString(columnIndex); | ||
return rs.wasNull() ? "" : string; | ||
} | ||
|
||
/** | ||
* @param rsmd Metadata of the executed SQL query. | ||
* @return List of column names. | ||
* @throws SQLException | ||
*/ | ||
public static List<String> getDbColumnNames(ResultSetMetaData rsmd) throws SQLException { | ||
List<String> columnNames = new ArrayList<>(); | ||
for (int i = 1; i <= rsmd.getColumnCount(); i++) { | ||
columnNames.add(rsmd.getColumnName(i)); | ||
} | ||
return columnNames; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
dumper-integration-tests/redshift-tests/src/main/resources/sql/svv_columns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- Copyright 2022 Google LLC | ||
-- | ||
-- 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. | ||
|
||
SELECT * FROM SVV_COLUMNS; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We have typically set dependency versions globally using a Gradle build convention. Can we please follow that convention for these submodule(s)?
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.
As of right now, this test automation framework isn't included as a submodule into the main project.
There are several reasons for that:
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.
(2) and (3) are review comments elsewhere; our convention is to use commons-csv and junit.
(4) should be a review comment; we would like this code to follow the conventions of the repository.
(5) Gradle would normally represent an integration test as a TestSet, and this practice is sufficiently standard that it is now part of Gradle core.