Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
</exclusion>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</exclusion>
<exclusion>
<groupId>com.oracle.jdbc</groupId>
<artifactId>orai18n</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -53,6 +61,18 @@
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>orai18n</artifactId>
<version>12.2.0.1</version>
<scope>compile</scope>
</dependency>

<!-- Test -->
<dependency>
Expand Down Expand Up @@ -139,8 +159,26 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven.oracle.com</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.oracle.com</url>
<layout>default</layout>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<url>https://maven.oracle.com</url>
</pluginRepository>
</pluginRepositories>

<profiles>
<profile>
<id>utPLSQL-local</id>
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/org/utplsql/cli/ReporterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
class ReporterManager {

private List<ReporterOptions> reporterOptionsList;
private List<Throwable> reporterGatherErrors;
private ExecutorService executorService;

ReporterManager(List<String> reporterParams ) {
initReporterOptionsList(reporterParams);
Expand Down Expand Up @@ -49,14 +51,33 @@ private void initReporterOptionsList( List<String> reporterParams ) {
}
}

private void abortGathering(Throwable e) {
addGatherError(e);
executorService.shutdownNow();
}

private void addGatherError( Throwable e ) {
if ( reporterGatherErrors == null ) {
reporterGatherErrors = new ArrayList<>();
}
reporterGatherErrors.add(e);
}

boolean haveGatherErrorsOccured() {
return reporterGatherErrors != null && !reporterGatherErrors.isEmpty();
}

List<Throwable> getGatherErrors() {
return reporterGatherErrors;
}

/** Initializes the reporters so we can use the id to gather results
*
* @param conn Active Connection
* @return List of Reporters
* @throws SQLException
*/
public List<Reporter> initReporters(Connection conn, ReporterFactory reporterFactory, CompatibilityProxy compatibilityProxy) throws SQLException
List<Reporter> initReporters(Connection conn, ReporterFactory reporterFactory, CompatibilityProxy compatibilityProxy) throws SQLException
{
final List<Reporter> reporterList = new ArrayList<>();

Expand All @@ -79,10 +100,14 @@ public List<Reporter> initReporters(Connection conn, ReporterFactory reporterFac
*
* @param executorService
* @param dataSource
* @param returnCode
*/
public void startReporterGatherers(ExecutorService executorService, final DataSource dataSource, final int[] returnCode)
void startReporterGatherers(ExecutorService executorService, final DataSource dataSource)
{
if ( this.executorService != null && !this.executorService.isShutdown())
throw new IllegalStateException("There is already a running executor service!");

this.executorService = executorService;

// TODO: Implement Init-check
// Gather each reporter results on a separate thread.
for (ReporterOptions ro : reporterOptionsList) {
Expand All @@ -103,9 +128,7 @@ public void startReporterGatherers(ExecutorService executorService, final DataSo

ro.getReporterObj().getOutputBuffer().printAvailable(conn, printStreams);
} catch (SQLException | FileNotFoundException e) {
System.out.println(e.getMessage());
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
executorService.shutdownNow();
abortGathering(e);
} finally {
if (fileOutStream != null)
fileOutStream.close();
Expand All @@ -114,9 +137,9 @@ public void startReporterGatherers(ExecutorService executorService, final DataSo
}
}

public List<ReporterOptions> getReporterOptionsList() {
List<ReporterOptions> getReporterOptionsList() {
return reporterOptionsList;
}

public int getNumberOfReporters() { return reporterOptionsList.size(); }
int getNumberOfReporters() { return reporterOptionsList.size(); }
}
126 changes: 74 additions & 52 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.*;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.db.DefaultDatabaseInformation;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.OracleCreateStatmenetStuckException;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.exception.DatabaseConnectionFailed;
import org.utplsql.cli.exception.ReporterTimeoutException;
import org.utplsql.cli.log.StringBlockFormatter;

import javax.sql.DataSource;
Expand All @@ -22,12 +25,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

/**
* Created by vinicius.moreira on 19/04/2017.
* Issues a Run-Command with all the options
*
* Uses an executor to start a RunTestRunnerTask and one ReporterGatheringTask per Reporter requested.
*
* @author vinicious moreira
* @author pesse
Expand Down Expand Up @@ -138,27 +141,17 @@ else if ( logDebug ) {
LoggerConfiguration.configure(level);
}

public int run() {
public int doRun() throws OracleCreateStatmenetStuckException {
init();
outputMainInformation();

HikariDataSource dataSource = null;
int returnCode = 0;
try {

final List<Reporter> reporterList;

final File baseDir = new File("").getAbsoluteFile();
final FileMapperOptions[] sourceMappingOptions = {null};
final FileMapperOptions[] testMappingOptions = {null};

final int[] returnCode = {0};

sourceMappingOptions[0] = getFileMapperOptionsByParamListItem(this.sourcePathParams, baseDir);
testMappingOptions[0] = getFileMapperOptionsByParamListItem(this.testPathParams, baseDir);

final List<String> finalIncludeObjectsList = getObjectList(includeObjects);
final List<String> finalExcludeObjectsList = getObjectList(excludeObjects);

final DataSource dataSource = DataSourceProvider.getDataSource(getConnectionInfo(), getReporterManager().getNumberOfReporters() + 1);
dataSource = (HikariDataSource) DataSourceProvider.getDataSource(getConnectionInfo(), getReporterManager().getNumberOfReporters() + 2);

initDatabase(dataSource);
reporterList = initReporters(dataSource);
Expand All @@ -172,48 +165,77 @@ public int run() {
ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());

// Run tests.
executorService.submit(() -> {
try (Connection conn = dataSource.getConnection()) {
TestRunner testRunner = new TestRunner()
.addPathList(testPaths)
.addReporterList(reporterList)
.sourceMappingOptions(sourceMappingOptions[0])
.testMappingOptions(testMappingOptions[0])
.colorConsole(this.colorConsole)
.failOnErrors(true)
.skipCompatibilityCheck(skipCompatibilityCheck)
.includeObjects(finalIncludeObjectsList)
.excludeObjects(finalExcludeObjectsList);

logger.info("Running tests now.");
logger.info("--------------------------------------");
testRunner.run(conn);
} catch (SomeTestsFailedException e) {
returnCode[0] = this.failureExitCode;
} catch (SQLException e) {
System.out.println(e.getMessage());
returnCode[0] = Cli.DEFAULT_ERROR_CODE;
executorService.shutdownNow();
}
});
Future<Boolean> future = executorService.submit(new RunTestRunnerTask(dataSource, newTestRunner(reporterList)));

// Gather each reporter results on a separate thread.
getReporterManager().startReporterGatherers(executorService, dataSource, returnCode);

executorService.shutdown();
executorService.awaitTermination(timeoutInMinutes, TimeUnit.MINUTES);
getReporterManager().startReporterGatherers(executorService, dataSource);

try {
future.get(timeoutInMinutes, TimeUnit.MINUTES);
} catch (TimeoutException e) {
executorService.shutdownNow();
throw new ReporterTimeoutException(timeoutInMinutes);
} catch (ExecutionException e) {
if (e.getCause() instanceof SomeTestsFailedException) {
returnCode = failureExitCode;
} else {
executorService.shutdownNow();
throw e.getCause();
}
} catch (InterruptedException e) {
executorService.shutdownNow();
throw e;
}
finally {
executorService.shutdown();
if (!executorService.awaitTermination(timeoutInMinutes, TimeUnit.MINUTES)) {
throw new ReporterTimeoutException(timeoutInMinutes);
}
}

logger.info("--------------------------------------");
logger.info("All tests done.");

return returnCode[0];
}
catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
} catch ( OracleCreateStatmenetStuckException e ) {
throw e;
} catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed | ReporterTimeoutException e ) {
System.out.println(e.getMessage());
} catch (Exception e) {
returnCode = Cli.DEFAULT_ERROR_CODE;
} catch (Throwable e) {
e.printStackTrace();
returnCode = Cli.DEFAULT_ERROR_CODE;
} finally {
if ( dataSource != null )
dataSource.close();
}
return 1;
return returnCode;
}

public int run() {
for ( int i = 1; i<5; i++ ) {
try {
return doRun();
} catch (OracleCreateStatmenetStuckException e) {
logger.warn("WARNING: Caught Oracle stuck during creation of Runner-Statement. Retrying ({})", i);
}
}

return Cli.DEFAULT_ERROR_CODE;
}

private TestRunner newTestRunner( List<Reporter> reporterList) {

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

return new TestRunner()
.addPathList(testPaths)
.addReporterList(reporterList)
.sourceMappingOptions(getFileMapperOptionsByParamListItem(this.sourcePathParams, baseDir))
.testMappingOptions(getFileMapperOptionsByParamListItem(this.testPathParams, baseDir))
.colorConsole(this.colorConsole)
.failOnErrors(true)
.skipCompatibilityCheck(skipCompatibilityCheck)
.includeObjects(getObjectList(includeObjects))
.excludeObjects(getObjectList(excludeObjects));
}

private ArrayList<String> getObjectList(String includeObjects) {
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/org/utplsql/cli/RunTestRunnerTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.utplsql.cli;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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
*
* 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;

RunTestRunnerTask(DataSource dataSource, TestRunner testRunner) {
this.dataSource = dataSource;
this.testRunner = testRunner;
}

@Override
public Boolean call() throws Exception {
Connection conn = null;
try {
conn = dataSource.getConnection();
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 {
conn.close();
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
}
}
return true;
}
}
Loading