Skip to content

Commit e703c33

Browse files
committed
Refactor a bit
1 parent 782b643 commit e703c33

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/main/java/org/utplsql/api/TestRunner.java

+27-9
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ private void delayedAddReporters() {
127127
}
128128

129129
private void handleException(Throwable e) throws SQLException {
130-
if (e instanceof SQLException) {
130+
// Just pass exceptions already categorized
131+
if ( e instanceof UtPLSQLNotInstalledException ) throw (UtPLSQLNotInstalledException)e;
132+
else if ( e instanceof SomeTestsFailedException ) throw (SomeTestsFailedException)e;
133+
else if ( e instanceof OracleCreateStatmenetStuckException ) throw (OracleCreateStatmenetStuckException)e;
134+
// Categorize exceptions
135+
else if (e instanceof SQLException) {
131136
SQLException sqlException = (SQLException) e;
132137
if (sqlException.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
133138
throw new SomeTestsFailedException(sqlException.getMessage(), e);
@@ -173,6 +178,23 @@ public void run(Connection conn) throws SQLException {
173178
options.reporterList.add(new DocumentationReporter().init(conn));
174179
}
175180

181+
TestRunnerStatement testRunnerStatement = null;
182+
try {
183+
testRunnerStatement = initStatementWithTimeout(conn);
184+
logger.info("Running tests");
185+
testRunnerStatement.execute();
186+
logger.info("Running tests finished.");
187+
testRunnerStatement.close();
188+
} catch (OracleCreateStatmenetStuckException e) {
189+
// Don't close statement in this case for it will be stuck, too
190+
throw e;
191+
} catch (SQLException e) {
192+
if (testRunnerStatement != null) testRunnerStatement.close();
193+
handleException(e);
194+
}
195+
}
196+
197+
private TestRunnerStatement initStatementWithTimeout( Connection conn ) throws OracleCreateStatmenetStuckException, SQLException {
176198
ExecutorService executor = Executors.newSingleThreadExecutor();
177199
Callable<TestRunnerStatement> callable = () -> compatibilityProxy.getTestRunnerStatement(options, conn);
178200
Future<TestRunnerStatement> future = executor.submit(callable);
@@ -181,21 +203,17 @@ public void run(Connection conn) throws SQLException {
181203
TestRunnerStatement testRunnerStatement = null;
182204
try {
183205
testRunnerStatement = future.get(2, TimeUnit.SECONDS);
184-
logger.info("Running tests");
185-
testRunnerStatement.execute();
186-
logger.info("Running tests finished.");
187-
testRunnerStatement.close();
188206
} catch (TimeoutException e) {
207+
logger.error("Detected Oracle driver stuck during Statement initialization");
189208
executor.shutdownNow();
190209
throw new OracleCreateStatmenetStuckException(e);
210+
} catch (InterruptedException e) {
211+
handleException(e);
191212
} catch (ExecutionException e) {
192213
handleException(e.getCause());
193-
} catch (Exception e) {
194-
if (testRunnerStatement != null) testRunnerStatement.close();
195-
handleException(e);
196214
}
197215

198-
executor.shutdown();
216+
return testRunnerStatement;
199217
}
200218

201219
/**

0 commit comments

Comments
 (0)