1- import { AbstractStartedContainer , GenericContainer , type StartedTestContainer } from "testcontainers" ;
1+ import { AbstractStartedContainer , GenericContainer , Wait , type StartedTestContainer } from "testcontainers" ;
22
33const CASSANDRA_PORT = 9042 ;
44
@@ -10,7 +10,7 @@ export class CassandraContainer extends GenericContainer {
1010
1111 constructor ( image = "cassandra:5.0.2" ) {
1212 super ( image ) ;
13- this . withExposedPorts ( CASSANDRA_PORT ) . withStartupTimeout ( 120_000 ) ;
13+ this . withExposedPorts ( CASSANDRA_PORT ) . withWaitStrategy ( Wait . forHealthCheck ( ) ) . withStartupTimeout ( 120_000 ) ;
1414 }
1515
1616 public withDatacenter ( dc : string ) : this {
@@ -44,7 +44,20 @@ export class CassandraContainer extends GenericContainer {
4444 CASSANDRA_PASSWORD : this . password ,
4545 CASSANDRA_SNITCH : "GossipingPropertyFileSnitch" ,
4646 CASSANDRA_ENDPOINT_SNITCH : "GossipingPropertyFileSnitch" ,
47+ CASSANDRA_NUM_TOKENS : "1" ,
48+ JVM_EXTRA_OPTS : "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0" ,
4749 } ) ;
50+ if ( ! this . healthCheck ) {
51+ this . withHealthCheck ( {
52+ test : [
53+ "CMD-SHELL" ,
54+ `cqlsh -u ${ this . username } -p ${ this . password } -e "SELECT release_version FROM system.local;"` ,
55+ ] ,
56+ interval : 250 ,
57+ timeout : 1000 ,
58+ retries : 1000 ,
59+ } ) ;
60+ }
4861 return new StartedCassandraContainer ( await super . start ( ) , this . dc , this . rack , this . username , this . password ) ;
4962 }
5063}
0 commit comments