11from testcontainers .core .config import MAX_TRIES
22from testcontainers .core .generic import DockerContainer
3- from testcontainers .core .waiting_utils import wait_container_is_ready , wait_for_logs
3+ from testcontainers .core .waiting_utils import wait_for_logs
44
55
66class CassandraContainer (DockerContainer ):
@@ -21,26 +21,30 @@ class CassandraContainer(DockerContainer):
2121 ... "{'class': 'SimpleStrategy', 'replication_factor': '1'};")
2222 """
2323
24- def __init__ (self , image = "rinscy/ cassandra:latest" , ports_to_expose = (9042 ,)):
24+ def __init__ (self , image = "cassandra:latest" , ports_to_expose = (9042 ,)):
2525 super ().__init__ (image )
2626 self .ports_to_expose = ports_to_expose
2727 self .with_exposed_ports (* self .ports_to_expose )
2828
29- @wait_container_is_ready ()
30- def _connect (self ):
31- wait_for_logs (self , predicate = "Starting listening for CQL clients" , timeout = MAX_TRIES )
32- cluster = self .get_cluster ()
33- cluster .connect ()
29+ self .with_env ("CASSANDRA_SNITCH" , "GossipingPropertyFileSnitch" )
30+ self .with_env ("CASSANDRA_ENDPOINT_SNITCH" , "GossipingPropertyFileSnitch" )
31+ self .with_env ("JVM_OPTS" ,
32+ "-Dcassandra.skip_wait_for_gossip_to_settle=0 "
33+ "-Dcassandra.initial_token=0" )
34+ self .with_env ("HEAP_NEWSIZE" , "128M" )
35+ self .with_env ("MAX_HEAP_SIZE" , "1024M" )
36+ self .with_env ("CASSANDRA_DC" , "datacenter1" )
3437
3538 def start (self ):
3639 super ().start ()
37- self . _connect ( )
40+ wait_for_logs ( self , predicate = "Starting listening for CQL clients" , timeout = MAX_TRIES )
3841 return self
3942
4043 def get_cluster (self , ** kwargs ):
4144 from cassandra .cluster import Cluster
4245
4346 container = self .get_wrapped_container ()
4447 container .reload ()
45- hostname = container .attrs ["NetworkSettings" ]["IPAddress" ]
46- return Cluster (contact_points = [hostname ], ** kwargs )
48+ hostname = self .get_container_host_ip ()
49+ port = self .get_exposed_port (9042 )
50+ return Cluster (contact_points = [hostname ], port = port , ** kwargs )
0 commit comments