-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Added JdbcUtils and methods 2. Added svv_columns.sql for retrieving table's data 3. Added SvvColumnsTest test 4. Removed CsvUtil and methods 5. Added Gradle reporting plugin 6. Setting dumper-integration-tests as a root independent Gradle project 7. Added required EnvVars to build.gradle
- Loading branch information
Showing
13 changed files
with
303 additions
and
193 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../gradlew |
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 @@ | ||
../gradlew.bat |
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.
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
/* | ||
* 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 com.opencsv.CSVParser; | ||
import com.opencsv.CSVParserBuilder; | ||
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 { | ||
|
||
public static final CSVParser CSV_PARSER = new CSVParserBuilder().withEscapeChar('\0').build(); | ||
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.