db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1141924 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: suites/ tests/jdbcapi/ tests/memory/
Date Fri, 01 Jul 2011 12:54:31 GMT
Author: kmarsden
Date: Fri Jul  1 12:54:30 2011
New Revision: 1141924

URL: http://svn.apache.org/viewvc?rev=1141924&view=rev
Log:
DERBY-3337 convert jdbcapi/derbyStress.java to JUnit
DERBY-4200 client side OutOfMemoryError running derbnetclientmats:jdbcapi/derbyStress

Convert test to JUnit and also run the finalizer periodically if freeMemory() falls below
500K.  The converted tests is no longer called derbyStress. It is now memory.MemoryLeakFixes
and runs with the junit-lowmem target or can be run directly with junit.textui.TestRunner
with -Xmx16M.  



Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/MemoryLeakFixesTest.java
      - copied, changed from r1136551, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress_app.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbyall.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude?rev=1141924&r1=1141923&r2=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
Fri Jul  1 12:54:30 2011
@@ -4,6 +4,4 @@
 # 			see DERBY-326 and DERBY-550 issues
 jdbcapi/rsgetXXXcolumnNames.java
 jdbcapi/SetQueryTimeoutTest.java
-# excluding jdbcapi/derbyStress.java - jcc runs out of memory with this test
-jdbcapi/derbyStress.java
 largedata/LobLimits.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude?rev=1141924&r1=1141923&r2=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
Fri Jul  1 12:54:30 2011
@@ -9,7 +9,6 @@
 # stress/stress.multi - exits suite
 # following fail for various reasons, many related to not being able to connect:
 #  lang/wisconsin.java
-#  jdbcapi/derbyStress.java
 #  jdbcapi/maxfieldsize.java
 #
 jdbcapi/HoldabilityTest.junit
@@ -19,5 +18,4 @@ derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
 stress/stress.multi
 lang/wisconsin.java
-jdbcapi/derbyStress.java
 jdbcapi/maxfieldsize.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbyall.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbyall.properties?rev=1141924&r1=1141923&r2=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbyall.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbyall.properties
Fri Jul  1 12:54:30 2011
@@ -13,6 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-suites=derbylang storeall xa derbytools jdbc20 jdbcapi derbynetclientmats encryptionAll simpledemo
unit i18nTest
+suites=derbylang storeall xa derbytools jdbc20 derbynetclientmats encryptionAll simpledemo
unit i18nTest
 derby.debug.true=enableBtreeConsistencyCheck
 derby.stream.error.logSeverityLevel=0

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.properties?rev=1141924&r1=1141923&r2=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.properties
Fri Jul  1 12:54:30 2011
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 framework=DerbyNetClient
-suites= encodingTests derbynetclientmats jdbcapi jdbc20
+suites= encodingTests derbynetclientmats jdbc20
 jdk12test=true
 runwithj9=false
 #Exclude for J2ME/Foundation - Network Server not supported

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.properties?rev=1141924&r1=1141923&r2=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.properties
Fri Jul  1 12:54:30 2011
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 framework=DerbyNet
-suites=j9derbynetmats jdbcapi jdbc20
+suites=j9derbynetmats jdbc20
 jdk12test=true
 runwithj9=false
 runwithibm13=false

Copied: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/MemoryLeakFixesTest.java
(from r1136551, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java)
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/MemoryLeakFixesTest.java?p2=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/MemoryLeakFixesTest.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java&r1=1136551&r2=1141924&rev=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/derbyStress.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/MemoryLeakFixesTest.java
Fri Jul  1 12:54:30 2011
@@ -1,6 +1,6 @@
 /*
 
-Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.derbyStress
+Derby - Class org.apache.derbyTesting.functionTests.tests.memory.MemoryLeakFixesTest
 
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
@@ -19,130 +19,112 @@ limitations under the License.
 
 */
 
-package org.apache.derbyTesting.functionTests.tests.jdbcapi;
+package org.apache.derbyTesting.functionTests.tests.memory;
 
 import java.sql.Connection;
-import java.sql.Statement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.sql.Statement;
 
-import org.apache.derby.tools.ij;
-import org.apache.derbyTesting.functionTests.util.TestUtil;
+import junit.framework.Test;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * MemoryLeakFixesTest should be run with -Xmx16M or run 
+ * as part of the ant junit-lowmem target. The test is
+ * generally successful if it does not run out of memory.
+ * Results are not typically checked.
+ *
+ */
+
+public class MemoryLeakFixesTest extends BaseJDBCTestCase {
+
+    public MemoryLeakFixesTest(String name) {
+        super(name);
+    }
+    private static long HALFMB = 500*1024;
+    
+    private static int numRows = 100;
+    private static int numPreparedStmts = 2000;
+
+
+    // Tests prepared statements are not leaked if not explicitly closed by
+    // user (DERBY-210)
+    public void testPrepStmtD210() throws Exception
+    {
+        Connection conn = getConnection();
+        PreparedStatement ps = null;
+        ResultSet rs = null;
+        conn.setAutoCommit(false);
+
+        Statement stmt = createStatement();
+
+        stmt.execute("create table t1 (lvc  LONG VARCHAR)");
+        stmt.close();
+
+        String insertTabSql = "insert into t1 values(?)";
+        ps = conn.prepareStatement(insertTabSql);
+        for (int i = 0; i < numRows; i++)
+        {
+            ps.setString(1,"Hello" + i);
+            ps.executeUpdate();
+        }
+        ps.close();
+
+
+
+        String selTabSql = "select * from t1";
+
+        for (int i = 0 ; i  < numPreparedStmts; i++)
+        {
+            ps = conn.prepareStatement(selTabSql);
+            rs = ps.executeQuery();
+
+            while (rs.next())
+            {
+                rs.getString(1);
+            }
+
+            rs.close();
+
+            // Do not close the prepared statement
+            // because we want to check that it is
+            // garbage collected
+            //ps.close();
+            if ((i % 100) == 0)
+                runFinalizerIfNeeded();
+        }
+        conn.commit();
+    }
+
+    // Tests re-execution of a statement without closing the result
+    // set (DERBY-557).
+    public void testReExecuteD557() throws Exception {
+        println("DERBY-557: reExecuteStatementTest() ");
+        Connection conn = getConnection();
+        Statement stmt = conn.createStatement();
+        for (int i = 0; i < 50000; i++) {
+            if ((i % 1000) == 0)
+                runFinalizerIfNeeded();
+            ResultSet rs = stmt.executeQuery("values(1)");
+            // How silly! I forgot to close the result set.
+        }
+        conn.commit();
+        stmt.close();
+        conn.close();
+    }
 
-public class derbyStress {
-	
-	private static int numConn = 1;
-	private static int numRows = 100;
-	private static int numPreparedStmts = 2000; 
-
-	public static void main(String[] args) {
-		try {
-			System.out.println("Test derbyStress starting");
-
-			// use the ij utility to read the property file and
-			// make the initial connection.
-			ij.getPropertyArg(args);
-			Connection conn = null;
-			
-			for (int i = 0; i < numConn; i++) {
-				 conn = ij.startJBMS();
-				 System.out.println("Testing with " + numPreparedStmts + " prepared statements");
-				 prepStmtTest(conn, numRows, numPreparedStmts);
-				 System.out.println("PASS -- Prepared statement test");
-				 conn.close();
-			}
-
-			reExecuteStatementTest();
-			testDerby3316();
-			System.out.println("Test derbyStress finished.");
-		} catch (SQLException se) {
-			TestUtil.dumpSQLExceptions(se);
-		} catch (Throwable e) {
-			System.out.println("FAIL -- unexpected exception caught in main():\n");
-			System.out.println(e.getMessage());
-			e.printStackTrace();
-		}
-	}
-	
-	private static void createTables(Connection conn, int numRows) throws SQLException{
-		Statement stmt = conn.createStatement();
-		
-		stmt.execute("create table t1 (lvc  LONG VARCHAR)");
-		stmt.close();
-		
-		String insertTabSql = "insert into t1 values(?)";
-		PreparedStatement ps = conn.prepareStatement(insertTabSql);
-		 for (int i = 0; i < numRows; i++)
-		 {
-			 ps.setString(1,"Hello" + i);
-			 ps.executeUpdate();
-		 }
-		 ps.close();
-	}
-	
-	// Tests prepared statements are not leaked if not explicitly closed by
-	// user (DERBY-210)
-	private static void prepStmtTest(Connection conn, int numRows, int numPreparedStmts) throws
Exception
-	{
-		PreparedStatement ps = null;
-		ResultSet rs = null;
-		conn.setAutoCommit(false);
-		 
-		try {
-		
-			createTables(conn, numRows);
-			
-			String selTabSql = "select * from t1";
-			
-			for (int i = 0 ; i  < numPreparedStmts; i++)
-			{
-				ps = conn.prepareStatement(selTabSql);
-				rs = ps.executeQuery();
-
-				while (rs.next())
-				{
-					rs.getString(1);
-				}
-
-				rs.close();
-			
-				// Do not close the prepared statement
-				//ps.close();
-			}
-			conn.commit();
-		} 
-		catch (SQLException e) {
-			TestUtil.dumpSQLExceptions(e);
-			conn.rollback();
-		}
-	}
-
-	// Tests re-execution of a statement without closing the result
-	// set (DERBY-557).
-	private static void reExecuteStatementTest() throws Exception {
-		System.out.print("DERBY-557: reExecuteStatementTest() ");
-		Connection conn = ij.startJBMS();
-		Statement stmt = conn.createStatement();
-		for (int i = 0; i < 50000; i++) {
-			ResultSet rs = stmt.executeQuery("values(1)");
-			// How silly! I forgot to close the result set.
-		}
-		conn.commit();
-		stmt.close();
-		conn.close();
-		System.out.println("PASSED");
-	}
-        
     /**
      * Test fix for leak if ResultSets are not closed.
      * @throws Exception
      */
-    public static void testDerby3316() throws Exception {
-          System.out.println("DERBY-3316: Multiple statement executions ");
-          Connection conn = ij.startJBMS();
+    public void testResultSetgcD3316() throws Exception {
+          println("DERBY-3316: Multiple statement executions ");
                 
-          Statement s = conn.createStatement();
+          Connection conn = getConnection();
+          Statement s = createStatement();
           s.executeUpdate("CREATE TABLE TAB (col1 varchar(32672))");
           PreparedStatement ps = conn.prepareStatement("INSERT INTO TAB VALUES(?)");
           ps.setString(1,"hello");
@@ -160,15 +142,41 @@ public class derbyStress {
                   // statement, we get a leak.
                   //rs.close();
                   //s.close();
+                  if ((i % 100) == 0) 
+                       runFinalizerIfNeeded();
+                  
           }    
           // close the connection to free up all the result sets that our sloppy 
           // user didn't close.
           conn.close();
-          conn = ij.startJBMS();
+          conn = getConnection();
           s = conn.createStatement();
           s.executeUpdate("DROP TABLE TAB");
           s.close();
           conn.close();
        }
-      
+
+    /**
+     * runFinalizerIfNeeded is called periodically for DERBY-4200. With the IBM
+     * JVM in some modes, like soft real time or in a single threaded
+     * environment on vmware. The finalizer may lag behind the program so much
+     * we get an OOM. If we get low on memory, force the finalizer to catch up.
+     * 
+     */
+    private static void runFinalizerIfNeeded() {
+        
+        Runtime rt = Runtime.getRuntime();
+        if (rt.freeMemory() < HALFMB){
+            println("Waiting for finalizer ");
+            rt.runFinalization();
+            
+
+        }
+
+    }
+    
+    public static Test suite() {
+        Test suite = TestConfiguration.defaultSuite(MemoryLeakFixesTest.class);
+        return suite;
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java?rev=1141924&r1=1141923&r2=1141924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java
Fri Jul  1 12:54:30 2011
@@ -42,6 +42,7 @@ public class _Suite extends BaseJDBCTest
         suite.addTest(RolesDependencyTest.suite());
         suite.addTest(Derby3009Test.suite());
         suite.addTest(XAMemTest.suite());
+        suite.addTest(MemoryLeakFixesTest.suite());
         return suite;
     }
 }



Mime
View raw message