Skip to content

Commit 42a0b6e

Browse files
committed
CVV_COLUMNS table integration test
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
1 parent a99dd62 commit 42a0b6e

File tree

13 files changed

+300
-193
lines changed

13 files changed

+300
-193
lines changed

dumper-integration-tests/gradlew

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../gradlew
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../gradlew.bat
Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
* Copyright 2013-2021 CompilerWorks
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
117
buildscript {
218
repositories {
319
mavenCentral()
420
}
5-
dependencies {
6-
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
7-
}
821
}
922

1023
plugins {
1124
id 'java'
12-
id "com.google.protobuf" version "0.8.18"
25+
id 'com.adarshr.test-logger' version '3.0.0'
1326
}
1427

1528
sourceCompatibility = 1.8
@@ -22,28 +35,32 @@ repositories {
2235
}
2336

2437
dependencies {
25-
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
38+
implementation 'org.codehaus.groovy:groovy-all:3.0.10'
39+
implementation 'com.google.guava:guava:31.1-jre'
2640
implementation 'org.testng:testng:7.5'
2741
implementation 'org.slf4j:slf4j-api:2.0.0-alpha5'
2842
implementation 'org.slf4j:slf4j-jdk14:2.0.0-alpha5'
29-
implementation 'com.amazon.redshift:redshift-jdbc42:2.1.0.6'
3043
implementation 'commons-io:commons-io:2.11.0'
31-
implementation 'org.apache.commons:commons-collections4:4.4'
32-
implementation 'com.google.guava:guava:31.0.1-jre'
3344
implementation 'com.opencsv:opencsv:5.6'
34-
implementation 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
35-
implementation 'com.google.protobuf:protobuf-java:3.20.1'
45+
implementation 'com.google.truth:truth:1.1.3'
46+
implementation 'com.google.truth.extensions:truth-java8-extension:1.1.3'
47+
48+
implementation 'com.amazon.redshift:redshift-jdbc42:2.1.0.7'
49+
annotationProcessor 'com.google.auto.value:auto-value:1.9'
50+
compileOnly 'com.google.auto.value:auto-value-annotations:1.9'
3651
}
3752

3853
test {
54+
ignoreFailures = true
55+
3956
useTestNG {
4057
preserveOrder true
4158
systemProperty 'java.util.logging.config.file', 'src/main/resources/logging.properties'
4259
}
43-
}
4460

45-
protobuf {
46-
protoc {
47-
artifact = 'com.google.protobuf:protoc:3.20.1'
48-
}
61+
def envFiles = ['EXPORT_PATH']
62+
envFiles.each { if (System.env[it] != null) inputs.dir(System.env[it])}
63+
64+
def envProperties = ['DB_URL', 'USERNAME', 'PASSWORD']
65+
envProperties.each { if (System.env[it] != null) inputs.property it, System.env[it]}
4966
}

dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestBase.java

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.edwmigration.dumper.base;
17+
18+
import static java.lang.String.format;
19+
import static java.lang.System.lineSeparator;
20+
21+
import com.google.common.base.Joiner;
22+
import com.google.common.collect.LinkedHashMultiset;
23+
import com.opencsv.CSVParser;
24+
import com.opencsv.CSVParserBuilder;
25+
import org.junit.Assert;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
29+
/** Base class with general values for all TestNG test suites */
30+
public abstract class TestBase {
31+
32+
public static final CSVParser CSV_PARSER = new CSVParserBuilder().withEscapeChar('\0').build();
33+
private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class);
34+
35+
/**
36+
* @param dbMultiset List of extracted from DB items.
37+
* @param csvMultiset List of uploaded from Avro items.
38+
*
39+
* This custom method exists due to Java out of heap memory error in
40+
* Truth.assertThat(dbMultiset).containsExactlyElementsIn(csvMultiset);
41+
* It probably happens because .containsExactlyElementsIn() tries to
42+
* print out not only the diff, let's say 1 element, but entire collections.
43+
*/
44+
public static void assertDbCsvDataEqual(
45+
LinkedHashMultiset<?> dbMultiset, LinkedHashMultiset<?> csvMultiset) {
46+
LinkedHashMultiset<?> dbMultisetCopy = LinkedHashMultiset.create(dbMultiset);
47+
csvMultiset.forEach(dbMultiset::remove);
48+
dbMultisetCopy.forEach(csvMultiset::remove);
49+
50+
String dbListForLogs = lineSeparator() + Joiner.on("").join(dbMultiset);
51+
String csvListForLogs = lineSeparator() + Joiner.on("").join(csvMultiset);
52+
53+
if (dbMultiset.isEmpty() && csvMultiset.isEmpty()) {
54+
LOGGER.info("DB view and CSV file are equal");
55+
} else if (!dbMultiset.isEmpty() && !csvMultiset.isEmpty()) {
56+
Assert.fail(
57+
format(
58+
"DB view and CSV file have mutually exclusive row(s)%n"
59+
+ "DB view has %d different row(s): %s%n"
60+
+ "CSV file has %d different row(s): %s",
61+
dbMultiset.size(), dbListForLogs, csvMultiset.size(), csvListForLogs));
62+
} else if (!dbMultiset.isEmpty()) {
63+
Assert.fail(format("DB view has %d extra row(s):%n%s", dbMultiset.size(), dbListForLogs));
64+
} else if (!csvMultiset.isEmpty()) {
65+
Assert.fail(format("CSV file has %d extra row(s):%n%s", csvMultiset.size(), csvListForLogs));
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
* Copyright 2022 Google LLC
3-
* Copyright 2013-2021 CompilerWorks
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");
65
* you may not use this file except in compliance with the License.
@@ -14,24 +13,20 @@
1413
* See the License for the specific language governing permissions and
1514
* limitations under the License.
1615
*/
17-
package com.google.base;
16+
package com.google.edwmigration.dumper.base;
1817

1918
import static java.lang.System.getenv;
2019

21-
import java.util.regex.Pattern;
22-
23-
/**
24-
* Stores constants common among all tests.
25-
*/
20+
/** Stores constants common among all tests. */
2621
public final class TestConstants {
2722

2823
public static final String URL_DB = getenv("DB_URL");
2924
public static final String USERNAME_DB = getenv("USERNAME");
3025
public static final String PASSWORD_DB = getenv("PASSWORD");
3126

32-
public static final String ET_OUTPUT_PATH = getenv("EXPORT_PATH");
33-
public static final Pattern TRAILING_SPACES_REGEX = Pattern.compile("\\s+$");
27+
public static final String EXPORTED_FILES_BASE_PATH = getenv("EXPORT_PATH");
28+
29+
public static final String SQL_REQUESTS_BASE_PATH = "sql/";
3430

35-
private TestConstants() {
36-
}
31+
private TestConstants() {}
3732
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.edwmigration.dumper.jdbc;
17+
18+
import java.sql.ResultSet;
19+
import java.sql.ResultSetMetaData;
20+
import java.sql.SQLException;
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
/**
25+
* A helper class for checking Null values returned by executing SELECT request against a database.
26+
*/
27+
public final class JdbcUtil {
28+
29+
private JdbcUtil() {}
30+
31+
/**
32+
* @param rs A row with SELECT results.
33+
* @param column Database column name.
34+
* @return String or an empty string if null.
35+
*/
36+
public static String getStringNotNull(ResultSet rs, String column) throws SQLException {
37+
String string = rs.getString(column);
38+
return rs.wasNull() ? "" : string;
39+
}
40+
41+
/**
42+
* @param rs A row with SELECT results.
43+
* @param columnIndex Database column index.
44+
* @return String or an empty string if null.
45+
*/
46+
public static String getStringNotNull(ResultSet rs, int columnIndex) throws SQLException {
47+
String string = rs.getString(columnIndex);
48+
return rs.wasNull() ? "" : string;
49+
}
50+
51+
/**
52+
* @param rsmd Metadata of the executed SQL query.
53+
* @return List of column names.
54+
* @throws SQLException
55+
*/
56+
public static List<String> getDbColumnNames(ResultSetMetaData rsmd) throws SQLException {
57+
List<String> columnNames = new ArrayList<>();
58+
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
59+
columnNames.add(rsmd.getColumnName(i));
60+
}
61+
return columnNames;
62+
}
63+
}

dumper-integration-tests/redshift-tests/src/main/java/com/google/sql/SqlUtil.java renamed to dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/sql/SqlUtil.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
* Copyright 2022 Google LLC
3-
* Copyright 2013-2021 CompilerWorks
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");
65
* you may not use this file except in compliance with the License.
@@ -14,16 +13,14 @@
1413
* See the License for the specific language governing permissions and
1514
* limitations under the License.
1615
*/
17-
package com.google.sql;
16+
package com.google.edwmigration.dumper.sql;
1817

19-
import static com.google.base.TestConstants.URL_DB;
18+
import static com.google.edwmigration.dumper.base.TestConstants.URL_DB;
2019
import static java.lang.String.format;
21-
import static org.apache.commons.io.FileUtils.readFileToString;
20+
import static java.nio.charset.StandardCharsets.UTF_8;
2221

23-
import java.io.File;
22+
import com.google.common.io.Resources;
2423
import java.io.IOException;
25-
import java.io.UncheckedIOException;
26-
import java.nio.charset.StandardCharsets;
2724
import java.sql.Connection;
2825
import java.sql.DriverManager;
2926
import java.sql.PreparedStatement;
@@ -32,26 +29,19 @@
3229
import org.slf4j.Logger;
3330
import org.slf4j.LoggerFactory;
3431

35-
/**
36-
* A helper class for reading .sql files.
37-
*/
32+
/** A helper class for reading .sql files. */
3833
public final class SqlUtil {
3934

4035
private static final Logger LOGGER = LoggerFactory.getLogger(SqlUtil.class);
4136

42-
private SqlUtil() {
43-
}
37+
private SqlUtil() {}
4438

4539
/**
4640
* @param sqlPath Path to an .sql file.
4741
* @return File contents, never null.
4842
*/
49-
public static String getSql(String sqlPath) {
50-
try {
51-
return readFileToString(new File(sqlPath), StandardCharsets.UTF_8);
52-
} catch (IOException exception) {
53-
throw new UncheckedIOException(format("Error while reading sql file %s", sqlPath), exception);
54-
}
43+
public static String getSql(String sqlPath) throws IOException {
44+
return Resources.toString(Resources.getResource(sqlPath), UTF_8);
5545
}
5646

5747
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright 2022 Google LLC
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
15+
SELECT * FROM SVV_COLUMNS;

0 commit comments

Comments
 (0)