use of org.h2.jdbc.JdbcSQLNonTransientConnectionException in project legend-engine by finos.
the class TestExecutionScope method setupTestServer.
public static TestExecutionScope setupTestServer(RichIterable<? extends String> sqls, Scope scope) throws SQLException {
// Start Test Database
int relationalDBPort = generatePort();
RelationalExecutor executor;
Server server;
try {
executor = buildTestExecutor(relationalDBPort);
server = AlloyH2Server.startServer(relationalDBPort);
} catch (JdbcSQLNonTransientConnectionException b) {
scope.span().log("exception opening port" + relationalDBPort + ". Retrying with another port.");
relationalDBPort = generatePort();
executor = buildTestExecutor(relationalDBPort);
server = AlloyH2Server.startServer(relationalDBPort);
}
scope.span().log("In memory database started on port " + relationalDBPort);
try {
// Set Up Data
try (Connection connection = executor.getConnectionManager().getTestDatabaseConnection()) {
sqls.forEach(new CheckedProcedure<String>() {
@Override
public void safeValue(String s) throws Exception {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate(s);
}
}
});
}
scope.span().log("Data inserted in the test database");
} catch (Exception e) {
server.shutdown();
server.stop();
throw e;
}
return new TestExecutionScope(relationalDBPort, server);
}
Aggregations