Skip to content

Commit 2385175

Browse files
remove unused test utils (#22464)
* wip; rem unused code * change visibibility of helper classes; move test code to usage sites * replace SchemaTableNamePair with record class * rename io.airbyte.test.airbyte_test_container -> io.airbyte.test.container * pr-feedback; remove references to deleted annotations * remove deprecated gh actions
1 parent e745e73 commit 2385175

File tree

15 files changed

+76
-344
lines changed

15 files changed

+76
-344
lines changed

.github/workflows/gradle.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -714,21 +714,6 @@ jobs:
714714
update-comment: true
715715
debug-mode: false
716716

717-
- name: Integration test
718-
uses: Wandalen/wretry.action@master
719-
with:
720-
command: SUB_BUILD=PLATFORM ./gradlew newIntegrationTest
721-
attempt_limit: 3
722-
attempt_delay: 5000 # in ms
723-
724-
- name: Slow integration test
725-
if: contains(github.ref, 'bump-version') || contains(github.ref, 'master')
726-
uses: Wandalen/wretry.action@master
727-
with:
728-
command: SUB_BUILD=PLATFORM ./gradlew slowIntegrationTest
729-
attempt_limit: 3
730-
attempt_delay: 5000 # in ms
731-
732717
- name: Test if Seed spec is updated
733718
uses: Wandalen/wretry.action@master
734719
with:

airbyte-integrations/connectors/destination-postgres/src/test/java/io/airbyte/integrations/destination/postgres/PostgresDestinationTest.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import com.fasterxml.jackson.databind.JsonNode;
1111
import com.fasterxml.jackson.databind.node.ObjectNode;
1212
import com.google.common.collect.ImmutableMap;
13+
import io.airbyte.commons.io.IOs;
1314
import io.airbyte.commons.json.Jsons;
15+
import io.airbyte.commons.string.Strings;
16+
import io.airbyte.db.factory.DataSourceFactory;
17+
import io.airbyte.db.factory.DatabaseDriver;
18+
import io.airbyte.db.jdbc.DefaultJdbcDatabase;
1419
import io.airbyte.db.jdbc.JdbcDatabase;
1520
import io.airbyte.db.jdbc.JdbcUtils;
1621
import io.airbyte.integrations.base.AirbyteMessageConsumer;
@@ -31,12 +36,14 @@
3136
import java.util.Map;
3237
import java.util.stream.Collectors;
3338
import java.util.stream.IntStream;
39+
import javax.sql.DataSource;
3440
import org.junit.jupiter.api.AfterAll;
3541
import org.junit.jupiter.api.Assertions;
3642
import org.junit.jupiter.api.BeforeAll;
3743
import org.junit.jupiter.api.BeforeEach;
3844
import org.junit.jupiter.api.Test;
3945
import org.testcontainers.containers.PostgreSQLContainer;
46+
import org.testcontainers.utility.MountableFile;
4047

4148
public class PostgresDestinationTest {
4249

@@ -109,7 +116,7 @@ static void init() {
109116

110117
@BeforeEach
111118
void setup() {
112-
config = PostgreSQLContainerHelper.createDatabaseWithRandomNameAndGetPostgresConfig(PSQL_DB);
119+
config = createDatabaseWithRandomNameAndGetPostgresConfig(PSQL_DB);
113120
}
114121

115122
@AfterAll
@@ -208,7 +215,7 @@ public void testCheckIncorrectDataBaseFailure() {
208215

209216
@Test
210217
public void testUserHasNoPermissionToDataBase() throws Exception {
211-
final JdbcDatabase database = PostgreSQLContainerHelper.getJdbcDatabaseFromConfig(PostgreSQLContainerHelper.getDataSourceFromConfig(config));
218+
final JdbcDatabase database = getJdbcDatabaseFromConfig(getDataSourceFromConfig(config));
212219

213220
database.execute(connection -> connection.createStatement()
214221
.execute(String.format("create user %s with password '%s';", USERNAME, PASSWORD)));
@@ -249,7 +256,7 @@ void sanityTest() throws Exception {
249256
.withState(new AirbyteStateMessage().withData(Jsons.jsonNode(ImmutableMap.of(SCHEMA_NAME + "." + STREAM_NAME, 10)))));
250257
consumer.close();
251258

252-
final JdbcDatabase database = PostgreSQLContainerHelper.getJdbcDatabaseFromConfig(PostgreSQLContainerHelper.getDataSourceFromConfig(config));
259+
final JdbcDatabase database = getJdbcDatabaseFromConfig(getDataSourceFromConfig(config));
253260

254261
final List<JsonNode> actualRecords = database.bufferedResultSetQuery(
255262
connection -> connection.createStatement().executeQuery("SELECT * FROM public._airbyte_raw_id_and_name;"),
@@ -273,4 +280,40 @@ private List<AirbyteMessage> getNRecords(final int n) {
273280
.collect(Collectors.toList());
274281
}
275282

283+
private JdbcDatabase getJdbcDatabaseFromConfig(final DataSource dataSource) {
284+
return new DefaultJdbcDatabase(dataSource, JdbcUtils.getDefaultSourceOperations());
285+
}
286+
287+
private JsonNode createDatabaseWithRandomNameAndGetPostgresConfig(final PostgreSQLContainer<?> psqlDb) {
288+
final var dbName = Strings.addRandomSuffix("db", "_", 10).toLowerCase();
289+
final var initScriptName = "init_" + dbName.concat(".sql");
290+
final var tmpFilePath = IOs.writeFileToRandomTmpDir(initScriptName, "CREATE DATABASE " + dbName + ";");
291+
292+
PostgreSQLContainerHelper.runSqlScript(MountableFile.forHostPath(tmpFilePath), psqlDb);
293+
return getDestinationConfig(psqlDb, dbName);
294+
}
295+
296+
private JsonNode getDestinationConfig(final PostgreSQLContainer<?> psqlDb, final String dbName) {
297+
return Jsons.jsonNode(ImmutableMap.builder()
298+
.put(JdbcUtils.HOST_KEY, psqlDb.getHost())
299+
.put(JdbcUtils.PORT_KEY, psqlDb.getFirstMappedPort())
300+
.put(JdbcUtils.DATABASE_KEY, dbName)
301+
.put(JdbcUtils.USERNAME_KEY, psqlDb.getUsername())
302+
.put(JdbcUtils.PASSWORD_KEY, psqlDb.getPassword())
303+
.put(JdbcUtils.SCHEMA_KEY, "public")
304+
.put(JdbcUtils.SSL_KEY, false)
305+
.build());
306+
}
307+
308+
private DataSource getDataSourceFromConfig(final JsonNode config) {
309+
return DataSourceFactory.create(
310+
config.get(JdbcUtils.USERNAME_KEY).asText(),
311+
config.get(JdbcUtils.PASSWORD_KEY).asText(),
312+
DatabaseDriver.POSTGRESQL.getDriverClassName(),
313+
String.format(DatabaseDriver.POSTGRESQL.getUrlFormatString(),
314+
config.get(JdbcUtils.HOST_KEY).asText(),
315+
config.get(JdbcUtils.PORT_KEY).asInt(),
316+
config.get(JdbcUtils.DATABASE_KEY).asText()));
317+
}
318+
276319
}

airbyte-test-utils/src/main/java/io/airbyte/test/annotations/IntegrationTest.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

airbyte-test-utils/src/main/java/io/airbyte/test/annotations/SlowIntegrationTest.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
33
*/
44

5-
package io.airbyte.test.airbyte_test_container;
5+
package io.airbyte.test.container;
66

77
import com.google.common.collect.Maps;
88
import io.airbyte.api.client.AirbyteApiClient;
@@ -141,7 +141,6 @@ private void serviceLogConsumer(final DockerComposeContainer<?> composeContainer
141141
/**
142142
* Exposes logs generated by docker containers in docker compose temporal test container.
143143
*
144-
*
145144
* @param service - name of docker container from which log is emitted.
146145
* @param customConsumer - each line output by the service in docker compose will be passed ot the
147146
* consumer. if null do nothing.

airbyte-test-utils/src/main/java/io/airbyte/test/utils/AirbyteAcceptanceTestHarness.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
import io.airbyte.commons.util.MoreProperties;
6969
import io.airbyte.db.Database;
7070
import io.airbyte.db.jdbc.JdbcUtils;
71-
import io.airbyte.test.airbyte_test_container.AirbyteTestContainer;
71+
import io.airbyte.test.container.AirbyteTestContainer;
7272
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
7373
import io.fabric8.kubernetes.client.KubernetesClient;
7474
import io.temporal.client.WorkflowClient;
@@ -413,17 +413,18 @@ public Set<SchemaTableNamePair> listAllTables(final Database database) throws SQ
413413

414414
private Set<SchemaTableNamePair> addAirbyteGeneratedTables(final boolean withScdTable, final Set<SchemaTableNamePair> sourceTables) {
415415
return sourceTables.stream().flatMap(x -> {
416-
final String cleanedNameStream = x.tableName.replace(".", "_");
416+
final String cleanedNameStream = x.tableName().replace(".", "_");
417417
final List<SchemaTableNamePair> explodedStreamNames = new ArrayList<>(List.of(
418-
new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + x.schemaName,
418+
new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + x.schemaName(),
419419
String.format("_airbyte_raw_%s%s", OUTPUT_STREAM_PREFIX, cleanedNameStream)),
420-
new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + x.schemaName, String.format("%s%s", OUTPUT_STREAM_PREFIX, cleanedNameStream))));
420+
new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + x.schemaName(), String.format("%s%s", OUTPUT_STREAM_PREFIX, cleanedNameStream))));
421421
if (withScdTable) {
422422
explodedStreamNames
423-
.add(new SchemaTableNamePair("_airbyte_" + OUTPUT_NAMESPACE_PREFIX + x.schemaName,
423+
.add(new SchemaTableNamePair("_airbyte_" + OUTPUT_NAMESPACE_PREFIX + x.schemaName(),
424424
String.format("%s%s_stg", OUTPUT_STREAM_PREFIX, cleanedNameStream)));
425425
explodedStreamNames
426-
.add(new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + x.schemaName, String.format("%s%s_scd", OUTPUT_STREAM_PREFIX, cleanedNameStream)));
426+
.add(new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + x.schemaName(),
427+
String.format("%s%s_scd", OUTPUT_STREAM_PREFIX, cleanedNameStream)));
427428
}
428429
return explodedStreamNames.stream();
429430
}).collect(Collectors.toSet());
@@ -605,8 +606,8 @@ public List<JsonNode> retrieveRawDestinationRecords(final SchemaTableNamePair pa
605606
final Database destination = getDestinationDatabase();
606607
final Set<SchemaTableNamePair> namePairs = listAllTables(destination);
607608

608-
final String rawStreamName = String.format("_airbyte_raw_%s%s", OUTPUT_STREAM_PREFIX, pair.tableName.replace(".", "_"));
609-
final SchemaTableNamePair rawTablePair = new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + pair.schemaName, rawStreamName);
609+
final String rawStreamName = String.format("_airbyte_raw_%s%s", OUTPUT_STREAM_PREFIX, pair.tableName().replace(".", "_"));
610+
final SchemaTableNamePair rawTablePair = new SchemaTableNamePair(OUTPUT_NAMESPACE_PREFIX + pair.schemaName(), rawStreamName);
610611
assertTrue(namePairs.contains(rawTablePair), "can't find a non-normalized version (raw) of " + rawTablePair.getFullyQualifiedTableName());
611612

612613
return retrieveDestinationRecords(destination, rawTablePair.getFullyQualifiedTableName());
@@ -766,15 +767,15 @@ private void clearSourceDbData() throws SQLException {
766767
final Database database = getSourceDatabase();
767768
final Set<SchemaTableNamePair> pairs = listAllTables(database);
768769
for (final SchemaTableNamePair pair : pairs) {
769-
database.query(context -> context.execute(String.format("DROP TABLE %s.%s", pair.schemaName, pair.tableName)));
770+
database.query(context -> context.execute(String.format("DROP TABLE %s.%s", pair.schemaName(), pair.tableName())));
770771
}
771772
}
772773

773774
private void clearDestinationDbData() throws SQLException {
774775
final Database database = getDestinationDatabase();
775776
final Set<SchemaTableNamePair> pairs = listAllTables(database);
776777
for (final SchemaTableNamePair pair : pairs) {
777-
database.query(context -> context.execute(String.format("DROP TABLE %s.%s CASCADE", pair.schemaName, pair.tableName)));
778+
database.query(context -> context.execute(String.format("DROP TABLE %s.%s CASCADE", pair.schemaName(), pair.tableName())));
778779
}
779780
}
780781

airbyte-test-utils/src/main/java/io/airbyte/test/utils/CockroachDBContainerHelper.java

Lines changed: 0 additions & 87 deletions
This file was deleted.

airbyte-test-utils/src/main/java/io/airbyte/test/utils/GKEPostgresConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
/**
1717
* This class is used to provide information related to the test databases for running the
18-
* {@link AdvancedAcceptanceTests} on GKE. We launch 2 postgres databases in GKE as pods which act
19-
* as source and destination and the tests run against them. In order to allow the test instance to
20-
* connect to these databases we use port forwarding Refer
18+
* {@link AirbyteAcceptanceTestHarness} on GKE. We launch 2 postgres databases in GKE as pods which
19+
* act as source and destination and the tests run against them. In order to allow the test instance
20+
* to connect to these databases we use port forwarding Refer
2121
* tools/bin/gke-kube-acceptance-test/acceptance_test_kube_gke.sh for more info
2222
*/
23-
public class GKEPostgresConfig {
23+
class GKEPostgresConfig {
2424

2525
private static final String SOURCE_HOST = "postgres-source-svc";
2626
private static final String DESTINATION_HOST = "postgres-destination-svc";
@@ -29,7 +29,7 @@ public class GKEPostgresConfig {
2929
private static final String PASSWORD = "admin123";
3030
private static final String DB = "postgresdb";
3131

32-
public static Map<Object, Object> dbConfig(final Type connectorType, final boolean hiddenPassword, final boolean withSchema) {
32+
static Map<Object, Object> dbConfig(final Type connectorType, final boolean hiddenPassword, final boolean withSchema) {
3333
final Map<Object, Object> dbConfig = new HashMap<>();
3434
dbConfig.put(JdbcUtils.HOST_KEY, connectorType == Type.SOURCE ? SOURCE_HOST : DESTINATION_HOST);
3535
dbConfig.put(JdbcUtils.PASSWORD_KEY, hiddenPassword ? "**********" : PASSWORD);
@@ -45,12 +45,12 @@ public static Map<Object, Object> dbConfig(final Type connectorType, final boole
4545
return dbConfig;
4646
}
4747

48-
public static Database getSourceDatabase() {
48+
static Database getSourceDatabase() {
4949
return new Database(DSLContextFactory.create(USERNAME, PASSWORD, DatabaseDriver.POSTGRESQL.getDriverClassName(),
5050
"jdbc:postgresql://localhost:2000/postgresdb", SQLDialect.POSTGRES));
5151
}
5252

53-
public static Database getDestinationDatabase() {
53+
static Database getDestinationDatabase() {
5454
return new Database(DSLContextFactory.create(USERNAME, PASSWORD, DatabaseDriver.POSTGRESQL.getDriverClassName(),
5555
"jdbc:postgresql://localhost:4000/postgresdb", SQLDialect.POSTGRES));
5656
}

0 commit comments

Comments
 (0)