javadockerdatastax

How to set up test container with datastax enterprise cassandra?


I can set up test containers with a regular version of cassandra, but trying to use a DSE version throws this error

org.testcontainers.shaded.org.awaitility.core.ConditionTimeoutException: org.testcontainers.containers.GenericContainer expected the predicate to return <true> but it returned <false> for input of <InspectContainerResponse(

This is my current set up that is failing


@TestConfiguration
class TestContainer {
  private static final String ROC_KEYSPACE = "cksdgmdp1";
  private static CassandraContainer cassandraRocContainer;
  private static final String DSE_IMAGE_VERSION =
          "artifactory.aexp.com/dockerproxy/datastax/dse-server:5.1.10";
  @BeforeAll
  static void setupCassandraConnectionProperties() {
    System.setProperty("spring.profiles.active", "e0");
    System.setProperty("spring.profiles.env", "e0");
  }

  @Bean("cassandraRocSession")
  public CassandraSession getCassandraRocSession() {
    DockerImageName myImage =
        DockerImageName.parse(DSE_IMAGE_VERSION)
            .asCompatibleSubstituteFor("cassandra");

    cassandraRocContainer =
        (CassandraContainer)
            new CassandraContainer(myImage)
                .withInitScript(getCqlScript(ROC_KEYSPACE))
                .withExposedPorts(9042);
    // start container
    cassandraRocContainer.start();
    // create cluster object from container
    Cluster cluster =
        Cluster.builder()
            .addContactPoint(cassandraRocContainer.getHost())
            .withPort(cassandraRocContainer.getMappedPort(9042))
            .withCredentials("", "")
            .build();

    // create session from newly created keyspace
    Session session = cluster.connect(ROC_KEYSPACE);
    return new CassandraSession(session, ROC_KEYSPACE);
  }

  public String getCqlScript(String keyspace) {
    return String.format("%s.cql", keyspace);
  }

  @AfterAll
  static void shutdown() {
    cassandraRocContainer.close();
  }
}

If i change that DSE_IMAGE_VERSION to cassandra:3.11.4 then it works fine but I need to use a DSE version. I'm not sure what to try to be honest, I am pretty new with both DSE and containers.


Solution

  • According to the documentation, DS_LICENSE=accept environment variable has to be presented.

    Examples Create a DSE database container: docker run -e DS_LICENSE=accept --name my-dse -d datastax/dse-server:<version tag>

    Try the following approach:

    DockerImageName myImage = DockerImageName.parse("artifactory.aexp.com/dockerproxy/datastax/dse-server:5.1.10")
            .asCompatibleSubstituteFor("cassandra");
    
    CassandraContainer cassandraContainer = new CassandraContainer<>(myImage)
            .withEnv("DS_LICENSE", "accept");
    
    cassandraContainer.start();