Check url connection to assume startup state. for both grpc and rest
endpoints
package com.quorum.tessera.test;
import com.quorum.tessera.config.CommunicationType;
+import com.quorum.tessera.config.Config;
+import com.quorum.tessera.config.util.JaxbUtil;
import com.quorum.tessera.io.FilesDelegate;
import com.quorum.tessera.test.util.ElUtil;
@@ -9,6 +11,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.net.URL;
+import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -24,6 +27,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
+import javax.ws.rs.core.UriBuilder;
public class ProcessManager {
@@ -133,22 +137,75 @@ public class ProcessManager {
}
});
- CountDownLatch startUpLatch = new CountDownLatch(1);
final String nodeId = nodeAlias;
+
+ final Config config = JaxbUtil.unmarshal(configFile.openStream(), Config.class);
+
+ final URL bindingUrl = config.getServerConfig().getBindingUri().toURL();
+
+ CountDownLatch startUpLatch = new CountDownLatch(communicationType == CommunicationType.GRPC ? 2 : 1);
+
+ if (communicationType == CommunicationType.GRPC) {
+ URL grpcUrl = UriBuilder.fromUri(config.getServerConfig().getBindingUri())
+ .port(config.getServerConfig().getGrpcPort())
+ .build().toURL();
+
+ executorService.submit(() -> {
+
+ while (true) {
+ try {
+ URLConnection conn = grpcUrl.openConnection();
+ conn.connect();
+ System.out.println(grpcUrl + " started. ");
+ startUpLatch.countDown();
+ return;
+ } catch (IOException ex) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(200L);
+ } catch (InterruptedException ex1) {
+ }
+ }
+ }
+
+ });
+ }
+
+ executorService.submit(() -> {
+
+ while (true) {
+ try {
+ URLConnection conn = bindingUrl.openConnection();
+ conn.connect();
+ System.out.println(bindingUrl + " started. ");
+ startUpLatch.countDown();
+ return;
+ } catch (IOException ex) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(200L);
+ } catch (InterruptedException ex1) {
+ }
+ }
+ }
+
+ });
+
+ boolean started = startUpLatch.await(2, TimeUnit.MINUTES);
+
+ if (!started) {
+ System.err.println(bindingUrl + " Not started. ");
+ }
+
executorService.submit(() -> {
try {
int exitCode = process.waitFor();
if (0 != exitCode) {
System.err.println("Node " + nodeId + " exited with code " + exitCode);
}
- startUpLatch.countDown();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
});
- startUpLatch.await(15, TimeUnit.SECONDS);
-
}
public void kill(String nodeAlias) throws Exception {
@@ -167,7 +224,7 @@ public class ProcessManager {
}
public static void main(String[] args) throws Exception {
- System.setProperty("application.jar", "/Users/mark/Projects/tessera/tessera-app/target/tessera-app-0.7-SNAPSHOT-app.jar");
+ System.setProperty("application.jar", "/Users/mark/Projects/tessera/tessera-app/target/tessera-app-0.8-SNAPSHOT-app.jar");
ProcessManager pm = new ProcessManager(CommunicationType.REST);
pm.startNodes();
