Skip to content

Commit 7f22e43

Browse files
authored
Merge pull request #82 from utPLSQL/feature/add_support_for_random_order_of_execution
Feature/add support for random order of execution
2 parents e6625e3 + 894e46e commit 7f22e43

File tree

11 files changed

+166
-21
lines changed

11 files changed

+166
-21
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ env:
2828
- UTPLSQL_VERSION="v3.1.1"
2929
- UTPLSQL_VERSION="v3.1.2"
3030
- UTPLSQL_VERSION="v3.1.3"
31+
- UTPLSQL_VERSION="v3.1.6"
3132
- UTPLSQL_VERSION="develop"
3233
UTPLSQL_FILE="utPLSQL"
3334

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ public TestRunner setReporterFactory(ReporterFactory reporterFactory) {
118118
return this;
119119
}
120120

121+
public TestRunner randomTestOrder(boolean randomTestOrder ) {
122+
this.options.randomTestOrder = randomTestOrder;
123+
return this;
124+
}
125+
126+
public TestRunner randomTestOrderSeed( Integer seed ) {
127+
this.options.randomTestOrderSeed = seed;
128+
if ( seed != null ) this.options.randomTestOrder = true;
129+
return this;
130+
}
131+
132+
public TestRunnerOptions getOptions() { return options; }
133+
121134
private void delayedAddReporters() {
122135
if (reporterFactory != null) {
123136
reporterNames.forEach(this::addReporter);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ public class TestRunnerOptions {
2525
public boolean failOnErrors = false;
2626
public boolean skipCompatibilityCheck = false;
2727
public String clientCharacterSet = Charset.defaultCharset().toString();
28+
public boolean randomTestOrder = false;
29+
public Integer randomTestOrderSeed;
2830
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public class Version implements Comparable<Version> {
3131
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, null, true);
3232
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, null, true);
3333
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, null, true);
34+
public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, null, true);
3435
private final static Map<String, Version> knownVersions =
35-
Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6)
36+
Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6, V3_1_7)
3637
.collect(toMap(Version::toString, Function.identity()));
37-
public final static Version LATEST = V3_1_6;
38+
public final static Version LATEST = V3_1_7;
3839

3940
private final String origString;
4041
private final Integer major;

