db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1586366 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest: NsTest.java utils/MemCheck.java
Date Thu, 10 Apr 2014 16:39:43 GMT
Author: rhillegas
Date: Thu Apr 10 16:39:43 2014
New Revision: 1586366

URL: http://svn.apache.org/r1586366
Log:
DERBY-6533: Give NsTest more defenses against OutOfMemoryErrors; commit derby-6533-04-outOfMemory.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/utils/MemCheck.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=1586366&r1=1586365&r2=1586366&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 Thu
Apr 10 16:39:43 2014
@@ -22,6 +22,7 @@ package org.apache.derbyTesting.system.n
 
 import java.util.HashMap;
 import java.util.Properties;
+import java.util.Date;
 import java.sql.SQLException;
 import java.sql.DriverManager;
 import java.io.IOException;
@@ -235,6 +236,10 @@ public class NsTest extends Thread
     private static  long        _startTimestamp;
     private static  long        _endTimestamp;
 
+    private static  long        _totalMemory;
+    private static  long        _freeMemory;
+    private static  Date        _lastMemoryCheckTime;
+
 	public static int numActiveTestThreads() {
 		int activeThreadCount=0;
 
@@ -250,6 +255,14 @@ public class NsTest extends Thread
 		return activeThreadCount;
 	}
 
+    public  static  void    updateMemoryTracker
+        ( long newTotalMemory, long newFreeMemory, Date newTimestamp )
+    {
+        _totalMemory = newTotalMemory;
+        _freeMemory = newFreeMemory;
+        _lastMemoryCheckTime = newTimestamp;
+    }
+
     public  static  void    updateSequenceTracker( long newValue )
     {
         _maxSequenceCounter = newValue;
@@ -649,6 +662,8 @@ public class NsTest extends Thread
 
         statisticsLogger.println( "\nMax sequence counter peeked at = " + _maxSequenceCounter
+ "\n" );
         
+        statisticsLogger.println( "\nLast total memory = " + _totalMemory + ", last free
memory = " + _freeMemory + " as measured at " + _lastMemoryCheckTime + "\n" );
+
         if ( _errors.size() > 0 )
         {
             countAndPrintSQLStates();
@@ -818,6 +833,7 @@ public class NsTest extends Thread
         if ( justCountErrors() )
         {
             addError( e );
+            vetError( e );
             return;
         }
         
@@ -846,8 +862,34 @@ public class NsTest extends Thread
 		logger.println("At this point - " + where
 				+ ", exception thrown was : " + e.getMessage());
 
+        vetError( e );
 	}
 
+    /**
+     * Analyze an error which is being reported. Currently, all this
+     * does is check for OutOfMemoryErrors. If we see an OutOfMemoryError,
+     * we kill the JVM since we will just get cascading noise after we exhaust
+     * memory.
+     */
+    private static  void    vetError( Throwable t )
+    {
+        if ( t == null ) { return; }
+        
+        if ( t instanceof OutOfMemoryError )
+        {
+            printStatistics();
+            Runtime.getRuntime().halt( 0 );
+        }
+
+        vetError( t.getCause() );
+
+        if ( t instanceof SQLException )
+        {
+            SQLException    sqlException = (SQLException) t;
+            vetError( sqlException.getNextException() );
+        }
+    }
+
 	public static String getDriverURL() {
 		if (driver_type.equalsIgnoreCase("DerbyClient")) {
 			return clientURL;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/MemCheck.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/MemCheck.java?rev=1586366&r1=1586365&r2=1586366&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/MemCheck.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/MemCheck.java
Thu Apr 10 16:39:43 2014
@@ -77,9 +77,12 @@ public class MemCheck extends Thread {
 		Runtime rt = null;
 		Date d = null;
 		rt = Runtime.getRuntime();
+        long    totalMemory = rt.totalMemory();
+        long    freeMemory = rt.freeMemory();
 		d = new Date();
-		NsTest.logger.println("total memory: " + rt.totalMemory() + " free: "
-				+ rt.freeMemory() + " " + d.toString());
+        NsTest.updateMemoryTracker( totalMemory, freeMemory, d );
+		NsTest.logger.println("total memory: " + totalMemory + " free: "
+				+ freeMemory + " " + d.toString());
 
 	}
 



Mime
View raw message