Skip to content

Commit 9489334

Browse files
authored
Merge pull request #142 from utPLSQL/feature/add_support_for_random_order_of_execution
Feature/add support for random order of execution Add support for RandomOrder execution. 2 new parameters: `-random` `-seed=value`
2 parents e6b59db + 3fc12f5 commit 9489334

File tree

6 files changed

+85
-42
lines changed

6 files changed

+85
-42
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ utplsql run "my/Username"/"myP@ssword"@connectstring
147147
148148
-dbout - Enables DBMS_OUTPUT in the TestRunner-Session
149149
(--dbms_output) Default: false
150+
151+
-random - Enables random order of test executions
152+
(--random-test-order) Default: false
153+
154+
-seed - Sets the seed to use for random test execution order. If set, it sets -random to true
155+
(--random-test-order-seed)
150156
```
151157

152158
Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
<version>${junit.jupiter.version}</version>
8282
<scope>test</scope>
8383
</dependency>
84+
<dependency>
85+
<groupId>org.hamcrest</groupId>
86+
<artifactId>hamcrest</artifactId>
87+
<version>2.1</version>
88+
<scope>test</scope>
89+
</dependency>
8490

8591
</dependencies>
8692

src/main/java/org/utplsql/cli/RunCommand.java

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.slf4j.LoggerFactory;
88
import org.utplsql.api.*;
99
import org.utplsql.api.compatibility.CompatibilityProxy;
10+
import org.utplsql.api.compatibility.OptionalFeatures;
1011
import org.utplsql.api.db.DefaultDatabaseInformation;
1112
import org.utplsql.api.exception.DatabaseNotCompatibleException;
1213
import org.utplsql.api.exception.OracleCreateStatmenetStuckException;
@@ -126,6 +127,18 @@ public class RunCommand implements ICommand {
126127
)
127128
private boolean enableDbmsOutput = false;
128129

130+
@Parameter(
131+
names = {"-random", "--random-test-order"},
132+
description = "Enables random order of test executions (default: DISABLED)"
133+
)
134+
private boolean randomTestOrder = false;
135+
136+
@Parameter(
137+
names = {"-seed", "--random-test-order-seed"},
138+
description = "Sets the seed to use for random test execution order. If set, it sets -random to true"
139+
)
140+
private Integer randomTestOrderSeed;
141+
129142
private CompatibilityProxy compatibilityProxy;
130143
private ReporterFactory reporterFactory;
131144
private ReporterManager reporterManager;
@@ -162,11 +175,7 @@ public int doRun() throws OracleCreateStatmenetStuckException {
162175
initDatabase(dataSource);
163176
reporterList = initReporters(dataSource);
164177

165-
// Output a message if --failureExitCode is set but database framework is not capable of
166-
String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getUtPlsqlVersion());
167-
if (msg != null) {
168-
System.out.println(msg);
169-
}
178+
checkForCompatibility(compatibilityProxy.getUtPlsqlVersion());
170179

171180
ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());
172181

@@ -228,7 +237,28 @@ public int run() {
228237
return Cli.DEFAULT_ERROR_CODE;
229238
}
230239

231-
private TestRunner newTestRunner( List<Reporter> reporterList) {
240+
private void checkForCompatibility( Version utPlSqlVersion ) {
241+
if (!OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(utPlSqlVersion) && failureExitCode != 1 ) {
242+
System.out.println("You specified option `--failure-exit-code` but your database framework version (" +
243+
utPlSqlVersion.getNormalizedString() + ") is not able to " +
244+
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.");
245+
}
246+
247+
if ( !OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSqlVersion) && randomTestOrder ) {
248+
System.out.println("You specified option `-random` but your database framework version (" +
249+
utPlSqlVersion.getNormalizedString() + ") is not able to " +
250+
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.");
251+
}
252+
253+
if ( !OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSqlVersion) && randomTestOrderSeed != null ) {
254+
System.out.println("You specified option `-seed` but your database framework version (" +
255+
utPlSqlVersion.getNormalizedString() + ") is not able to " +
256+
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.");
257+
}
258+
259+
}
260+
261+
TestRunner newTestRunner( List<Reporter> reporterList) {
232262

233263
final File baseDir = new File("").getAbsoluteFile();
234264

@@ -241,7 +271,9 @@ private TestRunner newTestRunner( List<Reporter> reporterList) {
241271
.failOnErrors(true)
242272
.skipCompatibilityCheck(skipCompatibilityCheck)
243273
.includeObjects(getObjectList(includeObjects))
244-
.excludeObjects(getObjectList(excludeObjects));
274+
.excludeObjects(getObjectList(excludeObjects))
275+
.randomTestOrder(randomTestOrder)
276+
.randomTestOrderSeed(randomTestOrderSeed);
245277
}
246278

247279
private ArrayList<String> getObjectList(String includeObjects) {

src/main/java/org/utplsql/cli/RunCommandChecker.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,4 @@ static void checkOracleI18nExists(Connection con) throws SQLException {
2727
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
2828
}
2929
}
30-
31-
/** Returns a warning message if failureExitCode is specified but database version is too low
32-
*
33-
* @param failureExitCode
34-
* @param databaseVersion
35-
*/
36-
static String getCheckFailOnErrorMessage(int failureExitCode, Version databaseVersion) {
37-
if ( failureExitCode != 1 && !OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(databaseVersion)) {
38-
return "Your database framework version (" + databaseVersion.getNormalizedString() + ") is not able to " +
39-
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.";
40-
}
41-
42-
return null;
43-
}
4430
}

src/test/java/org/utplsql/cli/RunCommandTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package org.utplsql.cli;
22

33
import org.junit.jupiter.api.Test;
4+
import org.utplsql.api.TestRunnerOptions;
45
import org.utplsql.api.reporter.CoreReporters;
56

7+
import java.util.ArrayList;
68
import java.util.List;
79

10+
import static org.hamcrest.CoreMatchers.equalTo;
11+
import static org.hamcrest.CoreMatchers.nullValue;
12+
import static org.hamcrest.MatcherAssert.assertThat;
813
import static org.junit.jupiter.api.Assertions.*;
914

1015
/**
@@ -92,4 +97,33 @@ void connectionString_asSysdba() {
9297
assertEquals("sys as sysdba/mypass@connectstring/service",
9398
runCmd.getConnectionInfo().getConnectionString());
9499
}
100+
101+
@Test
102+
void randomOrder_default() {
103+
RunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString());
104+
105+
TestRunnerOptions options = runCmd.newTestRunner(new ArrayList<>()).getOptions();
106+
assertThat(options.randomTestOrder, equalTo(false));
107+
assertThat(options.randomTestOrderSeed, nullValue());
108+
}
109+
110+
@Test
111+
void randomOrder_withoutSeed() {
112+
RunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
113+
"-random");
114+
115+
TestRunnerOptions options = runCmd.newTestRunner(new ArrayList<>()).getOptions();
116+
assertThat(options.randomTestOrder, equalTo(true));
117+
assertThat(options.randomTestOrderSeed, nullValue());
118+
}
119+
120+
@Test
121+
void randomOrder_withSeed() {
122+
RunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
123+
"-seed=42");
124+
125+
TestRunnerOptions options = runCmd.newTestRunner(new ArrayList<>()).getOptions();
126+
assertThat(options.randomTestOrder, equalTo(true));
127+
assertThat(options.randomTestOrderSeed, equalTo(42));
128+
}
95129
}

src/test/java/org/utplsql/cli/TestRunCommandChecker.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)