If you develop services using Spring Boot and maybe Spring Cloud and you do medium sized tests during build process, then this set of Spring Boot auto-configurations might be handy. By adding module into classpath, you will get stateful service, like Couchbase or Kafka, auto-started and available for connection from your application service w/o wiring any additional code. Docker and TestContainers are used to bootstrap stateful service using Spring Cloud bootstrap phase. Usage of Spring Cloud in your production code is optional, but you will need it in tests. See How to use below.
-
Install Docker on your machine
-
Make sure you have Spring Boot and Spring Cloud in classpath of your tests. In case if you need to pick version.
pom.xml<project> ... <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter</artifactId> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter --> <version>[pick version]</version> </dependency> ... </project>
-
If you do not use Spring Cloud - make it work for tests only:
pom.xml<project> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter --> <version>[pick version]</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter</artifactId> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter --> <version>[pick version]</version> <scope>test</scope> </dependency> ... </project>
-
Add data service library:
pom.xml<project> ... <dependency> <groupId>com.playtika.testcontainers</groupId> <artifactId>embedded-kafka</artifactId> <!-- https://mvnrepository.com/artifact/com.playtika.testcontainers/ --> <version>[pick version]</version> <scope>test</scope> </dependency> ... </project>
-
Use produced properties in your configuration.
Example:
/src/test/resources/application.propertiesspring.kafka.bootstrap-servers=${embedded.kafka.brokerList}
/src/test/resources/bootstrap.propertiesembedded.kafka.topicsToCreate=some_topic
embedded.containers.forceShutdown=true //default is false
Note
|
Otherwise it will be shutdown with delay, see https://github.com/testcontainers/moby-ryuk |
embedded.containers.enabled=true //default is true
Note
|
If you setup, for example embedded.kafka.enabled + embedded.containers.enabled, result will be same as using AND between two booleans. |
Note
|
embedded.kafka.enabled=false will cause DockerNotPresentException if you don’t have docker installed. But embedded.containers.enabled=false won’t cause any exceptions in this case. |
Setting1 | Setting2 | Outcome |
---|---|---|
embedded.containers.enabled=false |
embedded.memsql.enabled=true |
Memsql will not start |
embedded.containers.enabled=true |
embedded.memsql.enabled=false |
Memsql will not start |
embedded.containers.enabled=true |
embedded.memsql.enabled=true |
Memsql will start |
embedded.containers.enabled is missing |
embedded.memsql.enabled is missing |
Memsql will start |
-
There are 2 branches in project:
master
anddevelop
-
You need to fork project and create branch from
develop
-
You do not need to update project version in
pom.xml
files, this will be done by release job -
Once finished - create pull request to
develop
from your fork, pass review and wait for merge -
On release, ci job will merge
develop
intomaster
and remove snapshot + publish artifacts into public maven repo
-
Naming/formatting patterns match existing code
-
Test for success scenario
-
Test for negative scenario (autoconfiguration is disabled via properties). How to test autoconfiguration
-
Add new module to
testcontainers-spring-boot-bom
-
Module provides documentation in
README.adoc
and this documentation is included in parentREADME.adoc
(see an example in already existing modules). Documentation should include:-
maven module declaration
-
consumed properties
-
produced properties
-
notes (if applicable)
-
example of usage
-
-
Release build is done using gitflow-maven-plugin
-
Release is done per each major change, critical bug
-
Release can be done by contributor request
-
Contacts to start release: