Skip to content

#87 - Debug utPLSQL tests #106

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 36 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
76f40dd
comment to integrate in IntelliJ and handle OSGi errors
PhilippSalvisberg May 31, 2020
a26d6f4
extend .gitignore regarding IntelliJ, SonarQube and more
PhilippSalvisberg May 31, 2020
cd109b2
change resource files to UTF-8 and escape umlauts
PhilippSalvisberg May 31, 2020
b3b53c7
simplify test, compare length instead of content
PhilippSalvisberg May 31, 2020
b21f2bf
add debug icon
PhilippSalvisberg Jun 1, 2020
3088dda
add debug test label to resource bundle
PhilippSalvisberg Jun 1, 2020
39cb25d
add dependencies to run debugger to pom.xml
PhilippSalvisberg Jun 1, 2020
3bf3fe8
add getProduceReportPlsql to be passed to the PL/SQL debugger
PhilippSalvisberg Jun 1, 2020
2cd156c
add "Debug utPLSQL test" to context menu of Connects window and editor
PhilippSalvisberg Jun 1, 2020
56e28af
ensure that realtime reporter is/stays visible during a test run
PhilippSalvisberg Jun 1, 2020
22c2898
simplify code
PhilippSalvisberg Jun 1, 2020
8ed6eb1
call the PL/SQL debugger when testing via realtime reporter
PhilippSalvisberg Jun 1, 2020
a6cea12
call the PL/SQL debugger when testing via worksheet
PhilippSalvisberg Jun 1, 2020
5006b7c
extend controller to handle debug action in the Connections window an…
PhilippSalvisberg Jun 1, 2020
4734c40
refactor, simplify
PhilippSalvisberg Jun 2, 2020
372fe3b
add debug icon and debug utPLSQL test context menu for realtime reporter
PhilippSalvisberg Jun 2, 2020
402d1b4
create own context, add debugging flag, change enableDebugging signature
PhilippSalvisberg Jun 2, 2020
4a39c8d
use new enableDebugging signature
PhilippSalvisberg Jun 2, 2020
7a5a945
add toolbar button and context menu to debug utPLSQL tests
PhilippSalvisberg Jun 2, 2020
2e8cf80
add stop icon
PhilippSalvisberg Jun 2, 2020
b25cdc9
add stop icon and text regarding stop utPLSQL run in realtime reporter
PhilippSalvisberg Jun 2, 2020
08b3efa
add jetbrains annotations
PhilippSalvisberg Jun 2, 2020
45c9a43
add explicit spring-core dependency
PhilippSalvisberg Jun 2, 2020
ee5eb1c
intitialize counter with zero values
PhilippSalvisberg Jun 2, 2020
7dd053e
initialize counter
PhilippSalvisberg Jun 2, 2020
94d8a3e
rename getDisabled to isDisabled
PhilippSalvisberg Jun 2, 2020
5ca644e
refactor, simplify
PhilippSalvisberg Jun 2, 2020
bfe8f19
make getTotalNumberOfCompletedTests more robust
PhilippSalvisberg Jun 2, 2020
d0d6ef1
always abort connections do not ask if connection is closed
PhilippSalvisberg Jun 2, 2020
175f821
add consumer connection of a run, to be closed in realtime reporter
PhilippSalvisberg Jun 2, 2020
cd16c05
refactor, simplify
PhilippSalvisberg Jun 2, 2020
6d69770
add signature to pass timeout in consumeReport
PhilippSalvisberg Jun 2, 2020
c3393b5
adapt test cases to match new counter default values
PhilippSalvisberg Jun 2, 2020
6f90c82
change timeout to 1h for debugging sessions, close session on abort p…
PhilippSalvisberg Jun 2, 2020
1ac611f
refactor, simplify
PhilippSalvisberg Jun 2, 2020
7867223
add stop button to toolbar in realtime reporter
PhilippSalvisberg Jun 2, 2020
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
50 changes: 35 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
# Compiled class file
*.class
*._trace
*.xtendbin
*.DS_Store

# Log file
*.log
**/target
**/bin
**/test-output
**/xtend-gen
**/.sonar
**/.project
**/.classpath
**/.settings
**/.idea

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #

# Package Files
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Xtend
*._trace
*.xtendbin
**/xtend-gen

# SonarQube
**/.sonar
**/.scannerwork

# Eclipse / Visual Studio Code
.project
.classpath
**/.settings

# IntelliJ
**/.idea
*.iml

# macOS
*.DS_Store

# Windows
Thumbs.db

# Targets
**/target
**/bin
14 changes: 12 additions & 2 deletions sqldev/extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@
<property name="Category">Code-Editor</property>
</properties>
</action>
<action id="utplsql.debug">
<properties>
<property name="Name">${MENU_DEBUG_TEST_LABEL}</property>
<property name="SmallIcon">res:/org/utplsql/sqldev/resources/images/debug.png</property>
<property name="Category">Code-Editor</property>
</properties>
</action>
<action id="utplsql.generate">
<properties>
<property name="Name">${MENU_GENERATE_TEST_LABEL}</property>
Expand All @@ -120,6 +127,7 @@
<update-rule rule="always-enabled">
<action id="utplsql.test" />
<action id="utplsql.coverage" />
<action id="utplsql.debug" />
<action id="utplsql.generate" />
</update-rule>
</update-rules>
Expand All @@ -132,7 +140,8 @@
id="UTPLSQL_MENU" weight="2.0">
<item action-ref="utplsql.test" weight="1.0" />
<item action-ref="utplsql.coverage" weight="1.1" />
<item action-ref="utplsql.generate" weight="1.2" />
<item action-ref="utplsql.debug" weight="1.2" />
<item action-ref="utplsql.generate" weight="1.3" />
</section>
</menu>
</context-menu-hook>
Expand All @@ -142,7 +151,8 @@
<section xmlns="http://jcp.org/jsr/198/extension-manifest"
id="UTPLSQL_MENU" weight="2.0">
<item action-ref="utplsql.test" weight="12.1" />
<item action-ref="utplsql.coverage" weight="12.2" />
<item action-ref="utplsql.debug" weight="12.2" />
<item action-ref="utplsql.coverage" weight="12.3" />
</section>
</menu>
</context-menu-hook>
Expand Down
38 changes: 37 additions & 1 deletion sqldev/pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!--suppress ALL -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -142,6 +143,20 @@
<scope>system</scope>
<systemPath>${sqldev.basedir}/jdev/extensions/oracle.jdeveloper.java.core.jar</systemPath>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>oracle.jdeveloper.runner.jar</artifactId>
<version>13.0.0</version>
<scope>system</scope>
<systemPath>${sqldev.basedir}/jdev/extensions/oracle.jdeveloper.runner.jar</systemPath>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>oracle.ide.runner</artifactId>
<version>19.3.0</version>
<scope>system</scope>
<systemPath>${sqldev.basedir}/ide/extensions/oracle.ide.runner.jar</systemPath>
</dependency>
<!-- SQL Developer specific dependencies part 2 (used for tests only) -->
<dependency>
<groupId>oracle</groupId>
Expand Down Expand Up @@ -172,6 +187,12 @@
<artifactId>spring-jdbc</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
<dependency>
<!-- transitive reference, but IntelliJ wants to have it explicit (to avoid warnings) -->
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
<dependency>
<!-- used for HtmlUtils.htmlEscape in RunnerPanel -->
<groupId>org.springframework</groupId>
Expand All @@ -191,7 +212,13 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<!-- Build Settings -->
<build>
Expand Down Expand Up @@ -370,6 +397,13 @@
</configuration>
</plugin>
<plugin>
<!-- builds the OSGi bundle including MANIFEST.MF with build version number and properties -->
<!-- IMPORTANT NOTICE: -->
<!-- disable OSGi facets in IntelliJ (2020.1) to get rid of the following types of warnings/errors: -->
<!-- - Warning:osgi: [org.utplsql.sqldev] Host ...= for this fragment/require bundle cannot be found on the classpath -->
<!-- - Warning:osgi: [org.utplsql.sqldev] No translation found for macro: ... -->
<!-- - Error:osgi: [org.utplsql.sqldev] Input file does not exist: target/classes/META-INF/extension.xml -->
<!-- - Error:osgi: [org.utplsql.sqldev] Invalid value for Bundle-Version, ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} does not match \d{1,9}(\.\d{1,9}(\.\d{1,9}(\.[-\w]+)?)?)? -->
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.1</version>
Expand Down Expand Up @@ -405,9 +439,11 @@
oracle.javatools,
oracle.javatools-nodeps,
oracle.jdeveloper.db.connection,
oracle.jdeveloper.runner,
oracle.idert,
oracle.ide,
oracle.ide.db,
oracle.ide.runner,
oracle.sqldeveloper,
oracle.sqldeveloper.utils,
oracle.sqldeveloper.worksheet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

