-
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
546 additions
and
170 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.
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
/* | ||
* 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 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 dbList List of extracted from DB items | ||
* @param csvList List of uploaded from Avro items | ||
*/ | ||
public static void assertListsEqual( | ||
final LinkedHashMultiset dbList, final LinkedHashMultiset csvList) { | ||
String dbListForLogs = lineSeparator() + Joiner.on("").join(dbList); | ||
String csvListForLogs = lineSeparator() + Joiner.on("").join(csvList); | ||
|
||
if (dbList.isEmpty() && csvList.isEmpty()) { | ||
LOGGER.info("DB view and CSV file are equal"); | ||
} else if (!dbList.isEmpty() && !csvList.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", | ||
dbList.size(), dbListForLogs, csvList.size(), csvListForLogs)); | ||
} else if (!dbList.isEmpty()) { | ||
Assert.fail(format("DB view has %d extra row(s):%n%s", dbList.size(), dbListForLogs)); | ||
} else if (!csvList.isEmpty()) { | ||
Assert.fail(format("CSV file has %d extra row(s):%n%s", csvList.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); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...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,105 @@ | ||
/* | ||
* 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 { | ||
int intValue = rs.getInt(column); | ||
return rs.wasNull() ? 0 : intValue; | ||
} | ||
|
||
/** | ||
* @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 { | ||
long longValue = rs.getLong(column); | ||
return rs.wasNull() ? 0L : longValue; | ||
} | ||
|
||
/** | ||
* @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 { | ||
double doubleValue = rs.getDouble(column); | ||
return rs.wasNull() ? 0.0 : doubleValue; | ||
} | ||
|
||
/** | ||
* @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.