Skip to content

Commit e9f67ba

Browse files
authored
🐛Destination-mysql: fixed integration test and build process (#13302)
* [13180] destination-mysql: fixed integration test
1 parent eedb740 commit e9f67ba

File tree

2 files changed

+78
-32
lines changed

2 files changed

+78
-32
lines changed

airbyte-integrations/connectors/destination-mysql-strict-encrypt/src/test-integration/java/io/airbyte/integrations/destination/mysql/MySQLStrictEncryptDestinationAcceptanceTest.java

+41-32
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import io.airbyte.commons.json.Jsons;
1313
import io.airbyte.db.Database;
1414
import io.airbyte.db.factory.DSLContextFactory;
15-
import io.airbyte.db.jdbc.JdbcUtils;
15+
import io.airbyte.db.factory.DatabaseDriver;
1616
import io.airbyte.integrations.base.JavaBaseConstants;
1717
import io.airbyte.integrations.destination.ExtendedNameTransformer;
18-
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
18+
import io.airbyte.integrations.standardtest.destination.JdbcDestinationAcceptanceTest;
19+
import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator;
1920
import io.airbyte.protocol.models.AirbyteCatalog;
2021
import io.airbyte.protocol.models.AirbyteMessage;
2122
import io.airbyte.protocol.models.AirbyteMessage.Type;
@@ -25,15 +26,14 @@
2526
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog;
2627
import java.sql.SQLException;
2728
import java.time.Instant;
28-
import java.util.ArrayList;
2929
import java.util.List;
3030
import java.util.stream.Collectors;
3131
import org.jooq.DSLContext;
3232
import org.jooq.SQLDialect;
3333
import org.junit.jupiter.api.Test;
3434
import org.testcontainers.containers.MySQLContainer;
3535

36-
public class MySQLStrictEncryptDestinationAcceptanceTest extends DestinationAcceptanceTest {
36+
public class MySQLStrictEncryptDestinationAcceptanceTest extends JdbcDestinationAcceptanceTest {
3737

3838
private MySQLContainer<?> db;
3939
private final ExtendedNameTransformer namingResolver = new MySQLNameTransformer();
@@ -58,6 +58,26 @@ protected boolean supportsNormalization() {
5858
return true;
5959
}
6060

61+
@Override
62+
protected TestDataComparator getTestDataComparator() {
63+
return new MySqlTestDataComparator();
64+
}
65+
66+
@Override
67+
protected boolean supportBasicDataTypeTest() {
68+
return true;
69+
}
70+
71+
@Override
72+
protected boolean supportArrayDataTypeTest() {
73+
return true;
74+
}
75+
76+
@Override
77+
protected boolean supportObjectDataTypeTest() {
78+
return true;
79+
}
80+
6181
@Override
6282
protected JsonNode getConfig() {
6383
return Jsons.jsonNode(ImmutableMap.builder()
@@ -96,28 +116,28 @@ protected List<JsonNode> retrieveRecords(final TestDestinationEnv testEnv,
96116
throws Exception {
97117
return retrieveRecordsFromTable(namingResolver.getRawTableName(streamName), namespace)
98118
.stream()
99-
.map(r -> Jsons.deserialize(r.get(JavaBaseConstants.COLUMN_NAME_DATA).asText()))
119+
.map(r -> r.get(JavaBaseConstants.COLUMN_NAME_DATA))
100120
.collect(Collectors.toList());
101121
}
102122

103123
private List<JsonNode> retrieveRecordsFromTable(final String tableName, final String schemaName) throws SQLException {
104-
final DSLContext dslContext = DSLContextFactory.create(
124+
try (final DSLContext dslContext = DSLContextFactory.create(
105125
db.getUsername(),
106126
db.getPassword(),
107127
db.getDriverClassName(),
108-
String.format("jdbc:mysql://%s:%s/%s?useSSL=true&requireSSL=true&verifyServerCertificate=false",
128+
String.format(DatabaseDriver.MYSQL.getUrlFormatString(),
109129
db.getHost(),
110130
db.getFirstMappedPort(),
111131
db.getDatabaseName()),
112-
SQLDialect.MYSQL);
113-
return new Database(dslContext).query(
114-
ctx -> ctx
115-
.fetch(String.format("SELECT * FROM %s.%s ORDER BY %s ASC;", schemaName, tableName,
116-
JavaBaseConstants.COLUMN_NAME_EMITTED_AT))
117-
.stream()
118-
.map(r -> r.formatJSON(JdbcUtils.getDefaultJSONFormat()))
119-
.map(Jsons::deserialize)
120-
.collect(Collectors.toList()));
132+
SQLDialect.MYSQL)) {
133+
return new Database(dslContext).query(
134+
ctx -> ctx
135+
.fetch(String.format("SELECT * FROM %s.%s ORDER BY %s ASC;", schemaName, tableName,
136+
JavaBaseConstants.COLUMN_NAME_EMITTED_AT))
137+
.stream()
138+
.map(this::getJsonFromRecord)
139+
.collect(Collectors.toList()));
140+
}
121141
}
122142

123143
@Override
@@ -128,18 +148,6 @@ protected List<JsonNode> retrieveNormalizedRecords(final TestDestinationEnv test
128148
return retrieveRecordsFromTable(tableName, schema);
129149
}
130150

131-
@Override
132-
protected List<String> resolveIdentifier(final String identifier) {
133-
final List<String> result = new ArrayList<>();
134-
final String resolved = namingResolver.getIdentifier(identifier);
135-
result.add(identifier);
136-
result.add(resolved);
137-
if (!resolved.startsWith("\"")) {
138-
result.add(resolved.toLowerCase());
139-
}
140-
return result;
141-
}
142-
143151
@Override
144152
protected void setup(final TestDestinationEnv testEnv) {
145153
db = new MySQLContainer<>("mysql:8.0");
@@ -163,10 +171,10 @@ private void grantCorrectPermissions() {
163171

164172
private void executeQuery(final String query) {
165173
try (final DSLContext dslContext = DSLContextFactory.create(
166-
db.getUsername(),
167-
db.getPassword(),
174+
"root",
175+
"test",
168176
db.getDriverClassName(),
169-
String.format("jdbc:mysql://%s:%s/%s?useSSL=true&requireSSL=true&verifyServerCertificate=false",
177+
String.format(DatabaseDriver.MYSQL.getUrlFormatString(),
170178
db.getHost(),
171179
db.getFirstMappedPort(),
172180
db.getDatabaseName()),
@@ -187,9 +195,10 @@ protected void tearDown(final TestDestinationEnv testEnv) {
187195

188196
@Override
189197
@Test
190-
public void testCustomDbtTransformations() {
198+
public void testCustomDbtTransformations() throws Exception {
191199
// We need to create view for testing custom dbt transformations
192200
executeQuery("GRANT CREATE VIEW ON *.* TO " + db.getUsername() + "@'%';");
201+
super.testCustomDbtTransformations();
193202
}
194203

195204
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
*/
4+
5+
package io.airbyte.integrations.destination.mysql;
6+
7+
import io.airbyte.integrations.destination.ExtendedNameTransformer;
8+
import io.airbyte.integrations.standardtest.destination.comparator.AdvancedTestDataComparator;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
public class MySqlTestDataComparator extends AdvancedTestDataComparator {
13+
14+
private final ExtendedNameTransformer namingResolver = new MySQLNameTransformer();
15+
16+
@Override
17+
protected List<String> resolveIdentifier(final String identifier) {
18+
final List<String> result = new ArrayList<>();
19+
final String resolved = namingResolver.getIdentifier(identifier);
20+
result.add(identifier);
21+
result.add(resolved);
22+
if (!resolved.startsWith("\"")) {
23+
result.add(resolved.toLowerCase());
24+
}
25+
return result;
26+
}
27+
28+
@Override
29+
protected boolean compareBooleanValues(String firstBooleanValue, String secondBooleanValue) {
30+
if (secondBooleanValue.equalsIgnoreCase("true") || secondBooleanValue.equalsIgnoreCase("false")) {
31+
return super.compareBooleanValues(firstBooleanValue, secondBooleanValue);
32+
} else {
33+
return super.compareBooleanValues(firstBooleanValue, String.valueOf(secondBooleanValue.equals("1")));
34+
}
35+
}
36+
37+
}

0 commit comments

Comments
 (0)