You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2014/07/14 16:00:02 UTC
svn commit: r1610412 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit:
BaseTestCase.java JDBC.java
Author: kahatlen
Date: Mon Jul 14 14:00:02 2014
New Revision: 1610412
URL: http://svn.apache.org/r1610412
Log:
DERBY-6660: ResultSet assertion methods fail in upgrade tests
If an error happens in addRsToReport(), don't let it shadow the
original error.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1610412&r1=1610411&r2=1610412&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Mon Jul 14 14:00:02 2014
@@ -1153,12 +1153,23 @@ public abstract class BaseTestCase
*/
public static void fail(String msg, Throwable t)
throws AssertionFailedError {
+ throw newAssertionFailedError(msg, t);
+ }
- AssertionFailedError ae = new AssertionFailedError(msg);
- ae.initCause(t);
- throw ae;
+ /**
+ * Create a new AssertionFailedError linked to another Throwable.
+ *
+ * @param message message explaining the failure
+ * @param cause the cause of the failure
+ * @return an AssertionFailedError
+ */
+ public static AssertionFailedError newAssertionFailedError(
+ String message, Throwable cause) {
+ AssertionFailedError e = new AssertionFailedError(message);
+ e.initCause(cause);
+ return e;
}
-
+
/**
* assert a method from an executing test
*
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?rev=1610412&r1=1610411&r2=1610412&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Mon Jul 14 14:00:02 2014
@@ -1796,84 +1796,95 @@ public class JDBC {
List<String> seenRow,
ResultSet rs) throws SQLException {
- if (rs == null) {
- return new AssertionFailedError(afe.getMessage() + "\n<NULL>");
- }
-
- final int c = rsmd.getColumnCount();
- StringBuilder heading = new StringBuilder(" ");
- StringBuilder underline = new StringBuilder(" ");
-
- // Display column headings
- for (int i=1; i<= c; i++) {
- if (i > 1) {
- heading.append(",");
- underline.append(" ");
+ try {
+ if (rs == null) {
+ return BaseTestCase.newAssertionFailedError(
+ afe.getMessage() + "\n<NULL>", afe);
}
- int len = heading.length();
- heading.append(rsmd.getColumnLabel(i));
- len = heading.length() - len;
+ final int c = rsmd.getColumnCount();
+ StringBuilder heading = new StringBuilder(" ");
+ StringBuilder underline = new StringBuilder(" ");
+
+ // Display column headings
+ for (int i=1; i<= c; i++) {
+ if (i > 1) {
+ heading.append(",");
+ underline.append(" ");
+ }
- for (int j = len; j > 0; j--) {
- underline.append("-");
+ int len = heading.length();
+ heading.append(rsmd.getColumnLabel(i));
+ len = heading.length() - len;
+
+ for (int j = len; j > 0; j--) {
+ underline.append("-");
+ }
}
- }
- heading.append("\n");
- underline.append("\n");
+ heading.append("\n");
+ underline.append("\n");
- StringBuilder rowImg = new StringBuilder();
- rowImg.append(afe.getMessage()).
- append("\n\n").
- append(heading.toString()).
- append(underline.toString());
-
- if (!rs.isClosed()) {
- final int s = seenRow.size();
-
- // Get any rest of columns of current row
- for (int i=0; i < c - s; i++) {
- String column = null;
-
- try {
- column = rs.getString(s + i + 1);
- } catch (SQLException e) {
- // We may not yet have called next?
- if (e.getSQLState().equals("24000")) {
- if (rs.next()) {
- column = rs.getString(s + i + 1);
- } else {
- break;
+ StringBuilder rowImg = new StringBuilder();
+ rowImg.append(afe.getMessage()).
+ append("\n\n").
+ append(heading.toString()).
+ append(underline.toString());
+
+ if (!rs.isClosed()) {
+ final int s = seenRow.size();
+
+ // Get any rest of columns of current row
+ for (int i=0; i < c - s; i++) {
+ String column = null;
+
+ try {
+ column = rs.getString(s + i + 1);
+ } catch (SQLException e) {
+ // We may not yet have called next?
+ if (e.getSQLState().equals("24000")) {
+ if (rs.next()) {
+ column = rs.getString(s + i + 1);
+ } else {
+ break;
+ }
}
}
+ seenRow.add(column);
}
- seenRow.add(column);
- }
- if (seenRow.size() > 0) {
- seen.add(new ArrayList<String>(seenRow));
- seenRow.clear();
- }
+ if (seenRow.size() > 0) {
+ seen.add(new ArrayList<String>(seenRow));
+ seenRow.clear();
+ }
- // Get any remaining rows
- while (rs.next()) {
- for (int i = 0; i < c; i++) {
- seenRow.add(rs.getString(i + 1));
+ // Get any remaining rows
+ while (rs.next()) {
+ for (int i = 0; i < c; i++) {
+ seenRow.add(rs.getString(i + 1));
+ }
+ seen.add(new ArrayList<String>(seenRow));
+ seenRow.clear();
}
- seen.add(new ArrayList<String>(seenRow));
- seenRow.clear();
}
- }
- // Display data
- for (List<String> row : seen) {
- rowImg.append(" ").
- append(row.toString()).
- append("\n");
- }
+ // Display data
+ for (List<String> row : seen) {
+ rowImg.append(" ").
+ append(row.toString()).
+ append("\n");
+ }
- return new AssertionFailedError(rowImg.toString());
- }
+ return BaseTestCase.newAssertionFailedError(rowImg.toString(), afe);
+
+ } catch (Throwable t) {
+ // Something went wrong when adding the ResultSet to the error
+ // message. Don't return this error, as it would shadow the
+ // original error. Print it to help debugging.
+ BaseTestCase.printStackTrace(t);
+ // Return the original error.
+ return afe;
+ }
+ }
}