@@ -127,7 +127,12 @@ private void delayedAddReporters() {
127
127
}
128
128
129
129
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 ) {
131
136
SQLException sqlException = (SQLException ) e ;
132
137
if (sqlException .getErrorCode () == SomeTestsFailedException .ERROR_CODE ) {
133
138
throw new SomeTestsFailedException (sqlException .getMessage (), e );
@@ -173,6 +178,23 @@ public void run(Connection conn) throws SQLException {
173
178
options .reporterList .add (new DocumentationReporter ().init (conn ));
174
179
}
175
180
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 {
176
198
ExecutorService executor = Executors .newSingleThreadExecutor ();
177
199
Callable <TestRunnerStatement > callable = () -> compatibilityProxy .getTestRunnerStatement (options , conn );
178
200
Future <TestRunnerStatement > future = executor .submit (callable );
@@ -181,21 +203,17 @@ public void run(Connection conn) throws SQLException {
181
203
TestRunnerStatement testRunnerStatement = null ;
182
204
try {
183
205
testRunnerStatement = future .get (2 , TimeUnit .SECONDS );
184
- logger .info ("Running tests" );
185
- testRunnerStatement .execute ();
186
- logger .info ("Running tests finished." );
187
- testRunnerStatement .close ();
188
206
} catch (TimeoutException e ) {
207
+ logger .error ("Detected Oracle driver stuck during Statement initialization" );
189
208
executor .shutdownNow ();
190
209
throw new OracleCreateStatmenetStuckException (e );
210
+ } catch (InterruptedException e ) {
211
+ handleException (e );
191
212
} catch (ExecutionException e ) {
192
213
handleException (e .getCause ());
193
- } catch (Exception e ) {
194
- if (testRunnerStatement != null ) testRunnerStatement .close ();
195
- handleException (e );
196
214
}
197
215
198
- executor . shutdown () ;
216
+ return testRunnerStatement ;
199
217
}
200
218
201
219
/**
0 commit comments