Cockroach

Testing

To test against Cockroach docker test container set the platform to cockroach in src/test/resources/application-test.yaml

Refer to docs / testing if application-test.yaml doesn't exist yet.

ebean:
  test:
    platform: cockroach #, h2, postgres, mysql, oracle, sqlserver
    ddlMode: dropCreate # none | dropCreate | migrations | create
    dbName: test

ebean-cockroach dependency

We can use the io.ebean:ebean-cockroach dependency rather than io.ebean:ebean if we want to only bring in the CockroachDB specific platform code. Depending on io.ebean:ebean will bring in all platforms.

Docker container

We can programmatically start a docker container version of CockroachDB.

The below uses ebean-test-docker dependency which already comes with ebean-test. If we do not have a dependency on ebean-test then add io.ebean:ebean-test-docker:5.0 as a dependency.

package main;

import io.ebean.docker.commands.CockroachContainer;

public class Main {

  public static void main(String[] args) {

    CockroachContainer container = CockroachContainer.newBuilder("v21.2.9")
      .dbName("unit")
      //.user("test_roach");
      .build();

    container.start();
  }
}