Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a test container for running Airbyte with docker-compose #4970

Merged
merged 9 commits into from
Jul 26, 2021

Conversation

cgardens
Copy link
Contributor

What

  • @subodh1810 figured out how to use test containers to run a docker compose config for MigrationAcceptanceTest.java.
  • I wanted to see if we could use it for AcceptanceTests
  • Also tried to encapsulate it so it is easier to use in other tests.

How

  • Encapsulate in AirbyteTestContainer
  • Make it optional so to whether to use the a version of airbyte running outside of the process. We still need this for K8s and tbh verdict is on whether it might sometimes still just be easier to run airbyte outside of the test container.
  • refactor MigrationAcceptanceTest.java so that it uses the current docker compose file on the "second" run so that there is less risk of drift (it had already started).

Recommended reading order

  1. AcceptanceTests.java
  2. AirbyteTestContainer.java
  3. MigrationAcceptanceTest.java

@cgardens cgardens requested a review from subodh1810 July 24, 2021 23:56
@github-actions github-actions bot added the area/api Related to the api label Jul 24, 2021
@@ -1,86 +0,0 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this into AirbyteTestContainer

DockerComposeContainer dockerComposeContainer = new DockerComposeContainer(secondRun)
.withLogConsumer("server", logConsumerForServer(logsToExpect))
.withEnv(environmentVariables);
final AirbyteTestContainer airbyteTestContainer = new AirbyteTestContainer.Builder(new File(Resources.getResource("docker-compose.yaml").toURI()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to run using the current compose file as opposed to a frozen.

@cgardens cgardens requested a review from davinchia July 25, 2021 00:03
@SuppressWarnings({"unchecked", "rawtypes"})
public void start() throws IOException, InterruptedException {
final File cleanedDockerComposeFile = prepareDockerComposeFile(dockerComposeFile);
dockerComposeContainer = new DockerComposeContainer(cleanedDockerComposeFile).withEnv(env);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's pretty awesome!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. credit goes to @subodh1810 for figuring this out originally. i'm just putting a new coat of paint on it.


@SuppressWarnings("BusyWait")
private static void waitForAirbyte() throws InterruptedException {
// todo (cgardens) - assumes port 8001 which is misleading since we can start airbyte on other
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: create follow up issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 #4992

.setPort(8001)
.setBasePath("/api"));

final HealthApi healthApi = apiClient.getHealthApi();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty clever haha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! we had been using timeouts and then i realized we have an endpoint that handles this exact purpose. 🤣

private void stopRetainVolumesInternal() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException {
final Class<? extends DockerComposeContainer> dockerComposeContainerClass = dockerComposeContainer.getClass();
try {
final Field ambassadorContainerField = dockerComposeContainerClass.getDeclaredField("ambassadorContainer");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the ambassadorContainerField and what is the SocatContainer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the reflection stuff that subodh figured out so that we could spin down a docker compose test container without deleting volumes. i'm just moving the code. i'd have to dig a bit deeper to remember how this works.

Copy link
Contributor

@davinchia davinchia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like it!

Copy link
Contributor

@jrhizor jrhizor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

…iner/AirbyteTestContainer.java

Co-authored-by: Davin Chia <davinchia@gmail.com>
@cgardens cgardens merged commit 4c8ce60 into master Jul 26, 2021
@cgardens cgardens deleted the cgardens/use_test_containers_for_compose branch July 26, 2021 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Related to the api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants