From 16db906b51cdc3825e342925fb605c01407d3a94 Mon Sep 17 00:00:00 2001 From: Ammar Khaku Date: Thu, 13 Oct 2022 17:36:44 -0700 Subject: [PATCH] Move Cassandra env variable setup to protected method With #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. --- .../containers/CassandraContainer.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java b/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java index a12ac03f18d..74d40306e6f 100644 --- a/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java +++ b/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java @@ -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 @@ -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 *