Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAT tearDown should cleanup *all* schemas used #29312

Merged
merged 9 commits into from
Aug 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.airbyte.integrations.standardtest.destination.comparator.AdvancedTestDataComparator;
import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -149,7 +150,7 @@ protected void setup(final TestDestinationEnv testEnv) {
* Remove all the S3 output from the tests.
*/
@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
final List<KeyVersion> keysToDelete = new LinkedList<>();
final List<S3ObjectSummary> objects = s3Client
.listObjects(config.getBucketName(), config.getBucketPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@

public abstract class DestinationAcceptanceTest {

private static final ArrayList<String> TEST_SCHEMAS = new ArrayList<>();
evantahler marked this conversation as resolved.
Show resolved Hide resolved

private static final Random RANDOM = new Random();
private static final String NORMALIZATION_VERSION = "dev";

Expand Down Expand Up @@ -210,7 +212,11 @@ protected String getDefaultSchema(final JsonNode config) throws Exception {
if (config.get("schema") == null) {
return null;
}
return config.get("schema").asText();
final String schema = config.get("schema").asText();
if (!TEST_SCHEMAS.contains(schema)) {
TEST_SCHEMAS.add(schema);
}
return schema;
}

/**
Expand Down Expand Up @@ -329,9 +335,10 @@ protected List<JsonNode> retrieveNormalizedRecords(final TestDestinationEnv test
* destination so that there is no contamination across tests.
*
* @param testEnv - information about the test environment.
* @param TEST_SCHEMAS
* @throws Exception - can throw any exception, test framework will handle.
*/
protected abstract void tearDown(TestDestinationEnv testEnv) throws Exception;
protected abstract void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) throws Exception;

/**
* @deprecated This method is moved to the AdvancedTestDataComparator. Please move your destination
Expand Down Expand Up @@ -366,7 +373,7 @@ void setUpInternal() throws Exception {

@AfterEach
void tearDownInternal() throws Exception {
tearDown(testEnv);
tearDown(testEnv, TEST_SCHEMAS);
}

/**
Expand Down Expand Up @@ -981,6 +988,7 @@ void testSyncUsesAirbyteStreamNamespaceIfNotNull() throws Exception {
// A randomized namespace is required otherwise you can generate a "false success" with data from a
// previous run.
final String namespace = Strings.addRandomSuffix("airbyte_source_namespace", "_", 8);
TEST_SCHEMAS.add(namespace);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


catalog.getStreams().forEach(stream -> stream.setNamespace(namespace));
final ConfiguredAirbyteCatalog configuredCatalog = CatalogHelpers.toDefaultConfiguredCatalog(
Expand Down Expand Up @@ -1014,10 +1022,12 @@ void testSyncWriteSameTableNameDifferentNamespace() throws Exception {
MoreResources.readResource(DataArgumentsProvider.EXCHANGE_RATE_CONFIG.getCatalogFileVersion(getProtocolVersion())),
AirbyteCatalog.class);
final var namespace1 = Strings.addRandomSuffix("sourcenamespace", "_", 8);
TEST_SCHEMAS.add(namespace1);
catalog.getStreams().forEach(stream -> stream.setNamespace(namespace1));

final var diffNamespaceStreams = new ArrayList<AirbyteStream>();
final var namespace2 = Strings.addRandomSuffix("diff_sourcenamespace", "_", 8);;
final var namespace2 = Strings.addRandomSuffix("diff_sourcenamespace", "_", 8);
TEST_SCHEMAS.add(namespace2);
final var mapper = MoreMappers.initMapper();
for (final AirbyteStream stream : catalog.getStreams()) {
final var clonedStream = mapper.readValue(mapper.writeValueAsString(stream),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected void setup(final TestDestinationEnv testEnv) {
* Remove all the Container output from the tests.
*/
@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
final BlobServiceClient storageClient =
new BlobServiceClientBuilder()
.endpoint(azureBlobStorageDestinationConfig.getEndpointUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.airbyte.protocol.models.v0.CatalogHelpers;
import io.airbyte.protocol.models.v0.ConfiguredAirbyteCatalog;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -210,7 +211,7 @@ protected void setup(final TestDestinationEnv testEnv) throws Exception {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
tearDownBigQuery(dataset, bigquery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.airbyte.integrations.destination.record_buffer.FileBuffer;
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import java.nio.file.Path;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,12 +53,13 @@ protected void setup(TestDestinationEnv testEnv) throws Exception {
/**
* Removes data from bigquery and GCS This function will be called after EACH test
*
* @see DestinationAcceptanceTest#tearDownInternal()
* @param testEnv - information about the test environment.
* @param testEnv - information about the test environment.
* @param TEST_SCHEMAS
* @throws Exception - can throw any exception, test framework will handle.
* @see DestinationAcceptanceTest#tearDownInternal()
*/
@Override
protected void tearDown(TestDestinationEnv testEnv) {
protected void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
tearDownBigQuery();
tearDownGcs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import java.nio.file.Path;
import java.util.ArrayList;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,12 +35,13 @@ protected void setup(TestDestinationEnv testEnv) throws Exception {
/**
* Removes data from bigquery This function will be called after EACH test
*
* @see DestinationAcceptanceTest#tearDownInternal()
* @param testEnv - information about the test environment.
* @param testEnv - information about the test environment.
* @param TEST_SCHEMAS
* @throws Exception - can throw any exception, test framework will handle.
* @see DestinationAcceptanceTest#tearDownInternal()
*/
@Override
protected void tearDown(TestDestinationEnv testEnv) {
protected void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
tearDownBigQuery();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.airbyte.commons.json.Jsons;
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import io.airbyte.integrations.util.HostPortResolver;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -41,7 +42,7 @@ protected void setup(TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(TestDestinationEnv testEnv) {
protected void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
cassandraCqlProvider.retrieveMetadata().forEach(meta -> {
var keyspace = meta.value1();
meta.value2().forEach(table -> cassandraCqlProvider.truncate(keyspace, table));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
db.stop();
db.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.airbyte.integrations.util.HostPortResolver;
import java.sql.SQLException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -145,7 +146,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
db.stop();
db.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
bastion.stopAndCloseContainers(db);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -123,7 +124,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
// no op
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.airbyte.integrations.destination.jdbc.copy.azure.AzureBlobStorageConfig;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Disabled;
import org.slf4j.Logger;
Expand Down Expand Up @@ -69,7 +70,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) throws SQLException {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) throws SQLException {
final BlobServiceClient storageClient = new BlobServiceClientBuilder()
.endpoint(azureBlobStorageConfig.getEndpointUrl())
.sasToken(azureBlobStorageConfig.getSasToken())
Expand All @@ -83,7 +84,7 @@ protected void tearDown(final TestDestinationEnv testEnv) throws SQLException {
blobContainerClient.delete();
}

super.tearDown(testEnv);
super.tearDown(testEnv, TEST_SCHEMAS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.airbyte.integrations.destination.s3.util.AvroRecordHelper;
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.jooq.DSLContext;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected List<JsonNode> retrieveRecords(final TestDestinationEnv testEnv,
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) throws SQLException {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) throws SQLException {
DatabricksUtilTest.cleanUpData(databricksConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void setup(TestDestinationEnv testEnv) throws Exception {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) throws SQLException {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) throws SQLException {
DatabricksUtilTest.cleanUpData(databricksConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.airbyte.integrations.destination.s3.S3DestinationConfig;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
Expand Down Expand Up @@ -63,7 +64,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) throws SQLException {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) throws SQLException {
// clean up s3
final List<KeyVersion> keysToDelete = new LinkedList<>();
final List<S3ObjectSummary> objects = s3Client
Expand All @@ -82,7 +83,7 @@ protected void tearDown(final TestDestinationEnv testEnv) throws SQLException {
}
s3Client.shutdown();

super.tearDown(testEnv);
super.tearDown(testEnv, TEST_SCHEMAS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import io.airbyte.protocol.models.v0.AirbyteMessage;
import io.airbyte.protocol.models.v0.AirbyteRecordMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -46,7 +47,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected void setup(TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(TestDestinationEnv testEnv) {
protected void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
// TODO Implement this method to run any cleanup actions needed after every test case
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
final var dynamodb = new DynamoDB(this.client);
final List<String> tables = new ArrayList<String>();
dynamodb.listTables().forEach(o -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import io.airbyte.protocol.models.v0.AirbyteMessage;
import io.airbyte.protocol.models.v0.AirbyteRecordMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -47,7 +48,7 @@ protected void setup(final TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -137,7 +138,7 @@ protected List<JsonNode> retrieveRecords(final DestinationAcceptanceTest.TestDes
protected void setup(final DestinationAcceptanceTest.TestDestinationEnv testEnv) {}

@Override
protected void tearDown(final DestinationAcceptanceTest.TestDestinationEnv testEnv) {
protected void tearDown(final TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
final ElasticsearchConnection connection = new ElasticsearchConnection(mapper.convertValue(getConfig(), ConnectorConfiguration.class));
connection.allIndices().forEach(connection::deleteIndexIfPresent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.airbyte.integrations.standardtest.destination.comparator.AdvancedTestDataComparator;
import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -117,7 +118,7 @@ protected List<JsonNode> retrieveRecords(TestDestinationEnv testEnv,
protected void setup(TestDestinationEnv testEnv) throws Exception {}

@Override
protected void tearDown(TestDestinationEnv testEnv) throws Exception {
protected void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) throws Exception {
ElasticsearchConnection connection = new ElasticsearchConnection(mapper.convertValue(getConfig(), ConnectorConfiguration.class));
connection.allIndices().forEach(connection::deleteIndexIfPresent);
connection.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected void setup(TestDestinationEnv testEnv) {
}

@Override
protected void tearDown(TestDestinationEnv testEnv) {
protected void tearDown(TestDestinationEnv testEnv, ArrayList<String> TEST_SCHEMAS) {
EXASOL.purgeDatabase();
}

Expand Down
Loading