Skip to content

Commit

Permalink
Move Cassandra env variable setup to protected method
Browse files Browse the repository at this point in the history
With testcontainers#2830 we added some environment variable setup to the
constructor in CassandraContainer. This causes problems in
scenarios where users customize the environment themselves
or customize the values in cassandra.yaml, so move this init
to a protected method to facilitate overriding.
  • Loading branch information
akhaku committed Oct 14, 2022
1 parent 2da2675 commit 16db906
Showing 1 changed file with 13 additions and 7 deletions.
Expand Up @@ -68,13 +68,6 @@ public CassandraContainer(DockerImageName dockerImageName) {

addExposedPort(CQL_PORT);
this.enableJmxReporting = false;

withEnv("CASSANDRA_SNITCH", "GossipingPropertyFileSnitch");
withEnv("JVM_OPTS", "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0");
withEnv("HEAP_NEWSIZE", "128M");
withEnv("MAX_HEAP_SIZE", "1024M");
withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch");
withEnv("CASSANDRA_DC", DEFAULT_LOCAL_DATACENTER);
}

@Override
Expand Down Expand Up @@ -131,6 +124,19 @@ protected void optionallyMapResourceParameterAsVolume(String pathNameInContainer
.ifPresent(mountableFile -> withCopyFileToContainer(mountableFile, pathNameInContainer));
}

/**
* Set up environment variables to allow Cassandra to start up. You may choose to override this method for example
* if you want to set your own variables to run multi-node clusters.
*/
protected void initEnv() {
withEnv("CASSANDRA_SNITCH", "GossipingPropertyFileSnitch");
withEnv("JVM_OPTS", "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0");
withEnv("HEAP_NEWSIZE", "128M");
withEnv("MAX_HEAP_SIZE", "1024M");
withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch");
withEnv("CASSANDRA_DC", getLocalDatacenter());
}

/**
* Initialize Cassandra with the custom overridden Cassandra configuration
* <p>
Expand Down

0 comments on commit 16db906

Please sign in to comment.