Search in sources :

Example 1 with JdbcSQLNonTransientConnectionException

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);
}
Also used : Server(org.h2.tools.Server) Statement(java.sql.Statement) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) Connection(java.sql.Connection) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) JdbcSQLNonTransientConnectionException(org.h2.jdbc.JdbcSQLNonTransientConnectionException) JdbcSQLNonTransientConnectionException(org.h2.jdbc.JdbcSQLNonTransientConnectionException) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Aggregations

IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 IdentifiedConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)1 ModelChainConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection)1 JdbcSQLNonTransientConnectionException (org.h2.jdbc.JdbcSQLNonTransientConnectionException)1 Server (org.h2.tools.Server)1