Bugfix/watchdog create statement stuck issue20 by pesse · Pull Request #77 · utPLSQL/utPLSQL-java-api
/** * Created by Vinicius Avellar on 12/04/2017.
private void handleException(Throwable e) throws SQLException { // Just pass exceptions already categorized if ( e instanceof UtPLSQLNotInstalledException ) throw (UtPLSQLNotInstalledException)e; else if ( e instanceof SomeTestsFailedException ) throw (SomeTestsFailedException)e; else if ( e instanceof OracleCreateStatmenetStuckException ) throw (OracleCreateStatmenetStuckException)e; // Categorize exceptions else if (e instanceof SQLException) { SQLException sqlException = (SQLException) e; if (sqlException.getErrorCode() == SomeTestsFailedException.ERROR_CODE) { throw new SomeTestsFailedException(sqlException.getMessage(), e); } else if (((SQLException) e).getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { throw new UtPLSQLNotInstalledException(sqlException); } else { throw sqlException; } } else { throw new SQLException("Unknown exception, wrapping: " + e.getMessage(), e); } }
public void run(Connection conn) throws SQLException {
logger.info("TestRunner initialized");
try (TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) { TestRunnerStatement testRunnerStatement = null; try { testRunnerStatement = initStatementWithTimeout(conn); logger.info("Running tests"); testRunnerStatement.execute(); logger.info("Running tests finished."); testRunnerStatement.close(); } catch (OracleCreateStatmenetStuckException e) { // Don't close statement in this case for it will be stuck, too throw e; } catch (SQLException e) { if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) { throw new SomeTestsFailedException(e.getMessage(), e); } else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { throw new UtPLSQLNotInstalledException(e); } else { throw e; } if (testRunnerStatement != null) testRunnerStatement.close(); handleException(e); } }
private TestRunnerStatement initStatementWithTimeout( Connection conn ) throws OracleCreateStatmenetStuckException, SQLException { ExecutorService executor = Executors.newSingleThreadExecutor(); Callable<TestRunnerStatement> callable = () -> compatibilityProxy.getTestRunnerStatement(options, conn); Future<TestRunnerStatement> future = executor.submit(callable);
// We want to leave the statement open in case of stuck scenario TestRunnerStatement testRunnerStatement = null; try { testRunnerStatement = future.get(2, TimeUnit.SECONDS); } catch (TimeoutException e) { logger.error("Detected Oracle driver stuck during Statement initialization"); executor.shutdownNow(); throw new OracleCreateStatmenetStuckException(e); } catch (InterruptedException e) { handleException(e); } catch (ExecutionException e) { handleException(e.getCause()); }
return testRunnerStatement; }
/**