-
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. Added SvvColumnsRow POJO object 5. Added CsvUtil and methods 6. Added Gradle reporting plugin
- Loading branch information
Showing
11 changed files
with
552 additions
and
180 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
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.
63 changes: 63 additions & 0 deletions
63
...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,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.base; | ||
|
||
import static java.lang.String.format; | ||
import static java.lang.System.lineSeparator; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.collect.LinkedHashMultiset; | ||
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 | ||
*/ | ||
public static void assertMultisetsEqual( | ||
LinkedHashMultiset dbMultiset, LinkedHashMultiset csvMultiset) { | ||
LinkedHashMultiset dbMultisetCopy = LinkedHashMultiset.create(dbMultiset); | ||
csvMultiset.forEach(dbMultiset::remove); | ||
dbMultisetCopy.forEach(csvMultiset::remove); | ||
|
||
String dbListForLogs = lineSeparator() + Joiner.on("").join(dbMultiset); | ||
String csvListForLogs = lineSeparator() + Joiner.on("").join(csvMultiset); | ||
|
||
if (dbMultiset.isEmpty() && csvMultiset.isEmpty()) { | ||
LOGGER.info("DB view and CSV file are equal"); | ||
} else if (!dbMultiset.isEmpty() && !csvMultiset.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", | ||
dbMultiset.size(), dbListForLogs, csvMultiset.size(), csvListForLogs)); | ||
} else if (!dbMultiset.isEmpty()) { | ||
Assert.fail(format("DB view has %d extra row(s):%n%s", dbMultiset.size(), dbListForLogs)); | ||
} else if (!csvMultiset.isEmpty()) { | ||
Assert.fail(format("CSV file has %d extra row(s):%n%s", csvMultiset.size(), csvListForLogs)); | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...ration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/csv/CsvUtil.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,39 @@ | ||
/* | ||
* 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.csv; | ||
|
||
import static com.google.edwmigration.dumper.base.TestConstants.TRAILING_SPACES_REGEX; | ||
import static java.lang.Integer.parseInt; | ||
|
||
/** A helper class for reading and extracting data from CSV files. */ | ||
public final class CsvUtil { | ||
|
||
private CsvUtil() {} | ||
|
||
/** | ||
* @return String or an empty string if null. | ||
*/ | ||
public static String getStringNotNull(String value) { | ||
return value == null ? "" : TRAILING_SPACES_REGEX.matcher(value).replaceFirst(""); | ||
} | ||
|
||
/** | ||
* @return int or 0 if "". | ||
*/ | ||
public static int getIntNotNull(String value) { | ||
return getStringNotNull(value).equals("") ? 0 : parseInt(value); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...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,102 @@ | ||
/* | ||
* 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 static com.google.edwmigration.dumper.base.TestConstants.TRAILING_SPACES_REGEX; | ||
|
||
import java.math.BigDecimal; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Timestamp; | ||
import java.time.ZonedDateTime; | ||
import java.util.Calendar; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* 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() ? "" : TRAILING_SPACES_REGEX.matcher(string).replaceFirst(""); | ||
} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param column Database column name. | ||
* @return int or 0 if null. | ||
*/ | ||
public static int getIntNotNull(ResultSet rs, String column) throws SQLException { | ||
return rs.getInt(column); | ||
} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param column Database column name. | ||
* @return long or 0L if null. | ||
*/ | ||
public static long getLongNotNull(ResultSet rs, String column) throws SQLException { | ||
return rs.getLong(column); | ||
} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param column Database column name. | ||
* @return byte[] or empty byte[] if null. | ||
*/ | ||
public static byte[] getBytesNotNull(ResultSet rs, String column) throws SQLException { | ||
try { | ||
byte[] bytesValue = rs.getBytes(column); | ||
return rs.wasNull() ? new byte[0] : bytesValue; | ||
} catch (SQLException e) { | ||
BigDecimal bigDecimal = rs.getBigDecimal(column); | ||
return rs.wasNull() ? new byte[0] : bigDecimal.toBigInteger().toByteArray(); | ||
} | ||
} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param column Database column name. | ||
* @return double or 0.0 if null. | ||
*/ | ||
public static double getDoubleNotNull(ResultSet rs, String column) throws SQLException { | ||
return rs.getDouble(column); | ||
} | ||
|
||
/** | ||
* @param rs A row with SELECT results. | ||
* @param column Database column name. | ||
* @return long or 0L if null. | ||
*/ | ||
public static long getTimestampNotNull(ResultSet rs, String column) throws SQLException { | ||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
Timestamp timestamp = rs.getTimestamp(column, cal); | ||
if (rs.wasNull()) { | ||
return 0L; | ||
} | ||
return Timestamp.from( | ||
ZonedDateTime.of(timestamp.toLocalDateTime(), cal.getTimeZone().toZoneId()).toInstant()) | ||
.getTime(); | ||
} | ||
} |
Oops, something went wrong.