testcontainers.org usage / docker based DB containers for testing

185 views
Skip to first unread message

Rob Bygrave

unread,
Aug 31, 2017, 6:12:32 PM8/31/17
to ebean@googlegroups
Hi,

Is there anyone using testcontainers.org in their build setup?

I ask as I have been looking at this but it doesn't quite do what I'd like it to do around the test lifecycle, especially around DB setup and mixed IDE and "full build" use cases. 

For me, there are the 2 main use cases as I see which is:

1) IDE based run a single test - where we typically don't want the container "recycled" and sometimes don't want to drop/create the DB user and schema

2) Full build based running all tests - where we typically do want a full container recycle and full drop create of DB user and schema


Has someone got a good mechanism in place for this and happy to share?


Thanks, Rob.


Background:
For me I think there is a real move away from testing against in-memory / H2 database towards testing against the production target DB's via docker containers. On current hardware this is plenty fast enough and the integration/unit test boundary is blurring. This is especially important as we use the full features of databases like Postgres that are not available on H2.

Yes, we do this now but the developer and build experience is a bit "clunky" and I'm keen to make this simpler.

Daryl Stultz

unread,
Sep 1, 2017, 9:20:42 AM9/1/17
to eb...@googlegroups.com
On Thu, Aug 31, 2017 at 6:12 PM, Rob Bygrave <robin....@gmail.com> wrote:
Hi,

Is there anyone using testcontainers.org in their build setup?


Has someone got a good mechanism in place for this and happy to share?

We don't use "testcontainers.org", but we do use Docker. We use Bitbucket and Pipelines to do build of a Spring Boot app. I created a build environment Docker image that has Java and PostgreSQL along with the nearly-empty database "seed" for the tests. So the DB is already installed and ready to go when the container is started up.

/Daryl

Rob Bygrave

unread,
Sep 4, 2017, 3:35:58 PM9/4/17
to ebean@googlegroups
For Maven & Postgres users, first cut is: https://github.com/avaje/docker-run-tile

1. Add a docker-run.properties file specifying db name, user, password, extensions.
2. Add the maven tile

The postgres docker container is started prior to running tests and stopped on 'package'.  This means that mvn clean package and mvn clean install ... stop the container(s) at the end of the maven build. Using mvn clean test will leave the containers running ... which I think is the correct behavior for developers developing and testing. 

So this works well for build agents and local developer use (using it now).


I'll look to extend this to for MySql, ElasticSearch and L2 cache options like Ignite and Hazelcast (and Redis).


This does require docker to be installed which I think is perfectly reasonable.

Unlike testcontainers.org this:
- Is orientated to keeping the containers around for a complete test cycle.
- Just calls the install docker executable to do most of the work via  https://github.com/avaje/docker-commands
- Supports automatic drop create of database, user and for Postgres extensions like hstore, pgcrypto etc



Cheers, Rob.


--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages