3
3
import com .beust .jcommander .Parameter ;
4
4
import com .beust .jcommander .Parameters ;
5
5
import com .zaxxer .hikari .HikariDataSource ;
6
- import com .zaxxer .hikari .pool .HikariProxyConnection ;
7
6
import org .slf4j .Logger ;
8
7
import org .slf4j .LoggerFactory ;
9
8
import org .utplsql .api .*;
26
25
import java .util .ArrayList ;
27
26
import java .util .Arrays ;
28
27
import java .util .List ;
29
- import java .util .concurrent .ExecutorService ;
30
- import java .util .concurrent .Executors ;
31
- import java .util .concurrent .Future ;
32
- import java .util .concurrent .TimeUnit ;
28
+ import java .util .concurrent .*;
33
29
34
30
/**
35
- * Created by vinicius.moreira on 19/04/2017.
31
+ * Issues a Run-Command with all the options
32
+ *
33
+ * Uses an executor to start a RunTestRunnerTask and one ReporterGatheringTask per Reporter requested.
36
34
*
37
35
* @author vinicious moreira
38
36
* @author pesse
@@ -143,18 +141,17 @@ else if ( logDebug ) {
143
141
LoggerConfiguration .configure (level );
144
142
}
145
143
146
- public int doRun () {
144
+ public int doRun () throws OracleCreateStatmenetStuckException {
147
145
init ();
148
146
outputMainInformation ();
149
147
148
+ HikariDataSource dataSource = null ;
149
+ int returnCode = 0 ;
150
150
try {
151
151
152
152
final List <Reporter > reporterList ;
153
153
154
- final File baseDir = new File ("" ).getAbsoluteFile ();
155
- final int [] returnCode = {0 };
156
-
157
- final DataSource dataSource = DataSourceProvider .getDataSource (getConnectionInfo (), getReporterManager ().getNumberOfReporters () + 2 );
154
+ dataSource = (HikariDataSource ) DataSourceProvider .getDataSource (getConnectionInfo (), getReporterManager ().getNumberOfReporters () + 2 );
158
155
159
156
initDatabase (dataSource );
160
157
reporterList = initReporters (dataSource );
@@ -168,81 +165,61 @@ public int doRun() {
168
165
ExecutorService executorService = Executors .newFixedThreadPool (1 + reporterList .size ());
169
166
170
167
// Run tests.
171
- Future <Integer > future = executorService .submit (() -> {
172
- Connection conn = null ;
173
- try {
174
- conn = dataSource .getConnection ();
175
- TestRunner testRunner = newTestRunner (reporterList );
176
-
177
- logger .info ("Running tests now." );
178
- logger .info ("--------------------------------------" );
179
- testRunner .run (conn );
180
- } catch (SomeTestsFailedException e ) {
181
- returnCode [0 ] = this .failureExitCode ;
182
- }
183
- catch (OracleCreateStatmenetStuckException e ) {
184
- try {
185
- conn .abort (Executors .newSingleThreadExecutor ());
186
- conn = null ;
187
- } catch (SQLException e1 ) {
188
- logger .error (e1 .getMessage (), e1 );
189
- }
190
- executorService .shutdownNow ();
191
- return 3 ;
192
- }
193
- catch (SQLException e ) {
194
- System .out .println (e .getMessage ());
195
- //returnCode[0] = Cli.DEFAULT_ERROR_CODE;
196
- executorService .shutdownNow ();
197
- return Cli .DEFAULT_ERROR_CODE ;
198
- }
199
- finally {
200
- if ( conn != null ) {
201
- try {
202
- conn .close ();
203
- } catch (SQLException e ) {
204
- e .printStackTrace ();
205
- }
206
- }
207
- }
208
- return 0 ;
209
- });
168
+ Future <Boolean > future = executorService .submit (new RunTestRunnerTask (dataSource , newTestRunner (reporterList )));
210
169
211
170
// Gather each reporter results on a separate thread.
212
171
getReporterManager ().startReporterGatherers (executorService , dataSource );
213
172
214
- Integer mainTestResult = future . get ();
215
-
216
- executorService . shutdown ();
217
- if ( ! executorService .awaitTermination ( timeoutInMinutes , TimeUnit . MINUTES ) ) {
173
+ try {
174
+ future . get ( timeoutInMinutes , TimeUnit . MINUTES );
175
+ } catch ( TimeoutException e ) {
176
+ executorService .shutdownNow ();
218
177
throw new ReporterTimeoutException (timeoutInMinutes );
178
+ } catch (ExecutionException e ) {
179
+ if (e .getCause () instanceof SomeTestsFailedException ) {
180
+ returnCode = failureExitCode ;
181
+ } else {
182
+ executorService .shutdownNow ();
183
+ throw e .getCause ();
184
+ }
185
+ } catch (InterruptedException e ) {
186
+ executorService .shutdownNow ();
187
+ throw e ;
188
+ }
189
+ finally {
190
+ executorService .shutdown ();
191
+ if (!executorService .awaitTermination (timeoutInMinutes , TimeUnit .MINUTES )) {
192
+ throw new ReporterTimeoutException (timeoutInMinutes );
193
+ }
219
194
}
220
195
221
196
logger .info ("--------------------------------------" );
222
197
logger .info ("All tests done." );
223
-
224
- ((HikariDataSource )dataSource ).close ();
225
-
226
- return mainTestResult ;
227
- }
228
- catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | ReporterTimeoutException e ) {
198
+ } catch ( OracleCreateStatmenetStuckException e ) {
199
+ throw e ;
200
+ } catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | ReporterTimeoutException e ) {
229
201
System .out .println (e .getMessage ());
230
- } catch (Exception e ) {
202
+ returnCode = Cli .DEFAULT_ERROR_CODE ;
203
+ } catch (Throwable e ) {
231
204
e .printStackTrace ();
205
+ returnCode = Cli .DEFAULT_ERROR_CODE ;
206
+ } finally {
207
+ if ( dataSource != null )
208
+ dataSource .close ();
232
209
}
233
- return Cli . DEFAULT_ERROR_CODE ;
210
+ return returnCode ;
234
211
}
235
212
236
213
public int run () {
237
- int i = 1 ;
238
- int exitCode = doRun ();
239
- // Retry
240
- while ( exitCode == 3 && i <10 ) {
241
- logger .warn ("Retry" );
242
- exitCode = doRun ();
243
- i ++;
214
+ for ( int i = 1 ; i <5 ; i ++ ) {
215
+ try {
216
+ return doRun ();
217
+ } catch (OracleCreateStatmenetStuckException e ) {
218
+ logger .warn ("WARNING: Caught Oracle stuck during creation of Runner-Statement. Retrying ({})" , i );
219
+ }
244
220
}
245
- return exitCode ;
221
+
222
+ return Cli .DEFAULT_ERROR_CODE ;
246
223
}
247
224
248
225
private TestRunner newTestRunner ( List <Reporter > reporterList ) {
0 commit comments