src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum OptionalFeatures {
1111
FAIL_ON_ERROR("3.0.3.1266", null),
1212
FRAMEWORK_COMPATIBILITY_CHECK("3.0.3.1266", null),
1313
CUSTOM_REPORTERS("3.1.0.1849", null),
14-
CLIENT_CHARACTER_SET("3.1.2.2130", null);
14+
CLIENT_CHARACTER_SET("3.1.2.2130", null),
15+
RANDOM_EXECUTION_ORDER("3.1.7.2795", null);
1516

1617
private final Version minVersion;
1718
private final Version maxVersion;

src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.sql.Connection;
66
import java.sql.SQLException;
7+
import java.sql.Types;
78

89
/**
910
* Provides the call to run tests for the most actual Framework version.
@@ -22,20 +23,24 @@ protected String getSql() {
2223
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
2324
String colorConsoleStr = Boolean.toString(options.colorConsole);
2425
String failOnErrors = Boolean.toString(options.failOnErrors);
26+
String randomExecutionOrder = Boolean.toString(options.randomTestOrder);
2527

2628
return
2729
"BEGIN " +
2830
"ut_runner.run(" +
29-
"a_paths => ?, " +
30-
"a_reporters => ?, " +
31-
"a_color_console => " + colorConsoleStr + ", " +
32-
"a_coverage_schemes => ?, " +
33-
"a_source_file_mappings => ?, " +
34-
"a_test_file_mappings => ?, " +
35-
"a_include_objects => ?, " +
36-
"a_exclude_objects => ?, " +
37-
"a_fail_on_errors => " + failOnErrors + ", " +
38-
"a_client_character_set => ?); " +
31+
"a_paths => ?, " +
32+
"a_reporters => ?, " +
33+
"a_color_console => " + colorConsoleStr + ", " +
34+
"a_coverage_schemes => ?, " +
35+
"a_source_file_mappings => ?, " +
36+
"a_test_file_mappings => ?, " +
37+
"a_include_objects => ?, " +
38+
"a_exclude_objects => ?, " +
39+
"a_fail_on_errors => " + failOnErrors + ", " +
40+
"a_client_character_set => ?, " +
41+
"a_random_test_order => " + randomExecutionOrder + ", " +
42+
"a_random_test_order_seed => ?"+
43+
"); " +
3944
"END;";
4045
}
4146

@@ -44,6 +49,11 @@ protected int createStatement() throws SQLException {
4449
int curParamIdx = super.createStatement();
4550

4651
callableStatement.setString(++curParamIdx, options.clientCharacterSet);
52+
if ( options.randomTestOrderSeed == null ) {
53+
callableStatement.setNull(++curParamIdx, Types.INTEGER);
54+
} else {
55+
callableStatement.setInt(++curParamIdx, options.randomTestOrderSeed);
56+
}
4757

4858
return curParamIdx;
4959
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.utplsql.api.testRunner;
2+
3+
import org.utplsql.api.TestRunnerOptions;
4+
5+
import java.sql.Connection;
6+
import java.sql.SQLException;
7+
8+
/**
9+
* Provides the call to run tests for the most actual Framework version.
10+
* Includes fail on error
11+
*
12+
* @author pesse
13+
*/
14+
class Pre317TestRunnerStatement extends AbstractTestRunnerStatement {
15+
16+
public Pre317TestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException {
17+
super(options, connection);
18+
}
19+
20+
@Override
21+
protected String getSql() {
22+
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
23+
String colorConsoleStr = Boolean.toString(options.colorConsole);
24+
String failOnErrors = Boolean.toString(options.failOnErrors);
25+
26+
return
27+
"BEGIN " +
28+
"ut_runner.run(" +
29+
"a_paths => ?, " +
30+
"a_reporters => ?, " +
31+
"a_color_console => " + colorConsoleStr + ", " +
32+
"a_coverage_schemes => ?, " +
33+
"a_source_file_mappings => ?, " +
34+
"a_test_file_mappings => ?, " +
35+
"a_include_objects => ?, " +
36+
"a_exclude_objects => ?, " +
37+
"a_fail_on_errors => " + failOnErrors + ", " +
38+
"a_client_character_set => ?); " +
39+
"END;";
40+
}
41+
42+
@Override
43+
protected int createStatement() throws SQLException {
44+
int curParamIdx = super.createStatement();
45+
46+
callableStatement.setString(++curParamIdx, options.clientCharacterSet);
47+
48+
return curParamIdx;
49+
}
50+
}

src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public static TestRunnerStatement getCompatibleTestRunnerStatement(Version datab
3535
stmt = new Pre303TestRunnerStatement(options, conn);
3636
} else if (databaseVersion.isLessThan(Version.V3_1_2)) {
3737
stmt = new Pre312TestRunnerStatement(options, conn);
38+
} else if (databaseVersion.isLessThan(Version.V3_1_7)) {
39+
stmt = new Pre317TestRunnerStatement(options, conn);
3840
}
3941

4042
} catch (InvalidVersionException ignored) {

src/test/java/org/utplsql/api/OptionalFeaturesIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ void clientCharset() throws SQLException, InvalidVersionException {
6464
assertFalse(available);
6565
}
6666
}
67+
68+
@Test
69+
void randomExecutionOrder() throws SQLException, InvalidVersionException {
70+
boolean available = OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(getConnection());
71+
72+
if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_7)) {
73+
assertTrue(available);
74+
} else {
75+
assertFalse(available);
76+
}
77+
}
6778
}

src/test/java/org/utplsql/api/TestRunnerIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void runWithoutCompatibilityCheck() throws SQLException, InvalidVersionException
3838
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
3939

4040
// We can only test this for the versions of the latest TestRunnerStatement-Change
41-
if ( OptionalFeatures.CLIENT_CHARACTER_SET.isAvailableFor(databaseInformation.getUtPlsqlFrameworkVersion(getConnection())) ) {
41+
if ( OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(databaseInformation.getUtPlsqlFrameworkVersion(getConnection())) ) {
4242
new TestRunner()
4343
.skipCompatibilityCheck(true)
4444
.run(getConnection());
@@ -78,4 +78,14 @@ void failOnErrors() throws SQLException, InvalidVersionException {
7878
}
7979
}
8080

81+
@Test
82+
void runWithRandomExecutionOrder() throws SQLException {
83+
CompatibilityProxy proxy = new CompatibilityProxy(getConnection());
84+
85+
new TestRunner()
86+
.randomTestOrder(true)
87+
.randomTestOrderSeed(123)
88+
.run(getConnection());
89+
}
90+
8191
}

0 commit comments

Comments
 (0)