db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1587581 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest: NsTest.java tester/Tester1.java tester/Tester2.java tester/TesterObject.java
Date Tue, 15 Apr 2014 13:38:32 GMT
Author: rhillegas
Date: Tue Apr 15 13:38:32 2014
New Revision: 1587581

URL: http://svn.apache.org/r1587581
Log:
DERBY-6533: Add more defensive code to NsTest; commit derby-6533-05-aa-dieQuickly.diff.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java?rev=1587581&r1=1587580&r2=1587581&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java Tue
Apr 15 13:38:32 2014
@@ -89,6 +89,8 @@ public class NsTest extends Thread
 
     private static  final   String  ERROR_BANNER1 = "//////////////////////////////////////////////////////////////\n";
     private static  final   String  ERROR_BANNER2 = "//    ";
+
+    public  static  final   String  DEAD_CONNECTION = "08003";
     
     
 	public static final String dbName = "nstestdb";
@@ -910,6 +912,19 @@ public class NsTest extends Thread
 
 	}
 
+    /** Return true if the connection is dead */
+    public  static  boolean deadConnection( Throwable t )
+    {
+        if ( t instanceof SQLException )
+        {
+            SQLException    se = (SQLException) t;
+
+            if ( DEAD_CONNECTION.equals( se.getSQLState() ) ) { return true; }
+        }
+
+        return false;
+    }
+
 	public static void printUsage()
     {
         _statisticsAlreadyPrinted = true;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java?rev=1587581&r1=1587580&r2=1587581&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java
Tue Apr 15 13:38:32 2014
@@ -71,6 +71,10 @@ public class Tester1 extends TesterObjec
 			NsTest.logger.println("FAIL: " + getThread_id()
 					+ "'s setAutoCommit() failed:");
 			printException("setting AutoCommit", e);
+
+            // if you can't change the autocommit state, the connection is unusable.
+            // get out of here.
+            return;
 		}
 
 		// also set isolation level to Connection.TRANSACTION_READ_UNCOMMITTED
@@ -104,6 +108,9 @@ public class Tester1 extends TesterObjec
 					printException("doSelectOperation()", e);
                     if ( NsTest.justCountErrors() ) { NsTest.printException( Tester1.class.getName(),
e ); }
 					else { e.printStackTrace( NsTest.logger ); }
+
+                    // if the connection is dead, there's no point in hanging around
+                    if ( NsTest.deadConnection( e ) ) { return; }
 				}
 				break;
 
@@ -112,6 +119,7 @@ public class Tester1 extends TesterObjec
 			case 3: // do Insert/Update/Delete operations
 				for (int j = 0; j < NsTest.MAX_LOW_STRESS_ROWS; j++) {
 					doIUDOperation();
+                    if ( deadConnection() ) { return; }
 				}
 				break;
 			}
@@ -126,6 +134,10 @@ public class Tester1 extends TesterObjec
 				NsTest.logger
 						.println("FAIL: " + getThread_id() + "'s commit() failed:");
 				printException("committing Xn in Tester1", e);
+
+                // if you can't commit, the connection is unusable.
+                // get out of here.
+                return;
 			}
 		}// end of for (int i=0;...)
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java?rev=1587581&r1=1587580&r2=1587581&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java
Tue Apr 15 13:38:32 2014
@@ -76,6 +76,10 @@ public class Tester2 extends TesterObjec
 				NsTest.logger.println("FAIL: " + getThread_id()
 						+ "'s setAutoCommit() failed:");
 				printException("setting AutoCommit in Tester2", e);
+                
+                // if you can't change the autocommit state, the connection is unusable.
+                // get out of here.
+                return;
 			}
 
 			//also set isolation level to Connection.TRANSACTION_READ_UNCOMMITTED to reduce number
of
@@ -120,6 +124,10 @@ public class Tester2 extends TesterObjec
 					NsTest.logger.println("FAIL: " + getThread_id()
 							+ "'s commit() failed:");
 					printException("committing Xn in Tester2", e);
+                    
+                    // if you can't commit, the connection is unusable.
+                    // get out of here.
+                    return;
 				}
 			}//end of for(int numOp=1...)
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java?rev=1587581&r1=1587580&r2=1587581&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
Tue Apr 15 13:38:32 2014
@@ -39,6 +39,7 @@ import org.apache.derbyTesting.system.ns
 public class TesterObject {
 
 	private String thread_id;
+    private boolean _deadConnection = false;
 
 	protected Connection connex = null;
 
@@ -152,6 +153,7 @@ public class TesterObject {
 					NsTest.addStats(NsTest.FAILED_INSERT, 1);
 			} catch (Exception e) {
 				printException("executing add_one_row()", e);
+                if ( NsTest.deadConnection( e ) ) { markDeadConnection(); }
 			}
 
 			break;
@@ -224,7 +226,10 @@ public class TesterObject {
 			printException(
 					"FAIL: doSelectOperation() had problems creating/executing query",
 					e);
-			s.close();
+            if ( rSet != null ) { rSet.close(); }
+			if ( s != null ) { s.close(); }
+
+            return numRowsSelected;
 		}
 
 		if (rSet != null) {
@@ -295,8 +300,8 @@ public class TesterObject {
 		        .println("FAIL: doSelectOperation() had problems working over the ResultSet");
 		        NsTest.addStats(NsTest.FAILED_SELECT, 1);
 		        printException("processing ResultSet during row data retrieval", e);
-		        rSet.close();
-		        s.close();
+		        if ( rSet != null ) { rSet.close(); }
+		        if ( s != null ) { s.close(); }
 		        NsTest.logger.println("Closed the select statement");
 		    }
 		}
@@ -379,4 +384,8 @@ public class TesterObject {
 		return thread_id;
 	}
 
+    public  void    markDeadConnection() { _deadConnection = true; }
+
+    public  boolean deadConnection() { return _deadConnection; }
+
 }



Mime
View raw message