@@ -64,7 +64,7 @@ public class ContainerQueryRunner
6464 private static final String PRESTO_COORDINATOR_IMAGE = System .getProperty ("coordinatorImage" , "presto-coordinator:latest" );
6565 private static final String PRESTO_WORKER_IMAGE = System .getProperty ("workerImage" , "presto-worker:latest" );
6666 private static final String CONTAINER_TIMEOUT = System .getProperty ("containerTimeout" , "120" );
67- private static final String CLUSTER_SHUTDOWN_TIMEOUT = System .getProperty ("clusterShutDownTimeout" , "1000 " );
67+ private static final String CLUSTER_SHUTDOWN_TIMEOUT = System .getProperty ("clusterShutDownTimeout" , "10 " );
6868 private static final String BASE_DIR = System .getProperty ("user.dir" );
6969 private static final int DEFAULT_COORDINATOR_PORT = 8080 ;
7070 private static final String TPCH_CATALOG = "tpch" ;
@@ -73,7 +73,7 @@ public class ContainerQueryRunner
7373 private static final Logger logger = Logger .getLogger (ContainerQueryRunner .class .getName ());
7474 private final GenericContainer <?> coordinator ;
7575 private final List <GenericContainer <?>> workers = new ArrayList <>();
76- private final Optional <GenericContainer <?>> sidecar ;
76+ private Optional <GenericContainer <?>> sidecar ;
7777 private final int coordinatorPort ;
7878 private final String catalog ;
7979 private final String schema ;
@@ -116,26 +116,19 @@ public ContainerQueryRunner(int numberOfWorkers, boolean isNativeCluster, boolea
116116 coordinator .start ();
117117 startWorkers (numberOfWorkers , isNativeCluster , isSidecarEnabled );
118118
119- if (isSidecarEnabled ) {
119+ TimeUnit .SECONDS .sleep (5 );
120+
121+ if (isSidecarEnabled && !isSidecarDelayed ) {
120122 GenericContainer <?> sidecarContainer = createSidecar (7777 + numberOfWorkers , "sidecar" );
121- if (isSidecarDelayed ) {
122- Thread .sleep (10000 );
123- }
124123 sidecarContainer .start ();
125124 this .sidecar = Optional .of (sidecarContainer );
125+ // First, wait for coordinator to become ACTIVE
126+ waitForCoordinatorActive (coordinator .getHost (), coordinator .getMappedPort (coordinatorPort ), 60 , 5 );
126127 }
127128 else {
128129 this .sidecar = Optional .empty ();
129130 }
130131
131- // Need some extra time for sidecar to register otherwise it throws sidecar not found error
132- if (isSidecarEnabled && !isSidecarDelayed ) {
133- TimeUnit .SECONDS .sleep (5 );
134- }
135- else {
136- TimeUnit .SECONDS .sleep (5 );
137- }
138-
139132 startCoordinatorAndLogUI ();
140133 initializeConnection ();
141134 cleanupDirectories (numberOfWorkers , isNativeCluster , isSidecarEnabled );
@@ -183,9 +176,6 @@ private void initializeConnection()
183176 String dockerHostIp = coordinator .getHost ();
184177 int mappedPort = coordinator .getMappedPort (coordinatorPort );
185178
186- // First, wait for coordinator to become ACTIVE
187- waitForCoordinatorActive (dockerHostIp , mappedPort , 60 , 5 );
188-
189179 String url = String .format ("jdbc:presto://%s:%s/%s/%s?%s" ,
190180 dockerHostIp ,
191181 mappedPort ,
@@ -201,10 +191,9 @@ private void initializeConnection()
201191 }
202192 }
203193
204- private void waitForCoordinatorActive (String host , int port , int maxRetries , int retryDelaySeconds )
194+ public void waitForCoordinatorActive (String host , int port , int maxRetries , int retryDelaySeconds )
205195 {
206196 String endpoint = String .format ("http://%s:%d/v1/info/state" , host , port );
207-
208197 for (int attempt = 1 ; attempt <= maxRetries ; attempt ++) {
209198 try {
210199 HttpURLConnection connection = (HttpURLConnection ) new URL (endpoint ).openConnection ();
@@ -319,6 +308,13 @@ private GenericContainer<?> createNativeWorker(int port, String nodeId, boolean
319308 .waitingFor (Wait .forLogMessage (".*Announcement succeeded: HTTP 202.*" , 1 ));
320309 }
321310
311+ public void waitForSidecarRegistration () throws IOException {
312+ GenericContainer <?> sidecarContainer = createSidecar (7777 + numberOfWorkers , "sidecar" );
313+ sidecarContainer .start ();
314+ this .sidecar = Optional .of (sidecarContainer );
315+ waitForCoordinatorActive (coordinator .getHost (), coordinator .getMappedPort (coordinatorPort ), 60 , 5 );
316+ }
317+
322318 @ Override
323319 public void close ()
324320 {
0 commit comments