From 03e12dfffe5a524a3d5cbb6a52cdd989cf2bf978 Mon Sep 17 00:00:00 2001 From: Danila Morokov Date: Wed, 25 May 2022 13:50:29 +0000 Subject: [PATCH] Integration test for CVV_COLUMNS table Kokoro build script invokes Dumper and Dumper extracts metadata to a local folder on a build worker, the path to a folder will be stored in EXPORT_PATH env var. After that, integration tests will be run and pointed to EXPORT_PATH to read CSV files from there. The logic of integration tests is to make an SQL request to DB, extract the data and save them to memory, then read CSV files, deserialize it, and then compare with the extraction from DB that the both data sets are field-to-field equal. --- .../redshift-tests/build.gradle | 53 +++++++---- .../main/java/com/google/base/TestBase.java | 59 ------------ .../edwmigration/dumper/base/TestBase.java | 67 ++++++++++++++ .../dumper}/base/TestConstants.java | 17 ++-- .../edwmigration/dumper/jdbc/JdbcUtil.java | 63 +++++++++++++ .../dumper}/sql/SqlUtil.java | 26 ++---- .../src/main/resources/sql/svv_columns.sql | 15 ++++ .../dumper/integration/SvvColumnsTest.java | 89 +++++++++++++++++++ .../com/google/integration/RedshiftTest.java | 80 ----------------- dumper/settings.gradle | 10 --- settings.gradle | 3 +- 11 files changed, 284 insertions(+), 198 deletions(-) delete mode 100644 dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestBase.java create mode 100644 dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestBase.java rename dumper-integration-tests/redshift-tests/src/main/java/com/google/{ => edwmigration/dumper}/base/TestConstants.java (72%) create mode 100644 dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/jdbc/JdbcUtil.java rename dumper-integration-tests/redshift-tests/src/main/java/com/google/{ => edwmigration/dumper}/sql/SqlUtil.java (77%) create mode 100644 dumper-integration-tests/redshift-tests/src/main/resources/sql/svv_columns.sql create mode 100644 dumper-integration-tests/redshift-tests/src/test/java/com/google/edwmigration/dumper/integration/SvvColumnsTest.java delete mode 100644 dumper-integration-tests/redshift-tests/src/test/java/com/google/integration/RedshiftTest.java delete mode 100644 dumper/settings.gradle diff --git a/dumper-integration-tests/redshift-tests/build.gradle b/dumper-integration-tests/redshift-tests/build.gradle index 4f3dd5975..d15faf866 100644 --- a/dumper-integration-tests/redshift-tests/build.gradle +++ b/dumper-integration-tests/redshift-tests/build.gradle @@ -1,15 +1,28 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2013-2021 CompilerWorks + * + * 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. + */ buildscript { repositories { mavenCentral() } - dependencies { - classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18' - } } plugins { id 'java' - id "com.google.protobuf" version "0.8.18" + id 'com.adarshr.test-logger' version '3.0.0' } sourceCompatibility = 1.8 @@ -22,28 +35,30 @@ repositories { } dependencies { - implementation 'org.codehaus.groovy:groovy-all:3.0.5' - implementation 'org.testng:testng:7.5' + implementation 'org.codehaus.groovy:groovy-all:3.0.10' + implementation 'com.google.guava:guava:31.1-jre' + implementation 'junit:junit:4.13.2' implementation 'org.slf4j:slf4j-api:2.0.0-alpha5' implementation 'org.slf4j:slf4j-jdk14:2.0.0-alpha5' - implementation 'com.amazon.redshift:redshift-jdbc42:2.1.0.6' implementation 'commons-io:commons-io:2.11.0' - implementation 'org.apache.commons:commons-collections4:4.4' - implementation 'com.google.guava:guava:31.0.1-jre' - implementation 'com.opencsv:opencsv:5.6' - implementation 'com.google.protobuf:protobuf-gradle-plugin:0.8.18' - implementation 'com.google.protobuf:protobuf-java:3.20.1' + implementation 'org.apache.commons:commons-csv:1.9.0' + implementation 'com.google.truth:truth:1.1.3' + implementation 'com.google.truth.extensions:truth-java8-extension:1.1.3' + implementation 'com.amazon.redshift:redshift-jdbc42:2.1.0.7' + annotationProcessor 'com.google.auto.value:auto-value:1.9' + compileOnly 'com.google.auto.value:auto-value-annotations:1.9' } test { - useTestNG { - preserveOrder true + ignoreFailures = true + + useJUnit() { systemProperty 'java.util.logging.config.file', 'src/main/resources/logging.properties' } -} -protobuf { - protoc { - artifact = 'com.google.protobuf:protoc:3.20.1' - } + def envFiles = ['EXPORT_PATH'] + envFiles.each { if (System.env[it] != null) inputs.dir(System.env[it]) } + + def envProperties = ['DB_URL', 'USERNAME', 'PASSWORD'] + envProperties.each { if (System.env[it] != null) inputs.property it, System.env[it] } } \ No newline at end of file diff --git a/dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestBase.java b/dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestBase.java deleted file mode 100644 index 201a05f51..000000000 --- a/dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestBase.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2022 Google LLC - * Copyright 2013-2021 CompilerWorks - * - * 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.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 Junit test suites - */ -public abstract class TestBase { - - private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class); - - /** - * @param dbList List of extracted from DB items - * @param outputList List of uploaded from Avro items - */ - public static void assertListsEqual(final LinkedHashMultiset dbList, - final LinkedHashMultiset outputList) { - String dbListOutputForLogs = lineSeparator() + Joiner.on("").join(dbList); - String outputListForLogs = lineSeparator() + Joiner.on("").join(outputList); - - if (dbList.isEmpty() && outputList.isEmpty()) { - LOGGER.info("DB view and Output file are equal"); - } else if (!dbList.isEmpty() && !outputList.isEmpty()) { - Assert.fail(format("DB view and Output file have mutually exclusive row(s)%n" - + "DB view '%s' has %d different row(s): %s%n" - + "Output file %s has %d different row(s): %s", dbList.size(), dbListOutputForLogs, - outputList.size(), outputListForLogs)); - } else if (!dbList.isEmpty()) { - Assert.fail( - format("DB view '%s' has %d extra row(s):%n%s", dbList.size(), dbListOutputForLogs)); - } else if (!outputList.isEmpty()) { - Assert.fail( - format("Output file %s has %d extra row(s):%n%s", outputList.size(), outputListForLogs)); - } - } -} diff --git a/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestBase.java b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestBase.java new file mode 100644 index 000000000..f46f8ed23 --- /dev/null +++ b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestBase.java @@ -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. + *

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)); + } + } +} diff --git a/dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestConstants.java b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestConstants.java similarity index 72% rename from dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestConstants.java rename to dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestConstants.java index 16d966dfd..4f3709455 100644 --- a/dumper-integration-tests/redshift-tests/src/main/java/com/google/base/TestConstants.java +++ b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/base/TestConstants.java @@ -1,6 +1,5 @@ /* * Copyright 2022 Google LLC - * Copyright 2013-2021 CompilerWorks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.base; +package com.google.edwmigration.dumper.base; import static java.lang.System.getenv; -import java.util.regex.Pattern; - -/** - * Stores constants common among all tests. - */ +/** Stores constants common among all tests. */ public final class TestConstants { public static final String URL_DB = getenv("DB_URL"); public static final String USERNAME_DB = getenv("USERNAME"); public static final String PASSWORD_DB = getenv("PASSWORD"); - public static final String ET_OUTPUT_PATH = getenv("EXPORT_PATH"); - public static final Pattern TRAILING_SPACES_REGEX = Pattern.compile("\\s+$"); + public static final String EXPORTED_FILES_BASE_PATH = getenv("EXPORT_PATH"); + + public static final String SQL_REQUESTS_BASE_PATH = "sql/"; - private TestConstants() { - } + private TestConstants() {} } diff --git a/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/jdbc/JdbcUtil.java b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/jdbc/JdbcUtil.java new file mode 100644 index 000000000..b051e0a6b --- /dev/null +++ b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/jdbc/JdbcUtil.java @@ -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 getDbColumnNames(ResultSetMetaData rsmd) throws SQLException { + List columnNames = new ArrayList<>(); + for (int i = 1; i <= rsmd.getColumnCount(); i++) { + columnNames.add(rsmd.getColumnName(i)); + } + return columnNames; + } +} diff --git a/dumper-integration-tests/redshift-tests/src/main/java/com/google/sql/SqlUtil.java b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/sql/SqlUtil.java similarity index 77% rename from dumper-integration-tests/redshift-tests/src/main/java/com/google/sql/SqlUtil.java rename to dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/sql/SqlUtil.java index fdc8daae6..36b658f91 100644 --- a/dumper-integration-tests/redshift-tests/src/main/java/com/google/sql/SqlUtil.java +++ b/dumper-integration-tests/redshift-tests/src/main/java/com/google/edwmigration/dumper/sql/SqlUtil.java @@ -1,6 +1,5 @@ /* * Copyright 2022 Google LLC - * Copyright 2013-2021 CompilerWorks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.sql; +package com.google.edwmigration.dumper.sql; -import static com.google.base.TestConstants.URL_DB; +import static com.google.edwmigration.dumper.base.TestConstants.URL_DB; import static java.lang.String.format; -import static org.apache.commons.io.FileUtils.readFileToString; +import static java.nio.charset.StandardCharsets.UTF_8; -import java.io.File; +import com.google.common.io.Resources; import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -32,26 +29,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * A helper class for reading .sql files. - */ +/** A helper class for reading .sql files. */ public final class SqlUtil { private static final Logger LOGGER = LoggerFactory.getLogger(SqlUtil.class); - private SqlUtil() { - } + private SqlUtil() {} /** * @param sqlPath Path to an .sql file. * @return File contents, never null. */ - public static String getSql(String sqlPath) { - try { - return readFileToString(new File(sqlPath), StandardCharsets.UTF_8); - } catch (IOException exception) { - throw new UncheckedIOException(format("Error while reading sql file %s", sqlPath), exception); - } + public static String getSql(String sqlPath) throws IOException { + return Resources.toString(Resources.getResource(sqlPath), UTF_8); } /** diff --git a/dumper-integration-tests/redshift-tests/src/main/resources/sql/svv_columns.sql b/dumper-integration-tests/redshift-tests/src/main/resources/sql/svv_columns.sql new file mode 100644 index 000000000..91ee61970 --- /dev/null +++ b/dumper-integration-tests/redshift-tests/src/main/resources/sql/svv_columns.sql @@ -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; \ No newline at end of file diff --git a/dumper-integration-tests/redshift-tests/src/test/java/com/google/edwmigration/dumper/integration/SvvColumnsTest.java b/dumper-integration-tests/redshift-tests/src/test/java/com/google/edwmigration/dumper/integration/SvvColumnsTest.java new file mode 100644 index 000000000..a921a51dc --- /dev/null +++ b/dumper-integration-tests/redshift-tests/src/test/java/com/google/edwmigration/dumper/integration/SvvColumnsTest.java @@ -0,0 +1,89 @@ +/* + * 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.integration; + +import static com.google.common.collect.LinkedHashMultiset.create; +import static com.google.common.truth.Truth.assertThat; +import static com.google.edwmigration.dumper.base.TestBase.assertDbCsvDataEqual; +import static com.google.edwmigration.dumper.base.TestConstants.EXPORTED_FILES_BASE_PATH; +import static com.google.edwmigration.dumper.base.TestConstants.PASSWORD_DB; +import static com.google.edwmigration.dumper.base.TestConstants.SQL_REQUESTS_BASE_PATH; +import static com.google.edwmigration.dumper.base.TestConstants.URL_DB; +import static com.google.edwmigration.dumper.base.TestConstants.USERNAME_DB; +import static com.google.edwmigration.dumper.jdbc.JdbcUtil.getDbColumnNames; +import static com.google.edwmigration.dumper.jdbc.JdbcUtil.getStringNotNull; +import static com.google.edwmigration.dumper.sql.SqlUtil.getSql; +import static java.sql.DriverManager.getConnection; + +import com.google.common.collect.LinkedHashMultiset; +import com.google.common.collect.Maps; +import com.google.common.collect.Streams; +import java.io.FileReader; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVRecord; +import org.junit.Test; + +public class SvvColumnsTest { + + private static final String SQL_PATH = SQL_REQUESTS_BASE_PATH + "svv_columns.sql"; + private static final String CSV_FILE_PATH = EXPORTED_FILES_BASE_PATH + "svv_columns.csv"; + + @Test + public void svvColumnsTest() throws SQLException, IOException { + LinkedHashMultiset> dbMultiset = create(); + LinkedHashMultiset> csvMultiset = create(); + LinkedHashMultiset dbColumnHeaders, csvColumnHeaders = null; + + try (Connection connection = getConnection(URL_DB, USERNAME_DB, PASSWORD_DB); + PreparedStatement preparedStatement = connection.prepareStatement(getSql(SQL_PATH))) { + ResultSet rs = preparedStatement.executeQuery(); + + dbColumnHeaders = create(getDbColumnNames(rs.getMetaData())); + + while (rs.next()) { + Map dbRow = new HashMap<>(); + for (String header : dbColumnHeaders) { + dbRow.put(header, getStringNotNull(rs, header)); + } + dbMultiset.add(dbRow); + } + } + + CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setSkipHeaderRecord(false).build(); + Iterable csvRows = csvFormat.parse(new FileReader(CSV_FILE_PATH)); + + csvColumnHeaders = create(csvRows.iterator().next().toList()); + + CSVRecord csvRecord; + while (csvRows.iterator().hasNext()) { + csvRecord = csvRows.iterator().next(); + csvMultiset.add( + Streams.zip(csvColumnHeaders.stream(), csvRecord.toList().stream(), Maps::immutableEntry) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + } + + assertThat(dbColumnHeaders).containsExactlyElementsIn(csvColumnHeaders); + assertDbCsvDataEqual(dbMultiset, csvMultiset); + } +} diff --git a/dumper-integration-tests/redshift-tests/src/test/java/com/google/integration/RedshiftTest.java b/dumper-integration-tests/redshift-tests/src/test/java/com/google/integration/RedshiftTest.java deleted file mode 100644 index d3cb84edb..000000000 --- a/dumper-integration-tests/redshift-tests/src/test/java/com/google/integration/RedshiftTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2022 Google LLC - * Copyright 2013-2021 CompilerWorks - * - * 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.integration; - -import static com.google.base.TestBase.assertListsEqual; -import static com.google.base.TestConstants.PASSWORD_DB; -import static com.google.base.TestConstants.URL_DB; -import static com.google.base.TestConstants.USERNAME_DB; - -import com.google.common.collect.LinkedHashMultiset; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class RedshiftTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(RedshiftTest.class); - private static Connection connection; - - @BeforeClass - public static void beforeClass() throws SQLException { - connection = DriverManager.getConnection(URL_DB, USERNAME_DB, PASSWORD_DB); - } - - @Test - public void templateTest() throws SQLException { - String sql = "select * from customers;"; - - LinkedHashMultiset dbList = LinkedHashMultiset.create(); - LinkedHashMultiset outputList = LinkedHashMultiset.create(); - - //Extract from RedShift - try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - String customernumber = rs.getString("customernumber"); - String customername = rs.getString("customername"); - String phonenumber = rs.getString("phonenumber"); - String postalcode = rs.getString("postalcode"); - String locale = rs.getString("locale"); - String datecreated = rs.getString("datecreated"); - String email = rs.getString("email"); - - LOGGER.info(String.format("%s, %s, %s, %s, %s, %s, %s", customernumber.trim(), customername, - phonenumber, postalcode, locale, datecreated, email)); - } - } - - //Extract from output files - // TODO - - //Reduce and compare - LinkedHashMultiset dbListCopy = LinkedHashMultiset.create(dbList); - outputList.forEach(dbList::remove); - dbListCopy.forEach(outputList::remove); - - assertListsEqual(dbList, outputList); - } -} diff --git a/dumper/settings.gradle b/dumper/settings.gradle deleted file mode 100644 index acd15c588..000000000 --- a/dumper/settings.gradle +++ /dev/null @@ -1,10 +0,0 @@ -rootProject.name = 'dwh-migration-dumper' -include( - 'lib-common', - 'lib-dumper-spi', - 'lib-ext-bigquery', - 'lib-ext-hive-metastore', - 'app' -) -includeFlat 'integration-tests' - diff --git a/settings.gradle b/settings.gradle index c172368dc..6ad006893 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,5 +4,6 @@ include( ':dumper:lib-dumper-spi', ':dumper:lib-ext-bigquery', ':dumper:lib-ext-hive-metastore', - ':dumper:app' + ':dumper:app', + ':dumper-integration-tests:redshift-tests' )