beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject [46/50] [abbrv] incubator-beam git commit: [BEAM-1057] Fix JDBC test derby startup issues
Date Tue, 06 Dec 2016 16:41:36 GMT
[BEAM-1057] Fix JDBC test derby startup issues


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/58916b94
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/58916b94
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/58916b94

Branch: refs/heads/gearpump-runner
Commit: 58916b94ada142d63d16a315da58f88184995f10
Parents: c22b97d
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Nov 28 16:47:37 2016 -0500
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Sun Dec 4 07:17:42 2016 +0100

----------------------------------------------------------------------
 .../org/apache/beam/sdk/io/jdbc/JdbcIOTest.java | 26 +++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/58916b94/sdks/java/io/jdbc/src/test/java/org/apache/beam/sdk/io/jdbc/JdbcIOTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/io/jdbc/src/test/java/org/apache/beam/sdk/io/jdbc/JdbcIOTest.java b/sdks/java/io/jdbc/src/test/java/org/apache/beam/sdk/io/jdbc/JdbcIOTest.java
index fe574af..d09929d 100644
--- a/sdks/java/io/jdbc/src/test/java/org/apache/beam/sdk/io/jdbc/JdbcIOTest.java
+++ b/sdks/java/io/jdbc/src/test/java/org/apache/beam/sdk/io/jdbc/JdbcIOTest.java
@@ -20,7 +20,9 @@ package org.apache.beam.sdk.io.jdbc;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.PrintWriter;
 import java.io.Serializable;
+import java.io.StringWriter;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.sql.Connection;
@@ -73,7 +75,29 @@ public class JdbcIOTest implements Serializable {
     System.setProperty("derby.stream.error.file", "target/derby.log");
 
     derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
-    derbyServer.start(null);
+    StringWriter out = new StringWriter();
+    derbyServer.start(new PrintWriter(out));
+    boolean started = false;
+    int count = 0;
+    // Use two different methods to detect when server is started:
+    // 1) Check the server stdout for the "started" string
+    // 2) wait up to 15 seconds for the derby server to start based on a ping
+    // on faster machines and networks, this may return very quick, but on slower
+    // networks where the DNS lookups are slow, this may take a little time
+    while (!started && count < 30) {
+      if (out.toString().contains("started")) {
+        started = true;
+      } else {
+        count++;
+        Thread.sleep(500);
+        try {
+          derbyServer.ping();
+          started = true;
+        } catch (Throwable t) {
+          //ignore, still trying to start
+        }
+      }
+    }
 
     dataSource = new ClientDataSource();
     dataSource.setCreateDatabase("create");


Mime
View raw message