22
33import org .testcontainers .containers .wait .strategy .Wait ;
44import org .testcontainers .containers .wait .strategy .WaitAllStrategy ;
5- import org .testcontainers .containers .wait .strategy .WaitStrategy ;
65import org .testcontainers .utility .DockerImageName ;
76
8- import java .util .ArrayList ;
9- import java .util .List ;
10-
117/**
128 * This container wraps Apache Pulsar running in standalone mode
139 */
@@ -36,6 +32,8 @@ public class PulsarContainer extends GenericContainer<PulsarContainer> {
3632 @ Deprecated
3733 private static final String DEFAULT_TAG = "2.10.0" ;
3834
35+ private final WaitAllStrategy waitAllStrategy = new WaitAllStrategy ();
36+
3937 private boolean functionsWorkerEnabled = false ;
4038
4139 private boolean transactionsEnabled = false ;
@@ -60,6 +58,7 @@ public PulsarContainer(final DockerImageName dockerImageName) {
6058 super (dockerImageName );
6159 dockerImageName .assertCompatibleWith (DockerImageName .parse ("apachepulsar/pulsar" ));
6260 withExposedPorts (BROKER_PORT , BROKER_HTTP_PORT );
61+ setWaitStrategy (waitAllStrategy );
6362 }
6463
6564 @ Override
@@ -98,21 +97,18 @@ protected void setupCommandAndEnv() {
9897
9998 final String clusterName = getEnvMap ().getOrDefault ("PULSAR_PREFIX_clusterName" , "standalone" );
10099 final String response = String .format ("[\" %s\" ]" , clusterName );
101-
102- List <WaitStrategy > waitStrategies = new ArrayList <>();
103- waitStrategies .add (Wait .defaultWaitStrategy ());
104- waitStrategies .add (
100+ waitAllStrategy .withStrategy (
105101 Wait .forHttp (ADMIN_CLUSTERS_ENDPOINT ).forPort (BROKER_HTTP_PORT ).forResponsePredicate (response ::equals )
106102 );
103+
107104 if (transactionsEnabled ) {
108105 withEnv ("PULSAR_PREFIX_transactionCoordinatorEnabled" , "true" );
109- waitStrategies .add (Wait .forHttp (TRANSACTION_TOPIC_ENDPOINT ).forStatusCode (200 ).forPort (BROKER_HTTP_PORT ));
106+ waitAllStrategy .withStrategy (
107+ Wait .forHttp (TRANSACTION_TOPIC_ENDPOINT ).forStatusCode (200 ).forPort (BROKER_HTTP_PORT )
108+ );
110109 }
111110 if (functionsWorkerEnabled ) {
112- waitStrategies . add (Wait .forLogMessage (".*Function worker service started.*" , 1 ));
111+ waitAllStrategy . withStrategy (Wait .forLogMessage (".*Function worker service started.*" , 1 ));
113112 }
114- final WaitAllStrategy compoundedWaitStrategy = new WaitAllStrategy ();
115- waitStrategies .forEach (compoundedWaitStrategy ::withStrategy );
116- waitingFor (compoundedWaitStrategy );
117113 }
118114}
0 commit comments