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

Reuse @TestContainers and @Container #11

Open
hantsy opened this issue Jun 29, 2024 · 5 comments
Open

Reuse @TestContainers and @Container #11

hantsy opened this issue Jun 29, 2024 · 5 comments

Comments

@hantsy
Copy link
Member

hantsy commented Jun 29, 2024

I found there is a new annotation @TestContainer added to control testcontainer Container. https://github.com/arquillian/arquillian-testcontainers/blob/main/src/main/java/org/jboss/arquillian/testcontainers/TestContainersObserver.java#L28

The basic support of Spring Boot testcontiners just adds a @ServiceConnection to the container declarations to setup the connection properties automatically.

@SpringBootTest
@Testcontainers// from testcontainers
class MyTeset {

   @Container // from testcontainers
   @ServiceConnection // from spring Boot
   static AContainer container = ...
}

If possible, reuse the testcontainers existing @Testcontainers and @Container to controll the container lifecycle, and ensure Arquillian sets up the application server adapter's properties after the successful waiting strategy. Then perform the deployment that is defined by @Deployment.

@jamezp
Copy link
Collaborator

jamezp commented Jul 1, 2024

Those annotations will not work in all cases. For example, in WildFly there is the ability to implement a ServerSetupTask which allows for configuration of WildFly before the deployment is done. You cannot inject the same instance of the Testcontainer in the ServerSetupTask without Arquillian managing the lifecyle of the Testcontainer.

@hantsy
Copy link
Member Author

hantsy commented Jul 2, 2024

Testcontainers have wait strategies, can the Wildfly/Glassfishs test deployment step wait for testconainters be ready for deployment?

@jamezp
Copy link
Collaborator

jamezp commented Jul 2, 2024

@hantsy Yes, that should be possible AFAIK. If you have an example of what it would look like without Arquillian, I can confirm.

What should happen though is the Testcontainer is started before the class. The class should then be created and the deployment done. Once the class is complete, the Testcontainer should stop.

@hantsy
Copy link
Member Author

hantsy commented Jul 2, 2024

I tried this way in an example before: https://github.com/hantsy/arquillian-testcontainers-example/blob/autodeployment/src/test/java/com/example/it/GreetingResourceTest.java#L51
(ignore this example in autodeployment branch, I was trying to use AutoDeployment provided in Arquillian, but not sure why the deployment was not started)

The @Container and @Deployment archives can be ready before running tests, Arquillian can utilize the wait strategy provided by Testcontainers, etc. to check the startup status of the application server and setup Arqullian properties for application servers, and decide to deploy.

@jamezp
Copy link
Collaborator

jamezp commented Jul 2, 2024

That could be done by extending the testcontainer. Note that the @Testcontainer annotation for JUnit 5 in the Testcontainer project is different than this. This project is for injecting a GenericContainer<?> as an @ArquillianResource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants