Skip to content

Feature/add support for random order of execution #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ utplsql run "my/Username"/"myP@ssword"@connectstring

-dbout - Enables DBMS_OUTPUT in the TestRunner-Session
(--dbms_output) Default: false

-random - Enables random order of test executions
(--random-test-order) Default: false

-seed - Sets the seed to use for random test execution order. If set, it sets -random to true
(--random-test-order-seed)
```

Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
46 changes: 39 additions & 7 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.slf4j.LoggerFactory;
import org.utplsql.api.*;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.compatibility.OptionalFeatures;
import org.utplsql.api.db.DefaultDatabaseInformation;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.OracleCreateStatmenetStuckException;
Expand Down Expand Up @@ -126,6 +127,18 @@ public class RunCommand implements ICommand {
)
private boolean enableDbmsOutput = false;

@Parameter(
names = {"-random", "--random-test-order"},
description = "Enables random order of test executions (default: DISABLED)"
)
private boolean randomTestOrder = false;

@Parameter(
names = {"-seed", "--random-test-order-seed"},
description = "Sets the seed to use for random test execution order. If set, it sets -random to true"
)
private Integer randomTestOrderSeed;

private CompatibilityProxy compatibilityProxy;
private ReporterFactory reporterFactory;
private ReporterManager reporterManager;
Expand Down Expand Up @@ -162,11 +175,7 @@ public int doRun() throws OracleCreateStatmenetStuckException {
initDatabase(dataSource);
reporterList = initReporters(dataSource);

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

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

Expand Down Expand Up @@ -228,7 +237,28 @@ public int run() {
return Cli.DEFAULT_ERROR_CODE;
}

private TestRunner newTestRunner( List<Reporter> reporterList) {
private void checkForCompatibility( Version utPlSqlVersion ) {
if (!OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(utPlSqlVersion) && failureExitCode != 1 ) {
System.out.println("You specified option `--failure-exit-code` but your database framework version (" +
utPlSqlVersion.getNormalizedString() + ") is not able to " +
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.");
}

if ( !OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSqlVersion) && randomTestOrder ) {
System.out.println("You specified option `-random` but your database framework version (" +
utPlSqlVersion.getNormalizedString() + ") is not able to " +
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.");
}

if ( !OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSqlVersion) && randomTestOrderSeed != null ) {
System.out.println("You specified option `-seed` but your database framework version (" +
utPlSqlVersion.getNormalizedString() + ") is not able to " +
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.");
}

}

TestRunner newTestRunner( List<Reporter> reporterList) {

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

Expand All @@ -241,7 +271,9 @@ private TestRunner newTestRunner( List<Reporter> reporterList) {
.failOnErrors(true)
.skipCompatibilityCheck(skipCompatibilityCheck)
.includeObjects(getObjectList(includeObjects))
.excludeObjects(getObjectList(excludeObjects));
.excludeObjects(getObjectList(excludeObjects))
.randomTestOrder(randomTestOrder)
.randomTestOrderSeed(randomTestOrderSeed);
}

private ArrayList<String> getObjectList(String includeObjects) {
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/org/utplsql/cli/RunCommandChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,4 @@ static void checkOracleI18nExists(Connection con) throws SQLException {
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
}
}

/** Returns a warning message if failureExitCode is specified but database version is too low
*
* @param failureExitCode
* @param databaseVersion
*/
static String getCheckFailOnErrorMessage(int failureExitCode, Version databaseVersion) {
if ( failureExitCode != 1 && !OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(databaseVersion)) {
return "Your database framework version (" + databaseVersion.getNormalizedString() + ") is not able to " +
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.";
}

return null;
}
}
34 changes: 34 additions & 0 deletions src/test/java/org/utplsql/cli/RunCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.utplsql.cli;

import org.junit.jupiter.api.Test;
import org.utplsql.api.TestRunnerOptions;
import org.utplsql.api.reporter.CoreReporters;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -92,4 +97,33 @@ void connectionString_asSysdba() {
assertEquals("sys as sysdba/mypass@connectstring/service",
runCmd.getConnectionInfo().getConnectionString());
}

@Test
void randomOrder_default() {
RunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString());

TestRunnerOptions options = runCmd.newTestRunner(new ArrayList<>()).getOptions();
assertThat(options.randomTestOrder, equalTo(false));
assertThat(options.randomTestOrderSeed, nullValue());
}

@Test
void randomOrder_withoutSeed() {
RunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
"-random");

TestRunnerOptions options = runCmd.newTestRunner(new ArrayList<>()).getOptions();
assertThat(options.randomTestOrder, equalTo(true));
assertThat(options.randomTestOrderSeed, nullValue());
}

@Test
void randomOrder_withSeed() {
RunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
"-seed=42");

TestRunnerOptions options = runCmd.newTestRunner(new ArrayList<>()).getOptions();
assertThat(options.randomTestOrder, equalTo(true));
assertThat(options.randomTestOrderSeed, equalTo(42));
}
}
21 changes: 0 additions & 21 deletions src/test/java/org/utplsql/cli/TestRunCommandChecker.java

This file was deleted.