import java.io.IOException;
import java.io.StringReader;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Logger;

Expand Down Expand Up @@ -54,12 +52,13 @@

import oracle.jdbc.OracleTypes;

@SuppressWarnings("StringBufferReplaceableByString")
public class RealtimeReporterDao {
private static final Logger logger = Logger.getLogger(RealtimeReporterDao.class.getName());
private static final int FIRST_VERSION_WITH_REALTIME_REPORTER = 3001004;
private final XMLTools xmlTools = new XMLTools();
private Connection conn;
private JdbcTemplate jdbcTemplate;
private final Connection conn;
private final JdbcTemplate jdbcTemplate;

public RealtimeReporterDao(final Connection conn) {
this.conn = conn;
Expand All @@ -72,12 +71,23 @@ public boolean isSupported() {
.normalizedUtPlsqlVersionNumber() >= RealtimeReporterDao.FIRST_VERSION_WITH_REALTIME_REPORTER;
}

public void produceReport(final String reporterId, final List<String> pathList) {
// used for execution via PL/SQL Debugger
public String getProduceReportPlsql(final String reporterId, final List<String> pathList) {
return getProduceReportPlsql(reporterId, pathList, false);
}

private String getProduceReportPlsql(final String reporterId, final List<String> pathList, boolean useBindVariable) {
StringBuilder sb = new StringBuilder();
sb.append("DECLARE\n");
sb.append(" l_reporter ut_realtime_reporter := ut_realtime_reporter();\n");
sb.append("BEGIN\n");
sb.append(" l_reporter.set_reporter_id(?);\n");
if (useBindVariable) {
sb.append(" l_reporter.set_reporter_id(?);\n");
} else {
sb.append(" l_reporter.set_reporter_id('");
sb.append(reporterId);
sb.append("');\n");
}
sb.append(" l_reporter.output_buffer.init();\n");
sb.append(" sys.dbms_output.enable(NULL);\n");
sb.append(" ut_runner.run(\n");
Expand All @@ -88,7 +98,11 @@ public void produceReport(final String reporterId, final List<String> pathList)
sb.append(" );\n");
sb.append(" sys.dbms_output.disable;\n");
sb.append("END;");
final String plsql = sb.toString();
return sb.toString();
}

public void produceReport(final String reporterId, final List<String> pathList) {
final String plsql = getProduceReportPlsql(reporterId, pathList, true);
final Object[] binds = { reporterId };
jdbcTemplate.update(plsql, binds);
}
Expand Down Expand Up @@ -135,35 +149,37 @@ public void produceReportWithCoverage(final String realtimeReporterId, final Str
}

public void consumeReport(final String reporterId, final RealtimeReporterEventConsumer consumer) {
consumeReport(reporterId, consumer, 60);
}

public void consumeReport(final String reporterId, final RealtimeReporterEventConsumer consumer, final int timeoutSeconds) {
StringBuilder sb = new StringBuilder();
sb.append("DECLARE\n");
sb.append(" l_reporter ut_realtime_reporter := ut_realtime_reporter();\n");
sb.append("BEGIN\n");
sb.append(" l_reporter.set_reporter_id(?);\n");
sb.append(" ? := l_reporter.get_lines_cursor();\n");
sb.append(" ? := l_reporter.get_lines_cursor(a_initial_timeout => ?);\n");
sb.append("END;");
final String plsql = sb.toString();
jdbcTemplate.setFetchSize(1);
try {
jdbcTemplate.execute(plsql, new CallableStatementCallback<Void>() {
@Override
public Void doInCallableStatement(final CallableStatement cs) throws SQLException {
cs.setString(1, reporterId);
cs.registerOutParameter(2, OracleTypes.CURSOR);
cs.execute();
final ResultSet rs = (ResultSet) cs.getObject(2);
while (rs.next()) {
final String itemType = rs.getString("item_type");
final Clob textClob = rs.getClob("text");
final String textString = textClob.getSubString(1, ((int) textClob.length()));
final RealtimeReporterEvent event = convert(itemType, textString);
if (event != null) {
consumer.process(event);
}
jdbcTemplate.execute(plsql, (CallableStatementCallback<Void>) cs -> {
cs.setString(1, reporterId);
cs.setInt(3, timeoutSeconds);
cs.registerOutParameter(2, OracleTypes.CURSOR);
cs.execute();
final ResultSet rs = (ResultSet) cs.getObject(2);
while (rs.next()) {
final String itemType = rs.getString("item_type");
final Clob textClob = rs.getClob("text");
final String textString = textClob.getSubString(1, ((int) textClob.length()));
final RealtimeReporterEvent event = convert(itemType, textString);
if (event != null) {
consumer.process(event);
}
rs.close();
return null;
}
rs.close();
return null;
});
} finally {
jdbcTemplate.setFetchSize(UtplsqlDao.FETCH_ROWS);
Expand All @@ -179,24 +195,21 @@ public String getHtmlCoverage(final String reporterId) {
sb.append(" ? := l_reporter.get_lines_cursor();\n");
sb.append("END;");
final String plsql = sb.toString();
return jdbcTemplate.execute(plsql, new CallableStatementCallback<String>() {
@Override
public String doInCallableStatement(final CallableStatement cs) throws SQLException {
cs.setString(1, reporterId);
cs.registerOutParameter(2, OracleTypes.CURSOR);
cs.execute();
final StringBuilder sb = new StringBuilder();
final ResultSet rs = (ResultSet) cs.getObject(2);
while (rs.next()) {
final String text = rs.getString("text");
if (text != null) {
sb.append(text);
sb.append('\n');
}
return jdbcTemplate.execute(plsql, (CallableStatementCallback<String>) cs -> {
cs.setString(1, reporterId);
cs.registerOutParameter(2, OracleTypes.CURSOR);
cs.execute();
final StringBuilder sb1 = new StringBuilder();
final ResultSet rs = (ResultSet) cs.getObject(2);
while (rs.next()) {
final String text = rs.getString("text");
if (text != null) {
sb1.append(text);
sb1.append('\n');
}
rs.close();
return sb.toString();
}
rs.close();
return sb1.toString();
});
}

Expand Down Expand Up @@ -231,14 +244,15 @@ private RealtimeReporterEvent convert(final String itemType, final String text)
}
}

@SuppressWarnings("DuplicatedCode")
private RealtimeReporterEvent convertToPreRunEvent(final Document doc) {
final PreRunEvent event = new PreRunEvent();
final Node totalNumberOfTestsNode = xmlTools.getNode(doc, "/event/totalNumberOfTests");
String totalNumberOfTestsTextContent = null;
if (totalNumberOfTestsNode != null) {
totalNumberOfTestsTextContent = totalNumberOfTestsNode.getTextContent();
}
event.setTotalNumberOfTests(Integer.valueOf(totalNumberOfTestsTextContent));
event.setTotalNumberOfTests(Integer.valueOf(totalNumberOfTestsTextContent != null ? totalNumberOfTestsTextContent : "0"));
final NodeList nodes = xmlTools.getNodeList(doc, "/event/items/*");
for (int i = 0; i < nodes.getLength(); i++) {
final Node node = nodes.item(i);
Expand Down Expand Up @@ -311,6 +325,7 @@ private RealtimeReporterEvent convertToPostTestEvent(final Document doc) {
return event;
}

@SuppressWarnings("DuplicatedCode")
private void populate(final Suite suite, final Node node) {
if (node instanceof Element) {
suite.setId(xmlTools.getAttributeValue(node, "id"));
Expand Down
Loading