Skip to content

Commit 569820e

Browse files
allow passing in a custom wait strategy string in Cassandra, Kafka and trino
1 parent 7a2ffe5 commit 569820e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

modules/cassandra/testcontainers/cassandra/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ class CassandraContainer(DockerContainer):
3939
CQL_PORT = 9042
4040
DEFAULT_LOCAL_DATACENTER = "datacenter1"
4141

42-
def __init__(self, image: str = "cassandra:latest", **kwargs) -> None:
42+
def __init__(
43+
self, image: str = "cassandra:latest", wait_strategy_check_string: str = "Startup complete", **kwargs
44+
) -> None:
4345
super().__init__(image=image, **kwargs)
4446
self.with_exposed_ports(self.CQL_PORT)
4547
self.with_env("JVM_OPTS", "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0")
4648
self.with_env("HEAP_NEWSIZE", "128M")
4749
self.with_env("MAX_HEAP_SIZE", "1024M")
4850
self.with_env("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch")
4951
self.with_env("CASSANDRA_DC", self.DEFAULT_LOCAL_DATACENTER)
50-
self.waiting_for(LogMessageWaitStrategy("Startup complete"))
52+
self.waiting_for(LogMessageWaitStrategy(wait_strategy_check_string))
5153

5254
def get_contact_points(self) -> list[tuple[str, int]]:
5355
return [(self.get_container_host_ip(), int(self.get_exposed_port(self.CQL_PORT)))]

modules/kafka/testcontainers/kafka/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ class KafkaContainer(DockerContainer):
5555
TC_START_SCRIPT = "/tc-start.sh"
5656
MIN_KRAFT_TAG = "7.0.0"
5757

58-
def __init__(self, image: str = "confluentinc/cp-kafka:7.6.0", port: int = 9093, **kwargs) -> None:
58+
def __init__(
59+
self,
60+
image: str = "confluentinc/cp-kafka:7.6.0",
61+
port: int = 9093,
62+
wait_strategy_check_string: str = r".*\[KafkaServer id=\d+\] started.*",
63+
**kwargs,
64+
) -> None:
5965
raise_for_deprecated_parameter(kwargs, "port_to_expose", "port")
6066
super().__init__(image, **kwargs)
6167
self.port = port
6268
self.kraft_enabled = False
63-
self.wait_for: re.Pattern[str] = re.compile(r".*\[KafkaServer id=\d+\] started.*")
69+
self.wait_for: re.Pattern[str] = re.compile(wait_strategy_check_string)
6470
self.boot_command = ""
6571
self.cluster_id = "MkU3OEVBNTcwNTJENDM2Qk"
6672
self.listeners = f"PLAINTEXT://0.0.0.0:{self.port},BROKER://0.0.0.0:9092"

modules/trino/testcontainers/trino/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ def __init__(
2424
user: str = "test",
2525
port: int = 8080,
2626
container_start_timeout: int = 30,
27+
wait_strategy_check_string: str = ".*======== SERVER STARTED ========.*",
2728
**kwargs,
2829
):
2930
super().__init__(image=image, **kwargs)
3031
self.user = user
3132
self.port = port
3233
self.with_exposed_ports(self.port)
3334
self.waiting_for(
34-
LogMessageWaitStrategy(re.compile(".*======== SERVER STARTED ========.*", re.MULTILINE))
35+
LogMessageWaitStrategy(re.compile(wait_strategy_check_string, re.MULTILINE))
3536
.with_poll_interval(c.sleep_time)
3637
.with_startup_timeout(container_start_timeout)
3738
)

0 commit comments

Comments
 (0)