java-cdk: introduce TestDatabase - #32656
Marius Posta (postamar) wants to merge 14 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
| @@ -1,74 +0,0 @@ | |||
| /* | |||
| } | ||
|
|
||
| } | ||
|
|
| .filter(d -> d.compareTo(CONNECT_TIMEOUT_DEFAULT) >= 0); | ||
| }; | ||
| return parsedConnectionTimeout.orElse(CONNECT_TIMEOUT_DEFAULT).toMillis(); | ||
| } |
There was a problem hiding this comment.
Stephane Geneix (@stephane-airbyte) I hope this is less offensive, despite having left in some Optional usages. I agree the previous iteration wasn't readable but I honestly believe that this one is.
There was a problem hiding this comment.
The purpose of adding support for these new databases is to speed up the test cases in which a timeout is expected. We don't want to have to wait a whole minute every time.
| .put("tunnel_user_password", tunnelMethod.equals(SSH_PASSWORD_AUTH) ? SSH_PASSWORD : "") | ||
| .put("ssh_key", tunnelMethod.equals(SSH_KEY_AUTH) ? bastion.execInContainer("cat", "var/bastion/id_rsa").getStdout() : "") | ||
| .build()); | ||
| } |
There was a problem hiding this comment.
This got lifted out of getTunnelConfig because we can't use the latter with the new TestDatabase.ConfigBuilder objects.
| @Override | ||
| public void close() { | ||
| stopAndClose(); | ||
| } |
There was a problem hiding this comment.
Dunno why this wasn't an AutoCloseable in the first place! I leftstopAndClose in place because why not.
| mySQLContainer.start(); | ||
| final Map<String, String> connectionProperties = Map.of( | ||
| CONNECT_TIMEOUT, "30"); | ||
| CONNECT_TIMEOUT, "5000"); |
There was a problem hiding this comment.
Updated to reflect the addition of MySQL support in getConnectionTimeoutMs. For MySQL the timeout value is expressed in milliseconds.
| Map.of("loginTimeout", "5")); | ||
| assertNotNull(dataSource); | ||
| assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
| assertEquals(5000, ((HikariDataSource) dataSource).getHikariConfigMXBean().getConnectionTimeout()); |
There was a problem hiding this comment.
Added a case to cover the new MS SQL Server support in getConnectionTimeoutMs.
| final CdcTargetPosition<T> targetPosition, | ||
| final boolean trackSchemaHistory, | ||
| final Duration firstRecordWaitTime, | ||
| final Duration subsequentRecordWaitTime, |
There was a problem hiding this comment.
Plumbing this value here and all the way into the DebeziumRecordIterator allows us to speed up the tests by relying on a different default value in tests. This change has no impact in production.
| /** | ||
| * In the default case here, we don't know for sure whether the Debezium Engine will produce records | ||
| * or not. We therefore pass {@link canShortCircuitDebeziumEngine} = false. | ||
| */ |
There was a problem hiding this comment.
I'm getting rid of the canShortCircuitDebeziumEngine functionality. It's not easily portable and there are easier ways to speed up the tests almost as well. Namely, heartbeats and a shorter subsequentRecordWaitTime.
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class FirstRecordWaitTimeUtil { | ||
| public class RecordWaitTimeUtil { |
There was a problem hiding this comment.
Renamed this class as a consequence of plumbing subsequentRecordWaitTime.
| import java.util.Optional; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class RecordWaitTimeUtilTest { |
There was a problem hiding this comment.
Renamed FirstRecordWaitTimeUtilTest into this as a consequence of plumbing subsequentRecordWaitTime.
|
|
||
| @ParameterizedTest | ||
| @Disabled | ||
| @ValueSource(strings = {"pgoutput", "wal2json"}) |
| final var slotStateAtTheEnd = getReplicationSlot(database, fullReplicationSlot, plugin, dbName); | ||
| Assertions.assertEquals(slotStateAfterCommit, slotStateAtTheEnd); | ||
|
|
||
| container.stop(); |
There was a problem hiding this comment.
Removed this part of the test case which is what covered the debezium short-circuiting functionality in maybeReplicationStreamIntervalHasRecords. It also was flaky which is why the test is no longer disabled.
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public abstract class CdcSourceTest { | ||
| public abstract class CdcSourceTest<S extends Source, T extends TestDatabase<?, T, ?>> { |
There was a problem hiding this comment.
This class is rewritten so that the only mutable state shared across test methods is protected T testdb,. The test logic itself remains unchanged.
| } | ||
|
|
||
| protected void maybeSetShorterConnectionTimeout() { | ||
| protected void maybeSetShorterConnectionTimeout(final JsonNode config) { |
There was a problem hiding this comment.
Signature was changed to reflect that of the similar method in the new JdbcSourceTest fixture.
| @SuppressFBWarnings( | ||
| value = {"MS_SHOULD_BE_FINAL"}, | ||
| justification = "The static variables are updated in subclasses for convenience, and cannot be final.") | ||
| abstract public class JdbcSourceTest<S extends Source, T extends TestDatabase<?, T, ?>> { |
There was a problem hiding this comment.
This class is JdbcSourceAcceptanceTest but where the only mutable state shared between test methods is protected T testdb;. This is the same idea as for CdcSourceTest but unlike that class, JdbcSourceAcceptanceTest is still used by many non-certified connectors.
| systemProperty 'junit.jupiter.execution.parallel.config.strategy', 'fixed' | ||
| systemProperty 'junit.jupiter.execution.parallel.config.fixed.parallelism', 1 | ||
| // Order test classes by annotation. | ||
| systemProperty 'junit.jupiter.testclass.order.default', 'org.junit.jupiter.api.ClassOrderer$OrderAnnotation' |
There was a problem hiding this comment.
This allows decorating test classes with @Order(...) annotations to help long-running classes get scheduled early on.
| class AirbyteJavaConnectorExtension { | ||
|
|
||
| boolean useLocalCdk = true | ||
| boolean useLocalCdk |
There was a problem hiding this comment.
I don't think true is a safe default at all.
| void setUseLocalCdk(boolean useLocalCdk) { | ||
| this.useLocalCdk = useLocalCdk | ||
| addCdkDependencies() | ||
| } |
There was a problem hiding this comment.
This is a bit of a hack (but gradle kind of sucks) to remove the need for the explicit addCdkDependencies() call in the connector's build.gradle, since setting useLocalCdk to either true or false is mandatory anyway. We should revisit this when we revamp the CDK development lifecycle.
The other changes to this file in this diff are benign additions or readability improvements.
|
This is now ready for review. I added some commentary to help the review process. See companion PRs for application to certified source connectors: |
|
Closed in favour of Graphite stacked PR #32772. |
This PR extracts a new, generic
TestDatabasesuperclass from the the newly-introducedPostgresTestDatabase, and rewrites theCdcSourceTestandJdbcSourceAcceptanceTestbase classes using these types.