forked from utPLSQL/utPLSQL-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunTestRunnerTask.java
More file actions
71 lines (65 loc) · 2.27 KB
/
RunTestRunnerTask.java
File metadata and controls
71 lines (65 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.utplsql.cli;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.DBHelper;
import org.utplsql.api.TestRunner;
import org.utplsql.api.exception.OracleCreateStatmenetStuckException;
import org.utplsql.api.exception.SomeTestsFailedException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
/**
* Runs the utPLSQL Test-Runner
* <p>
* Takes care of its connection.
* In case of an OracleCreateStatementStuckException it will abort the connection, otherwise close it.
*
* @author pesse
*/
public class RunTestRunnerTask implements Callable<Boolean> {
private static final Logger logger = LoggerFactory.getLogger(RunTestRunnerTask.class);
private DataSource dataSource;
private TestRunner testRunner;
private boolean enableDmbsOutput;
RunTestRunnerTask(DataSource dataSource, TestRunner testRunner, boolean enableDmbsOutput) {
this.dataSource = dataSource;
this.testRunner = testRunner;
this.enableDmbsOutput = enableDmbsOutput;
}
@Override
public Boolean call() throws Exception {
Connection conn = null;
try {
conn = dataSource.getConnection();
if (enableDmbsOutput) DBHelper.enableDBMSOutput(conn);
logger.info("Running tests now.");
logger.info("--------------------------------------");
testRunner.run(conn);
} catch (SomeTestsFailedException e) {
throw e;
} catch (OracleCreateStatmenetStuckException e) {
try {
conn.abort(Executors.newSingleThreadExecutor());
conn = null;
} catch (SQLException e1) {
logger.error(e1.getMessage(), e1);
}
throw e;
} catch (SQLException e) {
System.out.println(e.getMessage());
throw e;
} finally {
if (conn != null) {
try {
if (enableDmbsOutput) DBHelper.disableDBMSOutput(conn);
conn.close();
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
}
}
return true;
}
}