db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r635625 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: harness/MultiTest.java util/TestUtil.java util/ThreadDump.java util/build.xml util/derby_tests.policy
Date Mon, 10 Mar 2008 18:17:42 GMT
Author: kmarsden
Date: Mon Mar 10 11:17:39 2008
New Revision: 635625

URL: http://svn.apache.org/viewvc?rev=635625&view=rev
Log:
DERBY-3503 Change stress.multi to dump thread stacks before killing off testers with jdk 1.5
and higher


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ThreadDump.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/MultiTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/MultiTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/MultiTest.java?rev=635625&r1=635624&r2=635625&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/MultiTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/MultiTest.java
Mon Mar 10 11:17:39 2008
@@ -34,6 +34,8 @@
 
 import org.apache.derby.iapi.tools.i18n.LocalizedResource;
 import org.apache.derby.iapi.tools.i18n.LocalizedOutput;
+import org.apache.derbyTesting.functionTests.util.TestUtil;
+
 
 /**
  * MultiTest is a multiuser test harness.  It
@@ -285,7 +287,9 @@
 	
 		/*	
 		** Now stop everyone that hasn't already stopped.
+		* First get thread dumps for jdk 15.
 		*/
+		TestUtil.dumpAllStackTracesIfSupported(log);
 		for (i = 0; i < MAX_WAIT_FOR_COMPLETION && (tg.isDestroyed() == false ); i++)

 		{ 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java?rev=635625&r1=635624&r2=635625&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
Mon Mar 10 11:17:39 2008
@@ -38,6 +38,7 @@
 import javax.sql.DataSource;
 
 import org.apache.derby.iapi.services.info.JVMInfo;
+import org.apache.derbyTesting.functionTests.harness.JavaVersionHolder;
 import org.apache.derbyTesting.functionTests.harness.RunTest;
 
 
@@ -913,5 +914,57 @@
 		return false;
 	}
 
+	/**
+	 * For JDK 1.5 or higher print all stack traces to the
+	 * specified PrintWriter.
+	 * 
+	 * @param log  PrintWriter to print to
+	 */
+    public static void dumpAllStackTracesIfSupported(PrintWriter log)
+	{
+		try {
+			String version =  (String) AccessController.doPrivileged
+				(new java.security.PrivilegedAction(){
+						public Object run(){
+							return System.getProperty("java.version");
+						}
+					}
+				 );
+                   
+			JavaVersionHolder j=  new JavaVersionHolder(version); 
+			
+			if (j.atLeast(1,5)){
+				Class c = Class.forName("org.apache.derbyTesting.functionTests.util.ThreadDump");
+				final Method m = c.getMethod("getStackDumpString",new Class[] {});
+				
+				String dump;
+				try {
+					dump = (String) AccessController.doPrivileged
+						(new PrivilegedExceptionAction(){
+								public Object run() throws 
+									IllegalArgumentException, 
+									IllegalAccessException, 
+									InvocationTargetException{
+									return m.invoke(null, null);
+								}
+							}
+						 );
+				}     catch (PrivilegedActionException e) {
+					throw  e.getException();
+				}
+				log.println(dump);                    
+			}                     
+		}
+		catch (Exception e){
+			// if we get an exception trying to get a thread dump. Just print it to the log and continue.
+			log.println("Error trying to dump thread stack traces");
+			if (e instanceof InvocationTargetException)
+				((InvocationTargetException) e).getTargetException().printStackTrace(log);
+			else
+				e.printStackTrace(log);
+		}
+		
+	}
 }
+
 

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ThreadDump.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ThreadDump.java?rev=635625&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ThreadDump.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ThreadDump.java
Mon Mar 10 11:17:39 2008
@@ -0,0 +1,50 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.util.ThreadDump
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.util;
+
+import java.util.Map;
+
+public class ThreadDump {
+
+    /**
+     * 
+     * @return A string representation of a full thread dump
+     */
+    public static String getStackDumpString() {
+        StringBuffer sb = new StringBuffer();
+        Map<Thread, StackTraceElement[]> st = Thread.getAllStackTraces();
+        for (Map.Entry<Thread, StackTraceElement[]> e : st.entrySet()) {
+            StackTraceElement[] lines = e.getValue();
+            Thread t = e.getKey();
+            sb.append("Thread name=" + t.getName() + " id=" + t.getId()
+                    + " priority=" + t.getPriority() + " state=" + t.getState()
+                    + " isdaemon=" + t.isDaemon() + "\n");
+            for (int i = 0; i < lines.length; i++) {
+                sb.append("\t" + lines[i] + "\n");
+
+            }
+            sb.append("\n");
+        }
+        return sb.toString();
+    }
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ThreadDump.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml?rev=635625&r1=635624&r2=635625&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml
Mon Mar 10 11:17:39 2008
@@ -65,6 +65,7 @@
       <include name="${this.dir}/streams/*.java"/> 
       <include name="${this.dir}/corruptio/*.java"/>
       <exclude name="${this.dir}/XATestUtil.java"/>
+      <exclude name="${this.dir}/ThreadDump.java"/>
     </javac>
     <javac
       source="1.4"
@@ -84,6 +85,25 @@
       </classpath>
       <!--exclude name=""/-->
 	  <include name="${this.dir}/XATestUtil.java"/>
+    </javac>
+
+    <javac
+      source="1.5"
+      target="1.5"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="true"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.testing.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java15compile.classpath}"/>
+      </classpath>
+    <include name="${this.dir}/ThreadDump.java"/>
     </javac>
   </target>
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=635625&r1=635624&r2=635625&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Mon Mar 10 11:17:39 2008
@@ -165,6 +165,11 @@
   permission java.security.SecurityPermission "getPolicy";
   permission java.lang.RuntimePermission "setIO";  
 
+  // These permissions are needed by stress.multi to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+
   // These permissions are needed when testing code instrumented with EMMA.
   permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
 };
@@ -205,6 +210,12 @@
   // streams. Currently the nist suite runs with useprocess=false.
   permission java.lang.RuntimePermission "setSecurityManager";
   permission java.lang.RuntimePermission "setIO"; 
+
+  // These permissions are needed by stress.multi to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+
 };
 
 // JUnit jar file tries to read junit.properties in the user's



Mime
View raw message