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

Implement dependsOn for cross-container dependencies #1404

Merged
merged 7 commits into from Jul 23, 2019
Merged

Conversation

bsideup
Copy link
Member

@bsideup bsideup commented Apr 15, 2019

No description provided.

@bsideup bsideup requested a review from a team April 15, 2019 09:05
@aguibert
Copy link
Contributor

aguibert commented May 8, 2019

@bsideup instead of depending on containers with the actual Starable instances, could we perhaps introduce some sort of naming mechanism for containers, and then we could simply do dependsOn(String)? This would be nice because we wouldn't have to swap from field-based declarations to a static init block.

An example of what I had in mind:

public class MyTest {

  @Container
  public static GenericContainer a = new GenericContainer(...).withID("a");

  @Container
  public static GenericContainer b = new GenericContainer(...).dependsOn("a");

}

WDYT?

@bsideup
Copy link
Member Author

bsideup commented May 8, 2019

@aguibert I have a really bad feeling about it.
References give strong guarantees on what user refers, while strings can be anything, they are global (imagine somebody defining some generic name like "kafka" in a big code base?) and in general are less safe.

This would be nice because we wouldn't have to swap from field-based declarations to a static init block.

dependsOn does not rely on the static blocks or anything and works with fields/rules too:

public class MyTest {

  @Container
  public static GenericContainer a = new GenericContainer(...);

  @Container
  public static GenericContainer b = new GenericContainer(...).dependsOn(a);

}

@aguibert
Copy link
Contributor

aguibert commented May 8, 2019

ah, that code example you posted makes sense. I forgot that was an option because I'm used to not being able to reference other container fields like this:

public class MyTest {

  @Container
  public static GenericContainer a = new GenericContainer(...);

  @Container
  public static GenericContainer b = new GenericContainer(...)
                  .withEnv("A_PORT", a.getFirstMappedPort()); // blows up because we call `getFirstMappedPort()` too early -- before `a` is started and has its port assigned.

}

@bsideup bsideup marked this pull request as ready for review July 19, 2019 13:36
@bsideup bsideup added this to the next milestone Jul 21, 2019
Copy link
Member

@rnorth rnorth left a comment

Choose a reason for hiding this comment

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

Looks good! I have some minor comments but nothing big; feel free to merge when you're satisfied.

}

VisibleAssertions.assertEquals("Started once", 1, startable.getStartInvocationCount().intValue());
VisibleAssertions.assertEquals("Does not trigger .stop()", 0, startable.getStopInvocationCount().intValue());
Copy link
Member

Choose a reason for hiding this comment

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

I'm sure there's a good reason, but why do we not propagate a stop() call through the dependencies?

Copy link
Member Author

Choose a reason for hiding this comment

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

because there is no guarantee that the dependencies will be a part of the same "group".

We may introduce deepStop in future

Choose a reason for hiding this comment

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

I think a deepStop would be useful for when you know these are the semantics you want. I end up having to manually create one in several projects. Thoughts on adding an API?

Btw, are both stop and start required to be idempotent? I think the current implementation of deepStart depends on this.

}

@Test
public void shouldStartTransitiveDependencies() {
Copy link
Member

Choose a reason for hiding this comment

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

Just eyeballing the code, it looks like we're safe from circular dependencies, and also 'diamond' dependencies should be OK too.

Do you think it might be good to have tests for these scenarios in case a regression is introduced later?

Copy link
Member Author

Choose a reason for hiding this comment

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

Circular dependencies won't work (we have "hard depends on")

I will add a test for the diamond case 👍

Copy link
Member

@rnorth rnorth left a comment

Choose a reason for hiding this comment

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

Looks great!

@bsideup bsideup merged commit 1d686a1 into master Jul 23, 2019
@delete-merged-branch delete-merged-branch bot deleted the dependsOn branch July 23, 2019 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants