Skip to content

Commit

Permalink
introduce BaseImage to MySql source
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-airbyte committed Dec 7, 2023
1 parent 4771e13 commit 71cf625
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.cdk.db.Database;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;

public class CDCMySqlDatatypeAccuracyTest extends MySqlDatatypeAccuracyTest {

Expand All @@ -21,7 +22,7 @@ protected JsonNode getConfig() {

@Override
protected Database setupDatabase() {
testdb = MySQLTestDatabase.in("mysql:8.0").withoutStrictMode().withCdcPermissions();
testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8).withoutStrictMode().withCdcPermissions();
return testdb.getDatabase();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.airbyte.commons.features.FeatureFlagsWrapper;
import io.airbyte.commons.json.Jsons;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.protocol.models.JsonSchemaType;
import io.airbyte.protocol.models.v0.AirbyteMessage;
import io.airbyte.protocol.models.v0.AirbyteStateMessage;
Expand All @@ -38,7 +39,7 @@ protected JsonNode getConfig() {

@Override
protected Database setupDatabase() {
testdb = MySQLTestDatabase.in("mysql:8.0").withoutStrictMode().withCdcPermissions();
testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8).withoutStrictMode().withCdcPermissions();
return testdb.getDatabase();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.airbyte.commons.features.FeatureFlags;
import io.airbyte.commons.features.FeatureFlagsWrapper;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;

public class CdcInitialSnapshotMySqlSourceDatatypeTest extends AbstractMySqlSourceDatatypeTest {

Expand All @@ -28,7 +29,7 @@ protected JsonNode getConfig() {

@Override
protected Database setupDatabase() {
testdb = MySQLTestDatabase.in("mysql:8.0").withoutStrictMode().withCdcPermissions();
testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8).withoutStrictMode().withCdcPermissions();
return testdb.getDatabase();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.airbyte.commons.features.FeatureFlagsWrapper;
import io.airbyte.commons.json.Jsons;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.protocol.models.Field;
import io.airbyte.protocol.models.JsonSchemaType;
import io.airbyte.protocol.models.v0.AirbyteMessage;
Expand Down Expand Up @@ -101,7 +102,7 @@ protected JsonNode getState() {

@Override
protected void setupEnvironment(final TestDestinationEnv environment) {
testdb = MySQLTestDatabase.in("mysql:8.0", extraContainerFactoryMethods().toArray(String[]::new))
testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8, extraContainerFactoryMethods().toArray(String[]::new))
.withCdcPermissions()
.with("CREATE TABLE id_and_name(id INTEGER, name VARCHAR(200));")
.with("INSERT INTO id_and_name (id, name) VALUES (1,'picard'), (2, 'crusher'), (3, 'vash');")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.airbyte.commons.features.FeatureFlagsWrapper;
import io.airbyte.commons.json.Jsons;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.protocol.models.Field;
import io.airbyte.protocol.models.JsonSchemaType;
import io.airbyte.protocol.models.v0.CatalogHelpers;
Expand All @@ -33,7 +34,7 @@ public class MySqlSourceAcceptanceTest extends SourceAcceptanceTest {

@Override
protected void setupEnvironment(final TestDestinationEnv environment) throws Exception {
testdb = MySQLTestDatabase.in("mysql:8.0", extraContainerFactoryMethods().toArray(String[]::new))
testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8, extraContainerFactoryMethods().toArray(String[]::new))
.with("CREATE TABLE id_and_name(id INTEGER, name VARCHAR(200));")
.with("INSERT INTO id_and_name (id, name) VALUES (1,'picard'), (2, 'crusher'), (3, 'vash');")
.with("CREATE TABLE starships(id INTEGER, name VARCHAR(200));")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.airbyte.cdk.integrations.base.ssh.SshTunnel;
import io.airbyte.commons.exceptions.ConfigErrorException;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.integrations.source.mysql.MySqlSource;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
Expand All @@ -25,7 +26,7 @@ public Path getConfigFilePath() {

@Test
public void sshTimeoutExceptionMarkAsConfigErrorTest() throws Exception {
try (final var testdb = MySQLTestDatabase.in("mysql:8.0", "withNetwork")) {
try (final var testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8, "withNetwork")) {
final SshBastionContainer bastion = new SshBastionContainer();
bastion.initAndStartBastion(testdb.getContainer().getNetwork());
final var config = testdb.integrationTestConfigBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.util.AutoCloseableIterator;
import io.airbyte.commons.util.AutoCloseableIterators;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.protocol.models.Field;
import io.airbyte.protocol.models.JsonSchemaType;
import io.airbyte.protocol.models.v0.AirbyteConnectionStatus;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class CdcMysqlSourceTest extends CdcSourceTest<MySqlSource, MySQLTestData

@Override
protected MySQLTestDatabase createTestDatabase() {
return MySQLTestDatabase.in("mysql:8.0", "withInvalidTimezoneCEST").withCdcPermissions();
return MySQLTestDatabase.in(BaseImage.MYSQL_8, "withInvalidTimezoneCEST").withCdcPermissions();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.resources.MoreResources;
import io.airbyte.commons.util.MoreIterators;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.integrations.source.mysql.internal.models.CursorBasedStatus;
import io.airbyte.integrations.source.mysql.internal.models.InternalModels.StateType;
import io.airbyte.protocol.models.Field;
Expand Down Expand Up @@ -78,7 +79,7 @@ protected MySqlSource source() {

@Override
protected MySQLTestDatabase createTestDatabase() {
return MySQLTestDatabase.in("mysql:8.0");
return MySQLTestDatabase.in(BaseImage.MYSQL_8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mysql.cj.MysqlType;
import io.airbyte.cdk.db.jdbc.DateTimeConverter;
import io.airbyte.commons.json.Jsons;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -91,7 +92,7 @@ private <T> void testImpl(
throws SQLException {
final var sqlSourceOperations = new MySqlSourceOperations();
final String cursorColumn = "cursor_column";
try (final var testdb = MySQLTestDatabase.in("mysql:8.0")
try (final var testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8)
.with("CREATE TABLE cursor_table (id INTEGER PRIMARY KEY, %s %s);", cursorColumn, sqlType)) {

final List<JsonNode> expectedRecords = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.airbyte.commons.features.FeatureFlagsWrapper;
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.util.MoreIterators;
import io.airbyte.integrations.source.mysql.MySQLTestDatabase.BaseImage;
import io.airbyte.protocol.models.Field;
import io.airbyte.protocol.models.JsonSchemaType;
import io.airbyte.protocol.models.v0.AirbyteConnectionStatus;
Expand All @@ -46,7 +47,7 @@ public MySqlSource source() {

@Test
public void testSettingTimezones() throws Exception {
try (final var testdb = MySQLTestDatabase.in("mysql:8.0", "withMoscowTimezone")) {
try (final var testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8, "withMoscowTimezone")) {
final var config = testdb.testConfigBuilder()
.with(JdbcUtils.JDBC_URL_PARAMS_KEY, "serverTimezone=Europe/Moscow")
.withoutSsl()
Expand Down Expand Up @@ -76,7 +77,7 @@ private JsonNode buildConfigEscapingNeeded() {
@Test
@Disabled("See https://github.com/airbytehq/airbyte/pull/23908#issuecomment-1463753684, enable once communication is out")
public void testNullCursorValueShouldThrowException() {
try (final var testdb = MySQLTestDatabase.in("mysql:8.0")
try (final var testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8)
.with("CREATE TABLE null_cursor_table(id INTEGER NULL);")
.with("INSERT INTO null_cursor_table(id) VALUES (1), (2), (NULL);")
.with("CREATE VIEW null_cursor_view(id) AS SELECT null_cursor_table.id FROM null_cursor_table;")) {
Expand Down Expand Up @@ -126,7 +127,7 @@ void testParseJdbcParameters() {

@Test
public void testJDBCSessionVariable() throws Exception {
try (final var testdb = MySQLTestDatabase.in("mysql:8.0")) {
try (final var testdb = MySQLTestDatabase.in(BaseImage.MYSQL_8)) {
final var config = testdb.testConfigBuilder()
.with(JdbcUtils.JDBC_URL_PARAMS_KEY, "sessionVariables=MAX_EXECUTION_TIME=28800000")
.withoutSsl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@
public class MySQLTestDatabase extends
TestDatabase<MySQLContainer<?>, MySQLTestDatabase, MySQLTestDatabase.MySQLConfigBuilder> {

static public MySQLTestDatabase in(String imageName, String... methods) {
final var container = new MySQLContainerFactory().shared(imageName, methods);
public static enum BaseImage {

MYSQL_8("mysql:8.0"),
;

private final String reference;

private BaseImage(String reference) {
this.reference = reference;
}

}

static public MySQLTestDatabase in(BaseImage baseImage, String... methods) {
final var container = new MySQLContainerFactory().shared(baseImage.reference, methods);
return new MySQLTestDatabase(container).initialized();
}

Expand Down

0 comments on commit 71cf625

Please sign in to comment.