From 1bc1c33a2f56831f2a9078c2972e10f6c9f54b37 Mon Sep 17 00:00:00 2001 From: ievgeniit Date: Sun, 9 Oct 2022 16:10:23 +0200 Subject: [PATCH 1/2] [17495] Source-oracle: fixed build and integration test --- .../source-oracle-strict-encrypt/build.gradle | 1 + .../AirbyteOracteTestContainer.java | 200 ++++++++++++++++++ ...StrictEncryptJdbcSourceAcceptanceTest.java | 8 +- ...acleStrictEncryptSourceAcceptanceTest.java | 4 +- .../connectors/source-oracle/build.gradle | 1 + ...AbstractSshOracleSourceAcceptanceTest.java | 6 +- .../oracle/AirbyteOracteTestContainer.java | 189 +++++++++++++++++ .../OracleJdbcSourceAcceptanceTest.java | 13 +- .../oracle/OracleSourceAcceptanceTest.java | 4 +- .../oracle/OracleSourceDatatypeTest.java | 20 +- .../source/oracle/OracleSourceTest.java | 20 +- 11 files changed, 430 insertions(+), 36 deletions(-) create mode 100644 airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java rename airbyte-integrations/connectors/source-oracle-strict-encrypt/src/{test => test-integration}/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java (98%) create mode 100644 airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java rename airbyte-integrations/connectors/source-oracle/src/{test => test-integration}/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java (97%) rename airbyte-integrations/connectors/source-oracle/src/{test => test-integration}/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java (90%) diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/build.gradle b/airbyte-integrations/connectors/source-oracle-strict-encrypt/build.gradle index ed3602b5cf9a..69ae71a6f8cc 100644 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/build.gradle +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/build.gradle @@ -30,6 +30,7 @@ dependencies { testImplementation libs.connectors.source.testcontainers.oracle.xe integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-source-test') + integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-oracle-strict-encrypt') implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) integrationTestJavaImplementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java new file mode 100644 index 000000000000..168c3d742eb8 --- /dev/null +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.integrations.source.oracle_strict_encrypt; + +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.util.Collections.singleton; + +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Future; +import org.apache.commons.lang3.StringUtils; +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; +import org.testcontainers.utility.DockerImageName; + +public class AirbyteOracteTestContainer extends JdbcDatabaseContainer { + + public static final String NAME = "oracle"; + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe"); + + static final String DEFAULT_TAG = "18.4.0-slim"; + static final String IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart(); + + private static final int ORACLE_PORT = 1521; + private static final int APEX_HTTP_PORT = 8080; + + private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240; + private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 120; + + // Container defaults + static final String DEFAULT_DATABASE_NAME = "xepdb1"; + static final String DEFAULT_SID = "xe"; + static final String DEFAULT_SYSTEM_USER = "system"; + static final String DEFAULT_SYS_USER = "sys"; + + // Test container defaults + static final String APP_USER = "test"; + static final String APP_USER_PASSWORD = "test"; + + // Restricted user and database names + private static final List ORACLE_SYSTEM_USERS = Arrays.asList(DEFAULT_SYSTEM_USER, DEFAULT_SYS_USER); + + private String databaseName = DEFAULT_DATABASE_NAME; + private String username = APP_USER; + private String password = APP_USER_PASSWORD; + private boolean usingSid = false; + + public AirbyteOracteTestContainer() { + this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG)); + } + + public AirbyteOracteTestContainer(final String dockerImageName) { + this(DockerImageName.parse(dockerImageName)); + } + + public AirbyteOracteTestContainer(final DockerImageName dockerImageName) { + super(dockerImageName); + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); + preconfigure(); + } + + public AirbyteOracteTestContainer(final Future dockerImageName) { + super(dockerImageName); + preconfigure(); + } + + private void preconfigure() { + this.waitStrategy = new LogMessageWaitStrategy() + .withRegEx(".*DATABASE IS READY TO USE!.*\\s") + .withTimes(1) + .withStartupTimeout(Duration.of(DEFAULT_STARTUP_TIMEOUT_SECONDS, SECONDS)); + + withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS); + addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT); + } + + @Override + protected void waitUntilContainerStarted() { + getWaitStrategy().waitUntilReady(this); + } + + @Override + public Set getLivenessCheckPortNumbers() { + return singleton(getMappedPort(ORACLE_PORT)); + } + + @Override + public String getDriverClassName() { + return "oracle.jdbc.OracleDriver"; + } + + @Override + public String getJdbcUrl() { + return isUsingSid() ? "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + ":" + getSid() + : "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + "/" + getDatabaseName(); + } + + @Override + public String getUsername() { + // An application user is tied to the database, and therefore not authenticated to connect to SID. + return isUsingSid() ? DEFAULT_SYSTEM_USER : username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getDatabaseName() { + return databaseName; + } + + protected boolean isUsingSid() { + return usingSid; + } + + @Override + public AirbyteOracteTestContainer withUsername(final String username) { + if (StringUtils.isEmpty(username)) { + throw new IllegalArgumentException("Username cannot be null or empty"); + } + if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) { + throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS); + } + this.username = username; + return self(); + } + + @Override + public AirbyteOracteTestContainer withPassword(final String password) { + if (StringUtils.isEmpty(password)) { + throw new IllegalArgumentException("Password cannot be null or empty"); + } + this.password = password; + return self(); + } + + @Override + public AirbyteOracteTestContainer withDatabaseName(final String databaseName) { + if (StringUtils.isEmpty(databaseName)) { + throw new IllegalArgumentException("Database name cannot be null or empty"); + } + + if (DEFAULT_DATABASE_NAME.equals(databaseName.toLowerCase())) { + throw new IllegalArgumentException("Database name cannot be set to " + DEFAULT_DATABASE_NAME); + } + + this.databaseName = databaseName; + return self(); + } + + public AirbyteOracteTestContainer usingSid() { + this.usingSid = true; + return self(); + } + + @Override + public AirbyteOracteTestContainer withUrlParam(final String paramName, final String paramValue) { + throw new UnsupportedOperationException("The Oracle Database driver does not support this"); + } + + @SuppressWarnings("SameReturnValue") + public String getSid() { + return DEFAULT_SID; + } + + public Integer getOraclePort() { + return getMappedPort(ORACLE_PORT); + } + + @SuppressWarnings("unused") + public Integer getWebPort() { + return getMappedPort(APEX_HTTP_PORT); + } + + @Override + public String getTestQueryString() { + return "SELECT 1 FROM DUAL"; + } + + @Override + protected void configure() { + withEnv("ORACLE_PASSWORD", password); + + // Only set ORACLE_DATABASE if different than the default. + if (databaseName != DEFAULT_DATABASE_NAME) { + withEnv("ORACLE_DATABASE", databaseName); + } + + withEnv("APP_USER", username); + withEnv("APP_USER_PASSWORD", password); + } + +} + diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java similarity index 98% rename from airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java rename to airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java index 48e9ef6d4d98..90e37537e957 100644 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java @@ -53,12 +53,11 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.OracleContainer; class OracleStrictEncryptJdbcSourceAcceptanceTest extends JdbcSourceAcceptanceTest { private static final Logger LOGGER = LoggerFactory.getLogger(OracleStrictEncryptJdbcSourceAcceptanceTest.class); - private static OracleContainer ORACLE_DB; + private static AirbyteOracteTestContainer ORACLE_DB; @BeforeAll static void init() { @@ -86,7 +85,10 @@ static void init() { CREATE_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "CREATE TABLE %s (%s VARCHAR(20))"; INSERT_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "INSERT INTO %s VALUES('Hello world :)')"; - ORACLE_DB = new OracleContainer("epiclabs/docker-oracle-xe-11g") + ORACLE_DB = new AirbyteOracteTestContainer() + .withUsername("test") + .withPassword("oracle") + .usingSid() .withEnv("NLS_DATE_FORMAT", "YYYY-MM-DD") .withEnv("RELAX_SECURITY", "1"); ORACLE_DB.start(); diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java index 064d0275c1c3..5c291814e8d4 100644 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java @@ -33,12 +33,12 @@ public class OracleStrictEncryptSourceAcceptanceTest extends SourceAcceptanceTes private static final String STREAM_NAME = "JDBC_SPACE.ID_AND_NAME"; private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS"; - protected OracleContainer container; + protected AirbyteOracteTestContainer container; protected JsonNode config; @Override protected void setupEnvironment(final TestDestinationEnv environment) throws Exception { - container = new OracleContainer() + container = new AirbyteOracteTestContainer() .withUsername("test") .withPassword("oracle") .usingSid();; diff --git a/airbyte-integrations/connectors/source-oracle/build.gradle b/airbyte-integrations/connectors/source-oracle/build.gradle index 1b961a1f51b6..435b7625e749 100644 --- a/airbyte-integrations/connectors/source-oracle/build.gradle +++ b/airbyte-integrations/connectors/source-oracle/build.gradle @@ -30,6 +30,7 @@ dependencies { testImplementation libs.connectors.source.testcontainers.oracle.xe integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-source-test') + integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-oracle') implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) integrationTestJavaImplementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java index 3c410eee49a5..ffb9c13393c2 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java @@ -36,7 +36,7 @@ public abstract class AbstractSshOracleSourceAcceptanceTest extends SourceAccept private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS"; private static final Network network = Network.newNetwork(); private final SshBastionContainer sshBastionContainer = new SshBastionContainer(); - private OracleContainer db; + private AirbyteOracteTestContainer db; private JsonNode config; @@ -90,7 +90,7 @@ private void startTestContainers() { } private void initAndStartJdbcContainer() { - db = new OracleContainer() + db = new AirbyteOracteTestContainer() .withUsername("test") .withPassword("oracle") .usingSid() @@ -108,7 +108,7 @@ protected ConnectorSpecification getSpec() throws Exception { return SshHelpers.getSpecAndInjectSsh(); } - public ImmutableMap.Builder getBasicOracleDbConfigBuider(final OracleContainer db) { + public ImmutableMap.Builder getBasicOracleDbConfigBuider(final AirbyteOracteTestContainer db) { return ImmutableMap.builder() .put("host", Objects.requireNonNull(db.getContainerInfo().getNetworkSettings() .getNetworks() diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java new file mode 100644 index 000000000000..1a075a1cb1cd --- /dev/null +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.integrations.source.oracle; + +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.util.Collections.singleton; + +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Future; +import org.apache.commons.lang3.StringUtils; +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; +import org.testcontainers.utility.DockerImageName; + +public class AirbyteOracteTestContainer extends JdbcDatabaseContainer { + + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe"); + + static final String DEFAULT_TAG = "18.4.0-slim"; + + private static final int ORACLE_PORT = 1521; + private static final int APEX_HTTP_PORT = 8080; + + private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240; + private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 120; + + // Container defaults + static final String DEFAULT_DATABASE_NAME = "xepdb1"; + static final String DEFAULT_SID = "xe"; + static final String DEFAULT_SYSTEM_USER = "system"; + static final String DEFAULT_SYS_USER = "sys"; + + // Test container defaults + static final String APP_USER = "test"; + static final String APP_USER_PASSWORD = "test"; + + // Restricted user and database names + private static final List ORACLE_SYSTEM_USERS = Arrays.asList(DEFAULT_SYSTEM_USER, DEFAULT_SYS_USER); + + private String databaseName = DEFAULT_DATABASE_NAME; + private String username = APP_USER; + private String password = APP_USER_PASSWORD; + private boolean usingSid = false; + + public AirbyteOracteTestContainer() { + this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG)); + } + + public AirbyteOracteTestContainer(final DockerImageName dockerImageName) { + super(dockerImageName); + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); + preconfigure(); + } + + private void preconfigure() { + this.waitStrategy = new LogMessageWaitStrategy() + .withRegEx(".*DATABASE IS READY TO USE!.*\\s") + .withTimes(1) + .withStartupTimeout(Duration.of(DEFAULT_STARTUP_TIMEOUT_SECONDS, SECONDS)); + + withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS); + addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT); + } + + @Override + protected void waitUntilContainerStarted() { + getWaitStrategy().waitUntilReady(this); + } + + @Override + public Set getLivenessCheckPortNumbers() { + return singleton(getMappedPort(ORACLE_PORT)); + } + + @Override + public String getDriverClassName() { + return "oracle.jdbc.OracleDriver"; + } + + @Override + public String getJdbcUrl() { + return isUsingSid() ? "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + ":" + getSid() + : "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + "/" + getDatabaseName(); + } + + @Override + public String getUsername() { + // An application user is tied to the database, and therefore not authenticated to connect to SID. + return isUsingSid() ? DEFAULT_SYSTEM_USER : username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getDatabaseName() { + return databaseName; + } + + protected boolean isUsingSid() { + return usingSid; + } + + @Override + public AirbyteOracteTestContainer withUsername(final String username) { + if (StringUtils.isEmpty(username)) { + throw new IllegalArgumentException("Username cannot be null or empty"); + } + if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) { + throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS); + } + this.username = username; + return self(); + } + + @Override + public AirbyteOracteTestContainer withPassword(final String password) { + if (StringUtils.isEmpty(password)) { + throw new IllegalArgumentException("Password cannot be null or empty"); + } + this.password = password; + return self(); + } + + @Override + public AirbyteOracteTestContainer withDatabaseName(final String databaseName) { + if (StringUtils.isEmpty(databaseName)) { + throw new IllegalArgumentException("Database name cannot be null or empty"); + } + + if (DEFAULT_DATABASE_NAME.equals(databaseName.toLowerCase())) { + throw new IllegalArgumentException("Database name cannot be set to " + DEFAULT_DATABASE_NAME); + } + + this.databaseName = databaseName; + return self(); + } + + public AirbyteOracteTestContainer usingSid() { + this.usingSid = true; + return self(); + } + + @Override + public AirbyteOracteTestContainer withUrlParam(final String paramName, final String paramValue) { + throw new UnsupportedOperationException("The Oracle Database driver does not support this"); + } + + @SuppressWarnings("SameReturnValue") + public String getSid() { + return DEFAULT_SID; + } + + public Integer getOraclePort() { + return getMappedPort(ORACLE_PORT); + } + + @SuppressWarnings("unused") + public Integer getWebPort() { + return getMappedPort(APEX_HTTP_PORT); + } + + @Override + public String getTestQueryString() { + return "SELECT 1 FROM DUAL"; + } + + @Override + protected void configure() { + withEnv("ORACLE_PASSWORD", password); + + // Only set ORACLE_DATABASE if different than the default. + if (databaseName != DEFAULT_DATABASE_NAME) { + withEnv("ORACLE_DATABASE", databaseName); + } + + withEnv("APP_USER", username); + withEnv("APP_USER_PASSWORD", password); + } + +} + diff --git a/airbyte-integrations/connectors/source-oracle/src/test/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java similarity index 97% rename from airbyte-integrations/connectors/source-oracle/src/test/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java rename to airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java index 714ca43d55eb..5b0d8021ad1f 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java @@ -55,14 +55,13 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.OracleContainer; class OracleJdbcSourceAcceptanceTest extends JdbcSourceAcceptanceTest { private static final Logger LOGGER = LoggerFactory.getLogger(OracleJdbcSourceAcceptanceTest.class); protected static final String USERNAME_WITHOUT_PERMISSION = "new_user"; protected static final String PASSWORD_WITHOUT_PERMISSION = "new_password"; - private static OracleContainer ORACLE_DB; + private static AirbyteOracteTestContainer ORACLE_DB; @BeforeAll static void init() { @@ -91,8 +90,12 @@ static void init() { CREATE_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "CREATE TABLE %s (%s VARCHAR(20))"; INSERT_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "INSERT INTO %s VALUES('Hello world :)')"; - ORACLE_DB = new OracleContainer("epiclabs/docker-oracle-xe-11g") + ORACLE_DB = new io.airbyte.integrations.source.oracle.AirbyteOracteTestContainer() .withEnv("NLS_DATE_FORMAT", "YYYY-MM-DD") + .withEnv("RELAX_SECURITY", "1") + .withUsername("TEST_ORA") + .withPassword("oracle") + .usingSid() .withEnv("RELAX_SECURITY", "1"); ORACLE_DB.start(); } @@ -398,8 +401,10 @@ void testCheckIncorrectPasswordFailure() throws Exception { ((ObjectNode) config).put(JdbcUtils.USERNAME_KEY, "locked_user"); ((ObjectNode) config).put(JdbcUtils.PASSWORD_KEY, "fake"); final AirbyteConnectionStatus status = source.check(config); + Assertions.assertEquals(AirbyteConnectionStatus.Status.FAILED, status.getStatus()); - assertTrue(status.getMessage().contains("State code: 99999; Error code: 28000;")); + assertEquals("State code: 72000; Error code: 1017; Message: ORA-01017: invalid username/password; logon denied\n", + status.getMessage()); } @Test diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java index 1de56a02dde5..81ae9b72a671 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java @@ -31,12 +31,12 @@ public class OracleSourceAcceptanceTest extends SourceAcceptanceTest { private static final String STREAM_NAME = "JDBC_SPACE.ID_AND_NAME"; private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS"; - protected OracleContainer container; + protected AirbyteOracteTestContainer container; protected JsonNode config; @Override protected void setupEnvironment(final TestDestinationEnv environment) throws Exception { - container = new OracleContainer() + container = new AirbyteOracteTestContainer() .withUsername("test") .withPassword("oracle") .usingSid(); diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java index 64e69c208569..89fd62baf29e 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java @@ -25,11 +25,10 @@ import org.jooq.DSLContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.OracleContainer; public class OracleSourceDatatypeTest extends AbstractSourceDatabaseTypeTest { - private OracleContainer container; + private AirbyteOracteTestContainer container; private JsonNode config; private DSLContext dslContext; @@ -37,7 +36,10 @@ public class OracleSourceDatatypeTest extends AbstractSourceDatabaseTypeTest { @Override protected Database setupDatabase() throws Exception { - container = new OracleContainer("epiclabs/docker-oracle-xe-11g") + container = new AirbyteOracteTestContainer() + .withUsername("TEST_ORA") + .withPassword("oracle") + .usingSid() .withEnv("RELAX_SECURITY", "1"); container.start(); @@ -64,7 +66,7 @@ protected Database setupDatabase() throws Exception { final Database database = new Database(dslContext); LOGGER.warn("config: " + config); - database.query(ctx -> ctx.fetch("CREATE USER test IDENTIFIED BY test DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS")); + database.query(ctx -> ctx.fetch("CREATE USER TEST IDENTIFIED BY TEST DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS")); return database; } @@ -286,11 +288,11 @@ protected void initTests() { "1\n" + "2\n" + "')") - .addExpectedValues("" + - "\n" + - " 1\n" + - " 2\n" + - "") + .addExpectedValues("\n" + + "\n" + + " 1\n" + + " 2\n" + + "\n") .build()); } diff --git a/airbyte-integrations/connectors/source-oracle/src/test/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java similarity index 90% rename from airbyte-integrations/connectors/source-oracle/src/test/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java rename to airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java index 4ef627107197..fdf913e47cb0 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java @@ -36,7 +36,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.testcontainers.containers.OracleContainer; class OracleSourceTest { @@ -48,18 +47,23 @@ class OracleSourceTest { Field.of("NAME", JsonSchemaType.STRING), Field.of("IMAGE", JsonSchemaType.STRING)) .withSupportedSyncModes(Lists.newArrayList(SyncMode.FULL_REFRESH, SyncMode.INCREMENTAL)))); + private static final ConfiguredAirbyteCatalog CONFIGURED_CATALOG = CatalogHelpers.toDefaultConfiguredCatalog(CATALOG); private static final Set ASCII_MESSAGES = Sets.newHashSet(createRecord(STREAM_NAME, map("ID", new BigDecimal("1.0"), "NAME", "user", "IMAGE", "last_summer.png".getBytes(StandardCharsets.UTF_8)))); - private static OracleContainer ORACLE_DB; + private static AirbyteOracteTestContainer ORACLE_DB; private static JsonNode config; @BeforeAll static void init() { - ORACLE_DB = new OracleContainer("epiclabs/docker-oracle-xe-11g") + ORACLE_DB = new AirbyteOracteTestContainer() + .withUsername("TEST_ORA") + .withPassword("oracle") + .usingSid() .withEnv("RELAX_SECURITY", "1"); + ORACLE_DB.start(); } @@ -97,16 +101,6 @@ void setup() throws Exception { } } - private JsonNode getConfig(final OracleContainer oracleDb) { - return Jsons.jsonNode(ImmutableMap.builder() - .put("host", oracleDb.getHost()) - .put("port", oracleDb.getFirstMappedPort()) - .put("sid", oracleDb.getSid()) - .put("username", oracleDb.getUsername()) - .put("password", oracleDb.getPassword()) - .build()); - } - @AfterAll static void cleanUp() { ORACLE_DB.close(); From 2f66e0d70bef735b45437cc7e2996902b56cec0e Mon Sep 17 00:00:00 2001 From: ievgeniit Date: Tue, 11 Oct 2022 20:24:13 +0200 Subject: [PATCH 2/2] [17495] Source-oracle: fixed build and integration test --- ...r.java => AirbyteOracleTestContainer.java} | 21 +- .../OracleContainer.java | 199 ------------------ ...StrictEncryptJdbcSourceAcceptanceTest.java | 4 +- ...acleStrictEncryptSourceAcceptanceTest.java | 4 +- ...AbstractSshOracleSourceAcceptanceTest.java | 6 +- ...r.java => AirbyteOracleTestContainer.java} | 20 +- .../oracle/AirbyteOracteTestContainer.java | 189 ----------------- .../OracleJdbcSourceAcceptanceTest.java | 4 +- .../oracle/OracleSourceAcceptanceTest.java | 4 +- .../oracle/OracleSourceDatatypeTest.java | 4 +- .../source/oracle/OracleSourceTest.java | 4 +- 11 files changed, 35 insertions(+), 424 deletions(-) rename airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/{AirbyteOracteTestContainer.java => AirbyteOracleTestContainer.java} (89%) delete mode 100644 airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleContainer.java rename airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/{OracleContainer.java => AirbyteOracleTestContainer.java} (87%) delete mode 100644 airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracleTestContainer.java similarity index 89% rename from airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java rename to airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracleTestContainer.java index 168c3d742eb8..989efbf78b44 100644 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracteTestContainer.java +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/AirbyteOracleTestContainer.java @@ -17,7 +17,7 @@ import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; import org.testcontainers.utility.DockerImageName; -public class AirbyteOracteTestContainer extends JdbcDatabaseContainer { +public class AirbyteOracleTestContainer extends JdbcDatabaseContainer { public static final String NAME = "oracle"; private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe"); @@ -49,21 +49,21 @@ public class AirbyteOracteTestContainer extends JdbcDatabaseContainer dockerImageName) { + public AirbyteOracleTestContainer(final Future dockerImageName) { super(dockerImageName); preconfigure(); } @@ -120,7 +120,7 @@ protected boolean isUsingSid() { } @Override - public AirbyteOracteTestContainer withUsername(final String username) { + public AirbyteOracleTestContainer withUsername(final String username) { if (StringUtils.isEmpty(username)) { throw new IllegalArgumentException("Username cannot be null or empty"); } @@ -132,7 +132,7 @@ public AirbyteOracteTestContainer withUsername(final String username) { } @Override - public AirbyteOracteTestContainer withPassword(final String password) { + public AirbyteOracleTestContainer withPassword(final String password) { if (StringUtils.isEmpty(password)) { throw new IllegalArgumentException("Password cannot be null or empty"); } @@ -141,7 +141,7 @@ public AirbyteOracteTestContainer withPassword(final String password) { } @Override - public AirbyteOracteTestContainer withDatabaseName(final String databaseName) { + public AirbyteOracleTestContainer withDatabaseName(final String databaseName) { if (StringUtils.isEmpty(databaseName)) { throw new IllegalArgumentException("Database name cannot be null or empty"); } @@ -154,13 +154,13 @@ public AirbyteOracteTestContainer withDatabaseName(final String databaseName) { return self(); } - public AirbyteOracteTestContainer usingSid() { + public AirbyteOracleTestContainer usingSid() { this.usingSid = true; return self(); } @Override - public AirbyteOracteTestContainer withUrlParam(final String paramName, final String paramValue) { + public AirbyteOracleTestContainer withUrlParam(final String paramName, final String paramValue) { throw new UnsupportedOperationException("The Oracle Database driver does not support this"); } @@ -197,4 +197,3 @@ protected void configure() { } } - diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleContainer.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleContainer.java deleted file mode 100644 index f534e1ce2d5c..000000000000 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleContainer.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2022 Airbyte, Inc., all rights reserved. - */ - -package io.airbyte.integrations.source.oracle_strict_encrypt; - -import static java.time.temporal.ChronoUnit.SECONDS; -import static java.util.Collections.singleton; - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; -import org.apache.commons.lang3.StringUtils; -import org.testcontainers.containers.JdbcDatabaseContainer; -import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; -import org.testcontainers.utility.DockerImageName; - -public class OracleContainer extends JdbcDatabaseContainer { - - public static final String NAME = "oracle"; - private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe"); - - static final String DEFAULT_TAG = "18.4.0-slim"; - static final String IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart(); - - private static final int ORACLE_PORT = 1521; - private static final int APEX_HTTP_PORT = 8080; - - private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240; - private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 120; - - // Container defaults - static final String DEFAULT_DATABASE_NAME = "xepdb1"; - static final String DEFAULT_SID = "xe"; - static final String DEFAULT_SYSTEM_USER = "system"; - static final String DEFAULT_SYS_USER = "sys"; - - // Test container defaults - static final String APP_USER = "test"; - static final String APP_USER_PASSWORD = "test"; - - // Restricted user and database names - private static final List ORACLE_SYSTEM_USERS = Arrays.asList(DEFAULT_SYSTEM_USER, DEFAULT_SYS_USER); - - private String databaseName = DEFAULT_DATABASE_NAME; - private String username = APP_USER; - private String password = APP_USER_PASSWORD; - private boolean usingSid = false; - - public OracleContainer() { - this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG)); - } - - public OracleContainer(final String dockerImageName) { - this(DockerImageName.parse(dockerImageName)); - } - - public OracleContainer(final DockerImageName dockerImageName) { - super(dockerImageName); - dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); - preconfigure(); - } - - public OracleContainer(final Future dockerImageName) { - super(dockerImageName); - preconfigure(); - } - - private void preconfigure() { - this.waitStrategy = new LogMessageWaitStrategy() - .withRegEx(".*DATABASE IS READY TO USE!.*\\s") - .withTimes(1) - .withStartupTimeout(Duration.of(DEFAULT_STARTUP_TIMEOUT_SECONDS, SECONDS)); - - withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS); - addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT); - } - - @Override - protected void waitUntilContainerStarted() { - getWaitStrategy().waitUntilReady(this); - } - - @Override - public Set getLivenessCheckPortNumbers() { - return singleton(getMappedPort(ORACLE_PORT)); - } - - @Override - public String getDriverClassName() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - public String getJdbcUrl() { - return isUsingSid() ? "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + ":" + getSid() - : "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + "/" + getDatabaseName(); - } - - @Override - public String getUsername() { - // An application user is tied to the database, and therefore not authenticated to connect to SID. - return isUsingSid() ? DEFAULT_SYSTEM_USER : username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getDatabaseName() { - return databaseName; - } - - protected boolean isUsingSid() { - return usingSid; - } - - @Override - public OracleContainer withUsername(final String username) { - if (StringUtils.isEmpty(username)) { - throw new IllegalArgumentException("Username cannot be null or empty"); - } - if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) { - throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS); - } - this.username = username; - return self(); - } - - @Override - public OracleContainer withPassword(final String password) { - if (StringUtils.isEmpty(password)) { - throw new IllegalArgumentException("Password cannot be null or empty"); - } - this.password = password; - return self(); - } - - @Override - public OracleContainer withDatabaseName(final String databaseName) { - if (StringUtils.isEmpty(databaseName)) { - throw new IllegalArgumentException("Database name cannot be null or empty"); - } - - if (DEFAULT_DATABASE_NAME.equals(databaseName.toLowerCase())) { - throw new IllegalArgumentException("Database name cannot be set to " + DEFAULT_DATABASE_NAME); - } - - this.databaseName = databaseName; - return self(); - } - - public OracleContainer usingSid() { - this.usingSid = true; - return self(); - } - - @Override - public OracleContainer withUrlParam(final String paramName, final String paramValue) { - throw new UnsupportedOperationException("The Oracle Database driver does not support this"); - } - - @SuppressWarnings("SameReturnValue") - public String getSid() { - return DEFAULT_SID; - } - - public Integer getOraclePort() { - return getMappedPort(ORACLE_PORT); - } - - @SuppressWarnings("unused") - public Integer getWebPort() { - return getMappedPort(APEX_HTTP_PORT); - } - - @Override - public String getTestQueryString() { - return "SELECT 1 FROM DUAL"; - } - - @Override - protected void configure() { - withEnv("ORACLE_PASSWORD", password); - - // Only set ORACLE_DATABASE if different than the default. - if (databaseName != DEFAULT_DATABASE_NAME) { - withEnv("ORACLE_DATABASE", databaseName); - } - - withEnv("APP_USER", username); - withEnv("APP_USER_PASSWORD", password); - } - -} diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java index 90e37537e957..bdee5069be37 100644 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptJdbcSourceAcceptanceTest.java @@ -57,7 +57,7 @@ class OracleStrictEncryptJdbcSourceAcceptanceTest extends JdbcSourceAcceptanceTest { private static final Logger LOGGER = LoggerFactory.getLogger(OracleStrictEncryptJdbcSourceAcceptanceTest.class); - private static AirbyteOracteTestContainer ORACLE_DB; + private static AirbyteOracleTestContainer ORACLE_DB; @BeforeAll static void init() { @@ -85,7 +85,7 @@ static void init() { CREATE_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "CREATE TABLE %s (%s VARCHAR(20))"; INSERT_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "INSERT INTO %s VALUES('Hello world :)')"; - ORACLE_DB = new AirbyteOracteTestContainer() + ORACLE_DB = new AirbyteOracleTestContainer() .withUsername("test") .withPassword("oracle") .usingSid() diff --git a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java index 5c291814e8d4..8e36d522ad33 100644 --- a/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/oracle_strict_encrypt/OracleStrictEncryptSourceAcceptanceTest.java @@ -33,12 +33,12 @@ public class OracleStrictEncryptSourceAcceptanceTest extends SourceAcceptanceTes private static final String STREAM_NAME = "JDBC_SPACE.ID_AND_NAME"; private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS"; - protected AirbyteOracteTestContainer container; + protected AirbyteOracleTestContainer container; protected JsonNode config; @Override protected void setupEnvironment(final TestDestinationEnv environment) throws Exception { - container = new AirbyteOracteTestContainer() + container = new AirbyteOracleTestContainer() .withUsername("test") .withPassword("oracle") .usingSid();; diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java index ffb9c13393c2..16eda8bdc340 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java @@ -36,7 +36,7 @@ public abstract class AbstractSshOracleSourceAcceptanceTest extends SourceAccept private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS"; private static final Network network = Network.newNetwork(); private final SshBastionContainer sshBastionContainer = new SshBastionContainer(); - private AirbyteOracteTestContainer db; + private AirbyteOracleTestContainer db; private JsonNode config; @@ -90,7 +90,7 @@ private void startTestContainers() { } private void initAndStartJdbcContainer() { - db = new AirbyteOracteTestContainer() + db = new AirbyteOracleTestContainer() .withUsername("test") .withPassword("oracle") .usingSid() @@ -108,7 +108,7 @@ protected ConnectorSpecification getSpec() throws Exception { return SshHelpers.getSpecAndInjectSsh(); } - public ImmutableMap.Builder getBasicOracleDbConfigBuider(final AirbyteOracteTestContainer db) { + public ImmutableMap.Builder getBasicOracleDbConfigBuider(final AirbyteOracleTestContainer db) { return ImmutableMap.builder() .put("host", Objects.requireNonNull(db.getContainerInfo().getNetworkSettings() .getNetworks() diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleContainer.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracleTestContainer.java similarity index 87% rename from airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleContainer.java rename to airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracleTestContainer.java index a83102f768a0..8b42af1d32b9 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleContainer.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracleTestContainer.java @@ -17,7 +17,7 @@ import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; import org.testcontainers.utility.DockerImageName; -public class OracleContainer extends JdbcDatabaseContainer { +public class AirbyteOracleTestContainer extends JdbcDatabaseContainer { public static final String NAME = "oracle"; private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe"); @@ -49,21 +49,21 @@ public class OracleContainer extends JdbcDatabaseContainer { private String password = APP_USER_PASSWORD; private boolean usingSid = false; - public OracleContainer() { + public AirbyteOracleTestContainer() { this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG)); } - public OracleContainer(final String dockerImageName) { + public AirbyteOracleTestContainer(final String dockerImageName) { this(DockerImageName.parse(dockerImageName)); } - public OracleContainer(final DockerImageName dockerImageName) { + public AirbyteOracleTestContainer(final DockerImageName dockerImageName) { super(dockerImageName); dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); preconfigure(); } - public OracleContainer(final Future dockerImageName) { + public AirbyteOracleTestContainer(final Future dockerImageName) { super(dockerImageName); preconfigure(); } @@ -120,7 +120,7 @@ protected boolean isUsingSid() { } @Override - public OracleContainer withUsername(final String username) { + public AirbyteOracleTestContainer withUsername(final String username) { if (StringUtils.isEmpty(username)) { throw new IllegalArgumentException("Username cannot be null or empty"); } @@ -132,7 +132,7 @@ public OracleContainer withUsername(final String username) { } @Override - public OracleContainer withPassword(final String password) { + public AirbyteOracleTestContainer withPassword(final String password) { if (StringUtils.isEmpty(password)) { throw new IllegalArgumentException("Password cannot be null or empty"); } @@ -141,7 +141,7 @@ public OracleContainer withPassword(final String password) { } @Override - public OracleContainer withDatabaseName(final String databaseName) { + public AirbyteOracleTestContainer withDatabaseName(final String databaseName) { if (StringUtils.isEmpty(databaseName)) { throw new IllegalArgumentException("Database name cannot be null or empty"); } @@ -154,13 +154,13 @@ public OracleContainer withDatabaseName(final String databaseName) { return self(); } - public OracleContainer usingSid() { + public AirbyteOracleTestContainer usingSid() { this.usingSid = true; return self(); } @Override - public OracleContainer withUrlParam(final String paramName, final String paramValue) { + public AirbyteOracleTestContainer withUrlParam(final String paramName, final String paramValue) { throw new UnsupportedOperationException("The Oracle Database driver does not support this"); } diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java deleted file mode 100644 index 1a075a1cb1cd..000000000000 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AirbyteOracteTestContainer.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2022 Airbyte, Inc., all rights reserved. - */ - -package io.airbyte.integrations.source.oracle; - -import static java.time.temporal.ChronoUnit.SECONDS; -import static java.util.Collections.singleton; - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; -import org.apache.commons.lang3.StringUtils; -import org.testcontainers.containers.JdbcDatabaseContainer; -import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; -import org.testcontainers.utility.DockerImageName; - -public class AirbyteOracteTestContainer extends JdbcDatabaseContainer { - - private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe"); - - static final String DEFAULT_TAG = "18.4.0-slim"; - - private static final int ORACLE_PORT = 1521; - private static final int APEX_HTTP_PORT = 8080; - - private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240; - private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 120; - - // Container defaults - static final String DEFAULT_DATABASE_NAME = "xepdb1"; - static final String DEFAULT_SID = "xe"; - static final String DEFAULT_SYSTEM_USER = "system"; - static final String DEFAULT_SYS_USER = "sys"; - - // Test container defaults - static final String APP_USER = "test"; - static final String APP_USER_PASSWORD = "test"; - - // Restricted user and database names - private static final List ORACLE_SYSTEM_USERS = Arrays.asList(DEFAULT_SYSTEM_USER, DEFAULT_SYS_USER); - - private String databaseName = DEFAULT_DATABASE_NAME; - private String username = APP_USER; - private String password = APP_USER_PASSWORD; - private boolean usingSid = false; - - public AirbyteOracteTestContainer() { - this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG)); - } - - public AirbyteOracteTestContainer(final DockerImageName dockerImageName) { - super(dockerImageName); - dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); - preconfigure(); - } - - private void preconfigure() { - this.waitStrategy = new LogMessageWaitStrategy() - .withRegEx(".*DATABASE IS READY TO USE!.*\\s") - .withTimes(1) - .withStartupTimeout(Duration.of(DEFAULT_STARTUP_TIMEOUT_SECONDS, SECONDS)); - - withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS); - addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT); - } - - @Override - protected void waitUntilContainerStarted() { - getWaitStrategy().waitUntilReady(this); - } - - @Override - public Set getLivenessCheckPortNumbers() { - return singleton(getMappedPort(ORACLE_PORT)); - } - - @Override - public String getDriverClassName() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - public String getJdbcUrl() { - return isUsingSid() ? "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + ":" + getSid() - : "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + "/" + getDatabaseName(); - } - - @Override - public String getUsername() { - // An application user is tied to the database, and therefore not authenticated to connect to SID. - return isUsingSid() ? DEFAULT_SYSTEM_USER : username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getDatabaseName() { - return databaseName; - } - - protected boolean isUsingSid() { - return usingSid; - } - - @Override - public AirbyteOracteTestContainer withUsername(final String username) { - if (StringUtils.isEmpty(username)) { - throw new IllegalArgumentException("Username cannot be null or empty"); - } - if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) { - throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS); - } - this.username = username; - return self(); - } - - @Override - public AirbyteOracteTestContainer withPassword(final String password) { - if (StringUtils.isEmpty(password)) { - throw new IllegalArgumentException("Password cannot be null or empty"); - } - this.password = password; - return self(); - } - - @Override - public AirbyteOracteTestContainer withDatabaseName(final String databaseName) { - if (StringUtils.isEmpty(databaseName)) { - throw new IllegalArgumentException("Database name cannot be null or empty"); - } - - if (DEFAULT_DATABASE_NAME.equals(databaseName.toLowerCase())) { - throw new IllegalArgumentException("Database name cannot be set to " + DEFAULT_DATABASE_NAME); - } - - this.databaseName = databaseName; - return self(); - } - - public AirbyteOracteTestContainer usingSid() { - this.usingSid = true; - return self(); - } - - @Override - public AirbyteOracteTestContainer withUrlParam(final String paramName, final String paramValue) { - throw new UnsupportedOperationException("The Oracle Database driver does not support this"); - } - - @SuppressWarnings("SameReturnValue") - public String getSid() { - return DEFAULT_SID; - } - - public Integer getOraclePort() { - return getMappedPort(ORACLE_PORT); - } - - @SuppressWarnings("unused") - public Integer getWebPort() { - return getMappedPort(APEX_HTTP_PORT); - } - - @Override - public String getTestQueryString() { - return "SELECT 1 FROM DUAL"; - } - - @Override - protected void configure() { - withEnv("ORACLE_PASSWORD", password); - - // Only set ORACLE_DATABASE if different than the default. - if (databaseName != DEFAULT_DATABASE_NAME) { - withEnv("ORACLE_DATABASE", databaseName); - } - - withEnv("APP_USER", username); - withEnv("APP_USER_PASSWORD", password); - } - -} - diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java index 5b0d8021ad1f..dcaf1803f431 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleJdbcSourceAcceptanceTest.java @@ -61,7 +61,7 @@ class OracleJdbcSourceAcceptanceTest extends JdbcSourceAcceptanceTest { private static final Logger LOGGER = LoggerFactory.getLogger(OracleJdbcSourceAcceptanceTest.class); protected static final String USERNAME_WITHOUT_PERMISSION = "new_user"; protected static final String PASSWORD_WITHOUT_PERMISSION = "new_password"; - private static AirbyteOracteTestContainer ORACLE_DB; + private static AirbyteOracleTestContainer ORACLE_DB; @BeforeAll static void init() { @@ -90,7 +90,7 @@ static void init() { CREATE_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "CREATE TABLE %s (%s VARCHAR(20))"; INSERT_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "INSERT INTO %s VALUES('Hello world :)')"; - ORACLE_DB = new io.airbyte.integrations.source.oracle.AirbyteOracteTestContainer() + ORACLE_DB = new AirbyteOracleTestContainer() .withEnv("NLS_DATE_FORMAT", "YYYY-MM-DD") .withEnv("RELAX_SECURITY", "1") .withUsername("TEST_ORA") diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java index 81ae9b72a671..498e5c329a37 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java @@ -31,12 +31,12 @@ public class OracleSourceAcceptanceTest extends SourceAcceptanceTest { private static final String STREAM_NAME = "JDBC_SPACE.ID_AND_NAME"; private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS"; - protected AirbyteOracteTestContainer container; + protected AirbyteOracleTestContainer container; protected JsonNode config; @Override protected void setupEnvironment(final TestDestinationEnv environment) throws Exception { - container = new AirbyteOracteTestContainer() + container = new AirbyteOracleTestContainer() .withUsername("test") .withPassword("oracle") .usingSid(); diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java index 89fd62baf29e..7d8541597a85 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java @@ -28,7 +28,7 @@ public class OracleSourceDatatypeTest extends AbstractSourceDatabaseTypeTest { - private AirbyteOracteTestContainer container; + private AirbyteOracleTestContainer container; private JsonNode config; private DSLContext dslContext; @@ -36,7 +36,7 @@ public class OracleSourceDatatypeTest extends AbstractSourceDatabaseTypeTest { @Override protected Database setupDatabase() throws Exception { - container = new AirbyteOracteTestContainer() + container = new AirbyteOracleTestContainer() .withUsername("TEST_ORA") .withPassword("oracle") .usingSid() diff --git a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java index fdf913e47cb0..35679e3e1905 100644 --- a/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java +++ b/airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceTest.java @@ -52,13 +52,13 @@ class OracleSourceTest { private static final Set ASCII_MESSAGES = Sets.newHashSet(createRecord(STREAM_NAME, map("ID", new BigDecimal("1.0"), "NAME", "user", "IMAGE", "last_summer.png".getBytes(StandardCharsets.UTF_8)))); - private static AirbyteOracteTestContainer ORACLE_DB; + private static AirbyteOracleTestContainer ORACLE_DB; private static JsonNode config; @BeforeAll static void init() { - ORACLE_DB = new AirbyteOracteTestContainer() + ORACLE_DB = new AirbyteOracleTestContainer() .withUsername("TEST_ORA") .withPassword("oracle") .usingSid()