Author: kmarsden Date: Thu Apr 21 03:24:51 2005 New Revision: 164027 URL: http://svn.apache.org/viewcvs?rev=164027&view=rev Log: Fix testRelative intermittent diff contributed by Shreyas Kaushik Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testRelative.out incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testRelative.out URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testRelative.out?rev=164027&r1=164026&r2=164027&view=diff ============================================================================== --- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testRelative.out (original) +++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testRelative.out Thu Apr 21 03:24:51 2005 @@ -4,6 +4,5 @@ Value=work3 Value=work1 isFirst=false isLast=false isAfterLast=true -FAIL -- unexpected exception -SQLSTATE(24000): SQL Exception: Invalid cursor state - no current row. -SQL Exception: Invalid cursor state - no current row. +PASS -- expected exception +SQLSTATE(24000): Invalid cursor state - no current row. Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java?rev=164027&r1=164026&r2=164027&view=diff ============================================================================== --- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java (original) +++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java Thu Apr 21 03:24:51 2005 @@ -7,18 +7,20 @@ import org.apache.derby.tools.JDBCDisplayUtil; public class testRelative { + + static final String EXPECTED_SQL_STATE = "24000"; + static Connection con; + static ResultSet rs; + static PreparedStatement stmt = null; + static PreparedStatement pStmt = null; + static Statement stmt1 = null; + static String returnValue = null; + public static void main(String[] args) { test1(args); } public static void test1(String []args) { - Connection con; - ResultSet rs; - PreparedStatement stmt = null; - PreparedStatement pStmt = null; - Statement stmt1 = null; - String returnValue = null; - System.out.println("Test testRelative starting"); try @@ -71,6 +73,14 @@ rs.relative(-2); returnValue = rs.getString("name"); System.out.println("Value="+returnValue); + } catch(SQLException se) { + unexpectedSQLException(se); + } catch(Throwable t) { + System.out.println("FAIL--unexpected exception: "+t.getMessage()); + t.printStackTrace(System.out); + } + + try { rs.relative(10); System.out.println("isFirst=" + rs.isFirst() + " isLast=" + rs.isLast() + " isAfterLast=" + rs.isAfterLast()); @@ -80,19 +90,36 @@ } catch(SQLException sqle) { dumpSQLExceptions(sqle); - sqle.printStackTrace(); } catch(Throwable e) { - System.out.println("FAIL -- unexpected exception: "+e); - e.printStackTrace(); + System.out.println("FAIL -- unexpected exception: "+e.getMessage()); + e.printStackTrace(System.out); } } - + + /** + * This is to print the expected Exception's details. We are here because we got an Exception + * when we expected one, but checking to see that we got the right one. + **/ static private void dumpSQLExceptions (SQLException se) { - System.out.println("FAIL -- unexpected exception"); + if( se.getSQLState() != null && (se.getSQLState().equals(EXPECTED_SQL_STATE))) { + System.out.println("PASS -- expected exception"); while (se != null) { - System.out.println("SQLSTATE("+se.getSQLState()+"): "+se); - se = se.getNextException(); + System.out.println("SQLSTATE("+se.getSQLState()+"): "+se.getMessage()); + se = se.getNextException(); } + } else { + System.out.println("FAIL--Unexpected SQLException: "+se.getMessage()); + se.printStackTrace(System.out); + } } -} \ No newline at end of file + + /** + * We are here because we got an exception when did not expect one. + * Hence printing the message and stack trace here. + **/ + static private void unexpectedSQLException(SQLException se) { + System.out.println("FAIL -- Unexpected Exception: "+ se.getMessage()); + se.printStackTrace(System.out); + } +}