Container auto-configurations for spring-boot based integration tests
Clone or download

README.md

CircleCI codecov Codacy Badge Maven Central

Data services library

If you are writing 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" below.

Table of Contents

  1. How to use
  2. List of properties per data service
    1. embedded-mariadb
    2. embedded-couchbase
    3. embedded-kafka
    4. embedded-aerospike
    5. embedded-memsql
    6. embedded-redis
    7. embedded-neo4j
    8. embedded-zookeeper
    9. embedded-postgresql
    10. embedded-elasticsearch
  3. How to contribute

How to use

Make sure you have spring boot and spring cloud in classpath of your tests. In case if you need to pick version.

<project>
...
      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
            ...
        </dependency>
...
</project>

If you do not use spring cloud - make it work for tests only

<project>
...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            ...
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
            ...
            <scope>test</scope>
        </dependency>
...
</project>

Add data service library

<project>
...
        <dependency>
            <groupId>com.playtika.testcontainers</groupId>
            <artifactId>embedded-kafka</artifactId>
            <scope>test</scope>
        </dependency>
...
</project>

Use produced properties in your configuration

Example:

/src/test/resources/application.properties

spring.kafka.zookeeperHost=${embedded.zookeeper.zookeeperConnect}
spring.kafka.brokerList=${embedded.kafka.brokerList}

/src/test/resources/bootstrap.properties

embedded.kafka.topicsToCreate=some_topic

List of properties per data service

embedded-mariadb

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-mariadb</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.mariadb.enabled (true|false, default is 'true')
  • embedded.mariadb.encoding (default is 'utf8mb4')
  • embedded.mariadb.collation (default is 'utf8mb4_unicode_ci')
  • embedded.mariadb.dockerImage (default is set to 'mariadb:10.3.2')
  • embedded.mariadb.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.mariadb.port
  • embedded.mariadb.host
  • embedded.mariadb.schema
  • embedded.mariadb.user
  • embedded.mariadb.password

embedded-couchbase

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-couchbase</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.couchbase.enabled (true|false, default is 'true')
  • embedded.couchbase.services (comma separated list, default is 'kv,index,n1ql,fts')
  • embedded.couchbase.clusterRamMb (default is set to '256')
  • embedded.couchbase.bucketRamMb (default is set to '100')
  • embedded.couchbase.dockerImage (default is set to 'couchbase:community-4.5.1')
    • You can pick wanted version on dockerhub
    • NOTE: Versions of couchbase 2.x/3.x are not functional via docker, consider use of CouchbaseMock
  • embedded.couchbase.bucketType (default is set to 'couchbase')
  • embedded.couchbase.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.couchbase.bootstrapHttpDirectPort
  • embedded.couchbase.bootstrapCarrierDirectPort
  • embedded.couchbase.host
  • embedded.couchbase.bucket
  • embedded.couchbase.user
  • embedded.couchbase.password

embedded-kafka

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-kafka</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.zookeeper.enabled (true|false, default is 'true')
  • embedded.zookeeper.waitTimeoutInSeconds (default is 60 seconds)
  • embedded.kafka.enabled (true|false, default is 'true')
  • embedded.kafka.topicsToCreate (comma separated list of topic names, default is empty)
  • embedded.kafka.dockerImage (default is set to kafka 0.11.x)
  • embedded.kafka.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.zookeeper.zookeeperConnect
  • embedded.kafka.brokerList

embedded-aerospike

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-aerospike</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • aerospike client library
  • embedded.aerospike.enabled (true|false, default is 'true')
  • embedded.aerospike.dockerImage (default is set to 'aerospike:3.15.0.1')
  • embedded.aerospike.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.aerospike.host
  • embedded.aerospike.port
  • embedded.aerospike.namespace
  • AerospikeTimeTravelService
    • timeTravelTo
    • nextDay
    • addDays
    • addHours
    • rollbackTime

embedded-memsql

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-memsql</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.memsql.enabled (true|false, default is 'true')
  • embedded.memsql.dockerImage (default is set to 'memsql/quickstart:minimal-6.0.8')
  • embedded.memsql.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.memsql.port
  • embedded.memsql.host
  • embedded.memsql.schema
  • embedded.memsql.user
  • embedded.memsql.password
Notes
  • Images without "minimal" tag do no start withing 30 secs, so they are unusable
  • There should be at least 1.5 GB of RAM available for memsql to start
  • You can enable debug logs for com.playtika.test category to troubleshoot issues

embedded-redis

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-redis</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.redis.enabled (true|false, default is 'true')
  • embedded.redis.dockerImage (default is set to 'redis:4.0.2')
  • embedded.redis.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.redis.host
  • embedded.redis.port
  • embedded.redis.user
  • embedded.redis.password

embedded-neo4j

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-neo4j</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.neo4j.enabled (true|false, default is 'true')
  • embedded.neo4j.dockerImage (default is set to 'neo4j:3.2.7')
  • embedded.neo4j.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.neo4j.user
  • embedded.neo4j.password
  • embedded.neo4j.httpsPort
  • embedded.neo4j.httpPort
  • embedded.neo4j.boltPort

embedded-zookeeper

Consumes (via bootstrap.properties)
Produces

embedded-postgresql

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-postgresql</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.postgresql.enabled (true|false, default is 'true')
  • embedded.postgresql.dockerImage (default is set to 'postgres:9.6.8')
  • embedded.postgresql.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.postgresql.port
  • embedded.postgresql.host
  • embedded.postgresql.schema
  • embedded.postgresql.user
  • embedded.postgresql.password

embedded-elasticsearch

Maven dependency
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-elasticsearch</artifactId>
    <scope>test</scope>
</dependency>
Consumes (via bootstrap.properties)
  • embedded.elasticsearch.enabled (true|false, default is 'true')
  • embedded.elasticsearch.dockerImage (default is set to 'docker.elastic.co/elasticsearch/elasticsearch:6.2.4')
  • embedded.elasticsearch.indices (indices to create, no indices are created by default)
  • embedded.elasticsearch.waitTimeoutInSeconds (default is 60 seconds)
Produces
  • embedded.elasticsearch.clusterName
  • embedded.elasticsearch.host
  • embedded.elasticsearch.httpPort
  • embedded.elasticsearch.transportPort

How to contribute

Flow

  • There is 2 branches in project: master and develop
  • 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 into master and remove snapshot + publish artifacts into public maven repo

Release