Skip to content

Commit

Permalink
[FLINK-3072] [streaming] Ensure Derby server starts before running an…
Browse files Browse the repository at this point in the history
…y tests

Closes apache#1401
  • Loading branch information
gyfora committed Nov 25, 2015
1 parent 25ef324 commit 90c76ad
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void startDerbyServer() throws UnknownHostException, Exception {
server = new NetworkServerControl(InetAddress.getByName("localhost"), 1526, "flink", "flink");
server.start(null);
tempDir = new File(ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH, UUID.randomUUID().toString());
// We need to ensure that the Derby server starts properly before
// beginning the tests
DbStateBackendTest.ensureServerStarted(server);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public class DbStateBackendTest {
@BeforeClass
public static void startDerbyServer() throws UnknownHostException, Exception {
server = new NetworkServerControl(InetAddress.getByName("localhost"), 1527, "flink", "flink");

// Async call, we need to ensure that the server starts before leaving
// the method
server.start(null);

tempDir = new File(ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH, UUID.randomUUID().toString());
conf = new DbBackendConfig("flink", "flink",
"jdbc:derby:https://localhost:1527/" + tempDir.getAbsolutePath() + "/flinkDB1;create=true");
Expand All @@ -78,6 +82,29 @@ public static void startDerbyServer() throws UnknownHostException, Exception {

url1 = "jdbc:derby:https://localhost:1527/" + tempDir.getAbsolutePath() + "/flinkDB1;create=true";
url2 = "jdbc:derby:https://localhost:1527/" + tempDir.getAbsolutePath() + "/flinkDB2;create=true";

// We need to ensure that the Derby server starts properly before
// beginning the tests
ensureServerStarted(server);
}

public static void ensureServerStarted(NetworkServerControl server) throws InterruptedException {
// We try to ping the server 10 times with 1s sleep in between
// If the ping succeeds without exception the server started
int retry = 0;
while (true) {
if (retry < 10) {
try {
server.ping();
break;
} catch (Exception e) {
retry++;
Thread.sleep(1000);
}
} else {
throw new RuntimeException("Could not start the Derby server in 10 seconds.");
}
}
}

@AfterClass
Expand Down

0 comments on commit 90c76ad

Please sign in to comment.