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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Adding get connection method to connectioninfo
  • Loading branch information
viniciusam committed May 20, 2017
commit 9d507414b17eb8190c2b0ed891beabfa390163db
7 changes: 7 additions & 0 deletions src/main/java/io/github/utplsql/cli/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.beust.jcommander.ParameterException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -32,6 +35,10 @@ public class ConnectionInfo {
public ConnectionInfo() {
}

public Connection getConnection() throws SQLException {
return DriverManager.getConnection(getConnectionUrl(), getUser(), getPassword());
}

public ConnectionInfo parseConnectionString(String connectionString) throws ParameterException {
Pattern p = Pattern.compile(CONNSTR_PATTERN);
Matcher m = p.matcher(connectionString);
Expand Down
85 changes: 31 additions & 54 deletions src/main/java/io/github/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.github.utplsql.api.OutputBuffer;
import io.github.utplsql.api.OutputBufferLines;
import io.github.utplsql.api.TestRunner;
import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.types.DocumentationReporter;
import io.github.utplsql.api.utPLSQL;

import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -24,15 +22,23 @@ public class RunCommand {

@Parameter(
required = true, converter = ConnectionStringConverter.class,
arity = 1,
description = "user/pass@[[host][:port]/]db")
private List<ConnectionInfo> connectionInfoList;

@Parameter(
names = {"-p", "--path"},
description = "run suites/tests by path, format: \n" +
"schema or schema:[suite ...][.test] or schema[.suite ...][.test]")
"-p schema or schema:[suite ...][.test] or schema[.suite ...][.test]")
private List<String> testPaths;

@Parameter(
names = {"-f", "--format"},
variableArity = true,
description = "output reporter format: \n" +
"-f reporter_name [output_file] [console_output]")
private List<String> reporterParams;

public ConnectionInfo getConnectionInfo() {
return connectionInfoList.get(0);
}
Expand All @@ -44,78 +50,49 @@ public String getTestPaths() {
return (testPaths == null) ? null : String.join(",", testPaths);
}

public List<String> getReporterParams() {
return reporterParams;
}

public void run() throws Exception {
ConnectionInfo ci = getConnectionInfo();
final ConnectionInfo ci = getConnectionInfo();
System.out.println("Running Tests For: " + ci.toString());

utPLSQL.init(ci.getConnectionUrl(), ci.getUser(), ci.getPassword());

String tempTestPaths = getTestPaths();
if (tempTestPaths == null) tempTestPaths = ci.getUser();

final BaseReporter reporter = createDocumentationReporter();
final BaseReporter reporter = new DocumentationReporter();
final String testPaths = tempTestPaths;

try (Connection conn = ci.getConnection()) {
reporter.init(conn);
} catch (SQLException e) {
// TODO
e.printStackTrace();
}

ExecutorService executorService = Executors.newFixedThreadPool(2);

executorService.submit(() -> {
Connection conn = null;
try {
conn = utPLSQL.getConnection();
try (Connection conn = ci.getConnection()){
new TestRunner().run(conn, testPaths, reporter);

OutputBufferLines outputLines = new OutputBuffer(reporter.getReporterId())
.fetchAll(conn);

if (outputLines.getLines().size() > 0)
System.out.println(outputLines.toString());
} catch (SQLException e) {
// TODO
e.printStackTrace();
} finally {
if (conn != null)
try { conn.close(); } catch (SQLException ignored) {}
}
});

// executorService.submit(() -> {
// Connection conn = null;
// try {
// conn = utPLSQL.getConnection();
// OutputBufferLines outputLines;
// do {
// outputLines = new OutputBuffer(reporter.getReporterId())
// .fetchAvailable(conn);
//
// Thread.sleep(500);
//
// if (outputLines.getLines().size() > 0)
// System.out.println(outputLines.toString());
// } while (!outputLines.isFinished());
// } catch (SQLException | InterruptedException e) {
// // TODO
// e.printStackTrace();
// } finally {
// if (conn != null)
// try { conn.close(); } catch (SQLException ignored) {}
// }
// });
executorService.submit(() -> {
try (Connection conn = ci.getConnection()){
new OutputBuffer(reporter).printAvailable(conn, System.out);
} catch (SQLException e) {
// TODO
e.printStackTrace();
}
});

executorService.shutdown();
executorService.awaitTermination(60, TimeUnit.MINUTES);
}

private BaseReporter createDocumentationReporter() throws SQLException {
Connection conn = null;
try {
conn = utPLSQL.getConnection();
BaseReporter reporter = new DocumentationReporter();
reporter.setReporterId(utPLSQL.newSysGuid(conn));
return reporter;
} finally {
if (conn != null)
try { conn.close(); } catch (SQLException ignored) {}
}
}

}