Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MySQL source: Add comprehensive data type test (#3810)
- Loading branch information
1 parent
5d911ed
commit 213fae1
Showing
55 changed files
with
1,419 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...ce-test/src/main/java/io/airbyte/integrations/standardtest/source/SourceAbstractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.integrations.standardtest.source; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.config.JobGetSpecConfig; | ||
import io.airbyte.config.StandardCheckConnectionInput; | ||
import io.airbyte.config.StandardCheckConnectionOutput; | ||
import io.airbyte.config.StandardDiscoverCatalogInput; | ||
import io.airbyte.config.StandardTapConfig; | ||
import io.airbyte.config.State; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import io.airbyte.protocol.models.ConnectorSpecification; | ||
import io.airbyte.workers.DefaultCheckConnectionWorker; | ||
import io.airbyte.workers.DefaultDiscoverCatalogWorker; | ||
import io.airbyte.workers.DefaultGetSpecWorker; | ||
import io.airbyte.workers.WorkerException; | ||
import io.airbyte.workers.process.AirbyteIntegrationLauncher; | ||
import io.airbyte.workers.process.DockerProcessFactory; | ||
import io.airbyte.workers.process.ProcessFactory; | ||
import io.airbyte.workers.protocols.airbyte.AirbyteSource; | ||
import io.airbyte.workers.protocols.airbyte.DefaultAirbyteSource; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public abstract class SourceAbstractTest { | ||
|
||
private TestDestinationEnv environment; | ||
private Path jobRoot; | ||
protected Path localRoot; | ||
private ProcessFactory processFactory; | ||
|
||
private static final long JOB_ID = 0L; | ||
private static final int JOB_ATTEMPT = 0; | ||
|
||
/** | ||
* Name of the docker image that the tests will run against. | ||
* | ||
* @return docker image name | ||
*/ | ||
protected abstract String getImageName(); | ||
|
||
/** | ||
* Configuration specific to the integration. Will be passed to integration where appropriate in | ||
* each test. Should be valid. | ||
* | ||
* @return integration-specific configuration | ||
*/ | ||
protected abstract JsonNode getConfig() throws Exception; | ||
|
||
/** | ||
* Function that performs any setup of external resources required for the test. e.g. instantiate a | ||
* postgres database. This function will be called before EACH test. | ||
* | ||
* @param environment - information about the test environment. | ||
* @throws Exception - can throw any exception, test framework will handle. | ||
*/ | ||
protected abstract void setupEnvironment(TestDestinationEnv environment) throws Exception; | ||
|
||
/** | ||
* Function that performs any clean up of external resources required for the test. e.g. delete a | ||
* postgres database. This function will be called after EACH test. It MUST remove all data in the | ||
* destination so that there is no contamination across tests. | ||
* | ||
* @param testEnv - information about the test environment. | ||
* @throws Exception - can throw any exception, test framework will handle. | ||
*/ | ||
protected abstract void tearDown(TestDestinationEnv testEnv) throws Exception; | ||
|
||
@BeforeEach | ||
public void setUpInternal() throws Exception { | ||
final Path testDir = Path.of("/tmp/airbyte_tests/"); | ||
Files.createDirectories(testDir); | ||
final Path workspaceRoot = Files.createTempDirectory(testDir, "test"); | ||
jobRoot = Files.createDirectories(Path.of(workspaceRoot.toString(), "job")); | ||
localRoot = Files.createTempDirectory(testDir, "output"); | ||
environment = new TestDestinationEnv(localRoot); | ||
|
||
setupEnvironment(environment); | ||
|
||
processFactory = new DockerProcessFactory( | ||
workspaceRoot, | ||
workspaceRoot.toString(), | ||
localRoot.toString(), | ||
"host"); | ||
} | ||
|
||
@AfterEach | ||
public void tearDownInternal() throws Exception { | ||
tearDown(environment); | ||
} | ||
|
||
protected ConnectorSpecification runSpec() throws WorkerException { | ||
return new DefaultGetSpecWorker(new AirbyteIntegrationLauncher(JOB_ID, JOB_ATTEMPT, getImageName(), processFactory)) | ||
.run(new JobGetSpecConfig().withDockerImage(getImageName()), jobRoot); | ||
} | ||
|
||
protected StandardCheckConnectionOutput runCheck() throws Exception { | ||
return new DefaultCheckConnectionWorker(new AirbyteIntegrationLauncher(JOB_ID, JOB_ATTEMPT, getImageName(), processFactory)) | ||
.run(new StandardCheckConnectionInput().withConnectionConfiguration(getConfig()), jobRoot); | ||
} | ||
|
||
protected AirbyteCatalog runDiscover() throws Exception { | ||
return new DefaultDiscoverCatalogWorker(new AirbyteIntegrationLauncher(JOB_ID, JOB_ATTEMPT, getImageName(), processFactory)) | ||
.run(new StandardDiscoverCatalogInput().withConnectionConfiguration(getConfig()), jobRoot); | ||
} | ||
|
||
protected List<AirbyteMessage> runRead(ConfiguredAirbyteCatalog configuredCatalog) throws Exception { | ||
return runRead(configuredCatalog, null); | ||
} | ||
|
||
// todo (cgardens) - assume no state since we are all full refresh right now. | ||
protected List<AirbyteMessage> runRead(ConfiguredAirbyteCatalog catalog, JsonNode state) throws Exception { | ||
final StandardTapConfig sourceConfig = new StandardTapConfig() | ||
.withSourceConnectionConfiguration(getConfig()) | ||
.withState(state == null ? null : new State().withState(state)) | ||
.withCatalog(catalog); | ||
|
||
final AirbyteSource source = new DefaultAirbyteSource(new AirbyteIntegrationLauncher(JOB_ID, JOB_ATTEMPT, getImageName(), processFactory)); | ||
final List<AirbyteMessage> messages = new ArrayList<>(); | ||
source.start(sourceConfig, jobRoot); | ||
while (!source.isFinished()) { | ||
source.attemptRead().ifPresent(messages::add); | ||
} | ||
source.close(); | ||
|
||
return messages; | ||
} | ||
|
||
} |
Oops, something went wrong.