db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lily...@apache.org
Subject svn commit: r1058404 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/iapi/services/context/ engine/org/apache/derby/iapi/services/info/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/impl/serv...
Date Thu, 13 Jan 2011 03:56:35 GMT
Author: lilywei
Date: Thu Jan 13 03:56:34 2011
New Revision: 1058404

URL: http://svn.apache.org/viewvc?rev=1058404&view=rev
Log:
DERBY-4856 this is part three of thread dump and diagnostic information check in. With this check in, user can use derby.stream.error.extendedDiagSeverityLevel to turn on more tracing or turn it off. I am assuming in the code whether database is up or not based on the information. Also modify tests that affected by this fix.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextManager.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/BasicDaemon.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/MaxLogNumberRecovery.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_FileSystemData.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_StreamFile.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java Thu Jan 13 03:56:34 2011
@@ -74,16 +74,25 @@ public interface Property { 
 		@see org.apache.derby.iapi.error.ExceptionSeverity#SESSION_SEVERITY
 	*/
 	String LOG_SEVERITY_LEVEL = "derby.stream.error.logSeverityLevel";
-
-	/**
-	 * derby.stream.error.logBootTrace
-	 * <BR>
-	 * defaults to false. If set to true logs a stack trace to 
-	 * the error stream on successful boot or shutdown.
-	 * This can be useful when trying to debug dual boot 
-	 * scenarios especially with multiple class loaders.
-	 * 
-	 */
+    
+    /**
+      * derby.stream.error.ExtendedDiagSeverityLevel=integerValue
+      * <BR>
+      * Indicates the minimum level of severity for errors that are reported thread dump information
+      * and diagnosis information depends on jvm vender.
+      * Default to SESSION_SEVERITY(40000).
+      *
+     */
+    String EXT_DIAG_SEVERITY_LEVEL = "derby.stream.error.extendedDiagSeverityLevel";
+    /**
+     * derby.stream.error.logBootTrace
+     * <BR>
+     * defaults to false. If set to true logs a stack trace to 
+     * the error stream on successful boot or shutdown.
+     * This can be useful when trying to debug dual boot 
+     * scenarios especially with multiple class loaders.
+     * 
+     */
 	
 	String LOG_BOOT_TRACE = "derby.stream.error.logBootTrace";
         /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextManager.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextManager.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ContextManager.java Thu Jan 13 03:56:34 2011
@@ -37,6 +37,7 @@ import org.apache.derby.iapi.services.pr
 
 import org.apache.derby.iapi.error.ExceptionSeverity;
 import org.apache.derby.iapi.services.i18n.LocaleFinder;
+import org.apache.derby.iapi.services.info.JVMInfo;
 
 import java.sql.SQLException;
 import java.util.HashMap;
@@ -236,12 +237,21 @@ public class ContextManager
 		final CtxStack cs = (CtxStack) ctxTable.get(contextId);
 		return (cs==null?Collections.EMPTY_LIST:cs.getUnmodifiableList());
 	}
-
-
-	/**
-		@return true if the context manager is shutdown, false otherwise.
-	 */
-	public boolean cleanupOnError(Throwable error)
+    
+    /**
+     * clean up error and print it to derby.log. Extended diagnosis including
+     * thread dump to derby.log and javaDump if available, will print if the
+     * database is active and severity is greater than or equals to
+     * SESSTION_SEVERITY or as configured by
+     * derby.stream.error.extendedDiagSeverityLevel property
+     * 
+     * @param error the error we want to clean up
+     * @param diagActive
+     *        true if extended diagnostics should be considered, 
+     *        false not interested of extended diagnostic information
+     * @return true if the context manager is shutdown, false otherwise.
+     */
+    public boolean cleanupOnError(Throwable error, boolean diagActive)
 	{
 		if (shutdown)
 			return true;
@@ -331,8 +341,14 @@ cleanup:	for (int index = holder.size() 
 					lastHandler = ctx.isLastHandler(errorSeverity);
 
 					ctx.cleanupOnError(error);
-                    if (reportError
-                            && errorSeverity >= ExceptionSeverity.SESSION_SEVERITY) {
+                    //When errorSeverity greater or equals Property.EXT_DIAG_SEVERITY_LEVEL,
+                    //the threadDump information will be in derby.log and 
+                    //the diagnosis information will be prepared.
+                    //If Property.EXT_DIAG_SEVERITY_LEVEL is not set in JVM property or
+                    //derby property, we will only handle threadDump information and diagnosis
+                    //information for errorSeverity = ExceptionSeverity.SESSION_SEVERITY.
+                    if (reportError && diagActive
+                            && (errorSeverity >= extDiagSeverityLevel)) {
                         threadDump = ExceptionUtil.dumpThreads();
                     } else {
                         threadDump = null;
@@ -407,8 +423,11 @@ cleanup:	for (int index = holder.size() 
 				}
 			}
 
-            if (threadDump != null)
+            if (threadDump != null) {
                 errorStream.println(threadDump);
+                JVMInfo.javaDump();
+            }
+
 			if (reportError) {
 				errorStream.println("Cleanup action completed");
 				errorStream.flush();
@@ -549,11 +568,16 @@ cleanup:	for (int index = holder.size() 
 
 		logSeverityLevel = PropertyUtil.getSystemInt(Property.LOG_SEVERITY_LEVEL,
 			SanityManager.DEBUG ? 0 : ExceptionSeverity.SESSION_SEVERITY);
+        extDiagSeverityLevel = PropertyUtil.getSystemInt(
+                Property.EXT_DIAG_SEVERITY_LEVEL,
+                ExceptionSeverity.SESSION_SEVERITY);
 	}
 
 	final ContextService owningCsf;
 
 	private int		logSeverityLevel;
+    // DERBY-4856 track extendedDiagSeverityLevel variable
+    private int extDiagSeverityLevel;
 
 	private HeaderPrintWriter errorStream;
 	private ErrorStringBuilder errorStringBuilder;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/JVMInfo.java Thu Jan 13 03:56:34 2011
@@ -21,6 +21,14 @@
 
 package org.apache.derby.iapi.services.info;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+
+import org.apache.derby.shared.common.sanity.SanityManager;
+
 /**
 	This class is used to determine which Java specification Derby will run at.
     For a useful discussion of how this class is used, please see DERBY-3176.
@@ -161,4 +169,71 @@ public abstract class JVMInfo
 		}
 	}
 
+    /**
+     * Get system property.
+     *
+     * @param name name of the property
+     */
+    private static String getSystemProperty(final String name) {
+        
+        return (String) AccessController
+                .doPrivileged(new java.security.PrivilegedAction() {
+                    
+                    public Object run() {
+                        return System.getProperty(name);
+                        
+                    }
+                    
+                });
+    }
+    
+    /**
+     * Check whether this is sun jvm.
+     *
+     * @return true if it is sun jvm, false if it is not sun jvm
+     */
+    public static final boolean isSunJVM() {
+        String vendor = getSystemProperty("java.vendor");
+        return "Sun Microsystems Inc.".equals(vendor)
+                || "Oracle Corporation".equals(vendor);
+    }
+    
+    /**
+     * Check whether this is IBM jvm.
+     *
+     * @return true if it is IBM jvm, false if it is not IBM jvm
+     */
+    public static final boolean isIBMJVM() {
+        return ("IBM Corporation".equals(getSystemProperty("java.vendor")));
+    }
+    
+    /**
+     * For IBM jvm, this method will dump more diagnostic information to file.
+     * JVM specific code for other vender can be added. DERBY-4856 
+     *  
+     */
+    public static void javaDump() {
+        if (isIBMJVM()) {
+            Class ibmc = null;
+            try {
+                ibmc = Class.forName("com.ibm.jvm.Dump");
+                final Method ibmm = ibmc.getMethod("JavaDump", new Class[] {});
+                
+                AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                    public Object run() throws IllegalAccessException,
+                            MalformedURLException, InstantiationException,
+                            InvocationTargetException {
+                        return ibmm.invoke(null, new Object[] {});
+                    }
+                });
+            } catch (Exception e) {
+                if (SanityManager.DEBUG) {
+                    SanityManager
+                            .THROWASSERT(
+                                    "Failed to execute com.ibm.jvm.Dump.JavaDump in IBM JVM",
+                                    e);
+                }
+            }
+        }
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Thu Jan 13 03:56:34 2011
@@ -628,7 +628,8 @@ public abstract class EmbedConnection im
                 if (se.getSeverity() < ExceptionSeverity.SESSION_SEVERITY)
                     se.setSeverity(ExceptionSeverity.SESSION_SEVERITY);
             }
-			tr.cleanupOnError(t);
+            //DERBY-4856, assume database is not up
+            tr.cleanupOnError(t, false);
 			throw handleException(t);
 		} finally {
 			restoreContextStack();
@@ -1912,7 +1913,8 @@ public abstract class EmbedConnection im
 							// on how long the client program wants to hold on to
 							// the Connection object.
 							tr.clearLcc(); 
-							tr.cleanupOnError(e);
+                            // DERBY-4856, assume database is not up
+                            tr.cleanupOnError(e, false);
 							
 						} catch (Throwable t) {
 							throw handleException(t);
@@ -1925,7 +1927,8 @@ public abstract class EmbedConnection im
 						// the cleanup has not been done yet.
                         InterruptStatus.restoreIntrFlagIfSeen();
 						tr.clearLcc(); 
-						tr.cleanupOnError(e);
+                        // DERBY-4856, assume database is not up
+                        tr.cleanupOnError(e, false);
 					}
 				}
 			}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java Thu Jan 13 03:56:34 2011
@@ -336,7 +336,7 @@ public final class TransactionResourceIm
 			// it was already removed.  all that's left to cleanup is
 			// JDBC objects.
 			if (cm!=null) {
-				boolean isShutdown = cleanupOnError(thrownException);
+				boolean isShutdown = cleanupOnError(thrownException, database != null ? database.isActive() : false);
 				if (checkForShutdown && isShutdown) {
 					// Change the error message to be a known shutdown.
 					thrownException = shutdownDatabaseException();
@@ -349,8 +349,8 @@ public final class TransactionResourceIm
 
 		} catch (Throwable t) {
 
-			if (cm!=null) { // something to let us cleanup?
-				cm.cleanupOnError(t);
+            if (cm != null) { // something to let us cleanup?
+                cm.cleanupOnError(t, database != null ? isActive() : false);
 			}
 
             InterruptStatus.restoreIntrFlagIfSeen();
@@ -416,12 +416,21 @@ public final class TransactionResourceIm
 		return  username;
 	}
 
-	boolean cleanupOnError(Throwable e)
+    /**
+     * clean up error and print it to derby.log if diagActive is true
+     * @param error the error we want to clean up
+     * @param diagActive
+     *        true if extended diagnostics should be considered, 
+     *        false not interested of extended diagnostic information
+     * @return true if the context manager is shutdown, false otherwise.
+     */
+    boolean cleanupOnError(Throwable e, boolean diagActive)
 	{
 		if (SanityManager.DEBUG)
 			SanityManager.ASSERT(cm != null, "cannot cleanup on error with null context manager");
 
-		return cm.cleanupOnError(e);
+        //DERBY-4856 thread dump
+        return cm.cleanupOnError(e, diagActive);
 	}
 
 	boolean isIdle()

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/BasicDaemon.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/BasicDaemon.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/BasicDaemon.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/BasicDaemon.java Thu Jan 13 03:56:34 2011
@@ -356,7 +356,9 @@ public class BasicDaemon implements Daem
 		{
 			if (SanityManager.DEBUG)
 				SanityManager.showTrace(e);
-			cm.cleanupOnError(e);
+
+            //Assume database is not active. DERBY-4856 thread dump
+            cm.cleanupOnError(e, false);
 		}
 	}
 
@@ -399,7 +401,10 @@ public class BasicDaemon implements Daem
 			running = false;
 			stopped = true;
 		}
-		contextMgr.cleanupOnError(StandardException.normalClose());
+        
+        //Assume database is not active. DERBY-4856 thread dump 
+        contextMgr.cleanupOnError(StandardException.normalClose(), false);
+
 		contextService.resetCurrentContextManager(contextMgr);
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java Thu Jan 13 03:56:34 2011
@@ -758,7 +758,7 @@ public class IndexStatisticsDaemonImpl
             // Do nothing, just let the thread die.
         } catch (ShutdownException se) {
             stop(); // Call stop to log activity statistics.
-            ctxMgr.cleanupOnError(se);
+            ctxMgr.cleanupOnError(se, db.isActive());
         } finally {
             synchronized (queue) {
                 runningThread = null;
@@ -851,7 +851,7 @@ public class IndexStatisticsDaemonImpl
             // The database or system is going down. Probably handled elsewhere
             // but disable daemon anyway.
             disable = true;
-            cm.cleanupOnError(se);
+            cm.cleanupOnError(se, db.isActive());
         }
 
         if (disable) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java Thu Jan 13 03:56:34 2011
@@ -1822,8 +1822,10 @@ nextModule:
 				usProperties.setServiceBooted();
 			}
             
-            if (cm != previousCM)
-                cm.cleanupOnError(StandardException.closeException());
+            if (cm != previousCM) {
+                //Assume database is not active. DERBY-4856 thread dump
+                cm.cleanupOnError(StandardException.closeException(), false);
+            }
             
 		} catch (Throwable t) {
 
@@ -1835,7 +1837,8 @@ nextModule:
 				se = Monitor.exceptionStartingModule(t);
 
 			if (cm != previousCM) {
-				cm.cleanupOnError(se);
+                //Assume database is not active. DERBY-4856 thread dump
+                cm.cleanupOnError(se, false);
 			}
 
 			if (ts != null) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java Thu Jan 13 03:56:34 2011
@@ -20,6 +20,7 @@
  */
 package org.apache.derby.impl.sql.catalog;
 
+import org.apache.derby.iapi.db.Database;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.cache.Cacheable;
@@ -211,7 +212,11 @@ public abstract class SequenceUpdater im
             clean( false );
         } catch (StandardException se)
         {
-            getLCC().getContextManager().cleanupOnError( se );
+            //Doing check for lcc and db to be certain
+            LanguageConnectionContext lcc = getLCC();
+            Database db = (lcc != null ? lcc.getDatabase() : null);
+            boolean isactive = (db != null ? db.isActive() : false);
+            lcc.getContextManager().cleanupOnError(se, isactive);
         }
     }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Thu Jan 13 03:56:34 2011
@@ -98,7 +98,16 @@ class EmbedPooledConnection implements j
 
 	protected boolean isActive;
     
-	EmbedPooledConnection(ReferenceableDataSource ds, String u, String p, boolean requestPassword) throws SQLException
+    /**
+     * getter function for isActive
+     * @return boolean is isActive is true
+     **/
+    public boolean isActive() {
+        return isActive;
+    }
+    
+    EmbedPooledConnection(ReferenceableDataSource ds, String u, String p,
+            boolean requestPassword) throws SQLException
 	{
 		dataSource = ds;
 		username = u;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAResource.java Thu Jan 13 03:56:34 2011
@@ -100,14 +100,15 @@ class EmbedXAResource implements XAResou
                 rm.commit(inDoubtCM, xid_im, onePhase);
                 
                 // close the connection/transaction since it can never
-                // be used again.
-                inDoubtCM.cleanupOnError(StandardException.closeException());
+                // be used again. DERBY-4856 No extended diagnostic information needed.
+                inDoubtCM.cleanupOnError(StandardException.closeException(),
+                        false);
                 return;
             } catch (StandardException se) {
                 // The rm threw an exception, clean it up in the approprate
                 // context.  There is no transactionResource to handle the
                 // exception for us.
-                inDoubtCM.cleanupOnError(se);
+                inDoubtCM.cleanupOnError(se, con.isActive());
                 throw wrapInXAException(se);
             } finally {
                 csf.resetCurrentContextManager(inDoubtCM);
@@ -404,13 +405,14 @@ class EmbedXAResource implements XAResou
                 rm.forget(inDoubtCM, xid_im);
                 
                 // close the connection/transaction since it can never be used again.
-                inDoubtCM.cleanupOnError(StandardException.closeException());
+                inDoubtCM.cleanupOnError(StandardException.closeException(),
+                        false);
                 return;
             } catch (StandardException se) {
                 // The rm threw an exception, clean it up in the approprate
                 // context.  There is no transactionResource to handle the
                 // exception for us.
-                inDoubtCM.cleanupOnError(se);
+                inDoubtCM.cleanupOnError(se, con.isActive());
                 throw wrapInXAException(se);
             } finally {
                 csf.resetCurrentContextManager(inDoubtCM);
@@ -454,13 +456,14 @@ class EmbedXAResource implements XAResou
                 rm.rollback(inDoubtCM, xid_im);
                 
                 // close the connection/transaction since it can never be used again.
-                inDoubtCM.cleanupOnError(StandardException.closeException());
+                inDoubtCM.cleanupOnError(StandardException.closeException(),
+                        false);
                 return;
             } catch (StandardException se) {
                 // The rm threw an exception, clean it up in the approprate
                 // context.  There is no transactionResource to handle the
                 // exception for us.
-                inDoubtCM.cleanupOnError(se);
+                inDoubtCM.cleanupOnError(se, con.isActive());
                 throw wrapInXAException(se);
             } finally {
                 csf.resetCurrentContextManager(inDoubtCM);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java Thu Jan 13 03:56:34 2011
@@ -89,6 +89,8 @@ public class AuthenticationTest extends 
     }
     
     public static Test baseSuite(String name) {
+        setSystemProperty("derby.stream.error.extendedDiagSeverityLevel","50000");
+        
         TestSuite suite = new TestSuite("AuthenticationTest");
         
         Test test = new AuthenticationTest(

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.java Thu Jan 13 03:56:34 2011
@@ -20,19 +20,25 @@
 package org.apache.derbyTesting.functionTests.tests.store;
 
 
+import java.io.File;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.Properties;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -46,6 +52,8 @@ public class Derby3980DeadlockTest exten
     private LinkedList  listExceptions = new LinkedList();
     private Object syncObject = new Object();
     private int startedCount = 0;
+    private String fprefix = "javacore";
+    private static String TARGET_POLICY_FILE_NAME="derby3980deadlock.policy";
     
     public Derby3980DeadlockTest(String name) {
         super(name);
@@ -64,6 +72,8 @@ public class Derby3980DeadlockTest exten
      * Check we have one deadlock exception.
      */
     private void checkExceptions() {        
+        //Due to timing, you might see ERROR 40XL1: A lock could not be obtained
+        //instead of ERROR 40001 (DERBY-3980)
         for( Iterator i = listExceptions.iterator(); i.hasNext(); ) {
             SQLException e = (SQLException) i.next();
             assertSQLState("40001",e);
@@ -71,7 +81,58 @@ public class Derby3980DeadlockTest exten
         assertEquals("Expected 1 exception, got" + listExceptions.size(),
                 1,listExceptions.size());
     }
+    /**
+     * Decorate a test with SecurityManagerSetup, clientServersuite, and
+     * SupportFilesSetup.
+     * 
+     * @return the decorated test
+     */
+    private static Test decorateTest() {
+        String policyName = new Derby3980DeadlockTest("test").makePolicyName();
+        Test test = TestConfiguration.clientServerSuite(Derby3980DeadlockTest.class);
+        Properties diagProperties = new Properties();
+        diagProperties.setProperty("derby.stream.error.extendedDiagSeverityLevel", "30000");
+        diagProperties.setProperty("derby.infolog.append", "true");
+        test = new SystemPropertyTestSetup(test, diagProperties, true);
+     
+        // Install a security manager using the initial policy file.
+        test = new SecurityManagerSetup(test, policyName);
+
+        // Copy over the policy file we want to use.
+        String POLICY_FILE_NAME=
+            "functionTests/tests/store/Derby3980DeadlockTest.policy";
+
+        test = new SupportFilesSetup
+        (
+                test,
+                null,
+                new String[] { POLICY_FILE_NAME },
+                null,
+                new String[] { TARGET_POLICY_FILE_NAME}
+        );
+        return test;
+    }
+    /**
+     * Generate the name of the local policy file
+     * @return the name of the local testing policy file
+     **/
+    private String makePolicyName() {
+        try {
+            String  userDir = getSystemProperty( "user.dir" );
+            String  fileName = userDir + File.separator + 
+            SupportFilesSetup.EXTINOUT + File.separator + TARGET_POLICY_FILE_NAME;
+            File      file = new File( fileName );
+            String  urlString = file.toURL().toExternalForm();
 
+            return urlString;
+        }
+        catch (Exception e) {
+            fail("Unexpected exception caught by " +
+                    "makePolicyName(): " + e );
+            return null;
+        }
+    }
+    
     private void waitForThreads(Thread[] t) {
         for (int i = 0; i < THREAD_COUNT; i++)
         {   
@@ -121,7 +182,7 @@ public class Derby3980DeadlockTest exten
                     ResultSet rs = stmt.executeQuery("select * from t where i = 456");
                     while (rs.next());
                     
-                    //stmt.executeUpdate("update t set i = 456 where i = 456");
+                    //stmt.executeUpdate("update t set i = 456 where i = 456")
                     stmt.executeUpdate("delete from t  where i = 456");
                     threadConnection.commit();
                     } catch (Exception e) {
@@ -138,8 +199,8 @@ public class Derby3980DeadlockTest exten
     }
 
     public static Test suite() {
-
-	Test suite = TestConfiguration.embeddedSuite(Derby3980DeadlockTest.class);
+    Test suite = decorateTest();
+ 
     return new  CleanDatabaseTestSetup(
                 DatabasePropertyTestSetup.setLockTimeouts(suite, 5, 10)) {
          /**
@@ -155,5 +216,20 @@ public class Derby3980DeadlockTest exten
 	
     }
 
+    /**
+     * Use tearDown to cleanup some of the diagnostic information files
+     */
+    protected void tearDown() throws Exception {
+        String dsh = BaseTestCase.getSystemProperty("user.dir");
+        try {
+          File basedir = new File(dsh);
+          String[] list = BaseTestCase.getFilesWith(basedir, fprefix);
+          removeFiles(list);
+        } catch (IllegalArgumentException e) {
+            fail("open directory");
+        }   
+        
+        super.tearDown();
+    }
 }
 

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy?rev=1058404&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/Derby3980DeadlockTest.policy Thu Jan 13 03:56:34 2011
@@ -0,0 +1,410 @@
+//
+// *  Derby - Class org.apache.derbyTesting.functionTests.util.Derby3980DeadlockTest.policy
+// *  
+// * 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.
+// *
+
+//
+// Policy file with minimal set of permissions to run derby's
+// functional tests.
+//
+// The test harness sets up four variables used by this policy file
+//
+// derbyTesting.codejar - URL to the jar files when they are in the classpath
+// derbyTesting.codeclasses - URL to the classes directory when it is in the classpath
+//
+// Only one of derbyTesting.codejar and derbyTesting.codeclasses will be valid, the
+// other will be set to a bogus URL like file://unused
+//
+// derbyTesting.codedir - File location of either derbyTesting.codejar or derbyTesting.codeclasses.
+// Only required due to a BUG (see below for more info).
+//
+// derbyTesting.jaxpjar - URL to the jar file containing the JAXP implementation
+//     for XML-based tests (ex. lang/XMLBindingTest.java).
+//
+// derbyTesting.serverhost - Host name or ip where network server is started 
+// derbyTesting.clienthost - specifies the clients ip address/hostName. 
+//     when testing with networkserver on a remote host, this needs to be passed in 
+//     with the NetworkServerControl start command
+
+//
+// Permissions for the embedded engine (derby.jar)
+//
+grant codeBase "${derbyTesting.codejar}derby.jar" {
+  permission java.util.PropertyPermission "derby.*", "read";
+  permission java.util.PropertyPermission "derby.storage.jvmInstanceId", 
+      "write"; 
+  // The next two properties are used to determine if the VM is 32 or 64 bit.
+  permission java.util.PropertyPermission "sun.arch.data.model", "read";
+  permission java.util.PropertyPermission "os.arch", "read";
+  permission java.util.PropertyPermission "java.class.path", "read";//sysinfo
+  permission java.util.PropertyPermission "java.runtime.version", "read";//sysinfo
+  permission java.util.PropertyPermission "java.fullversion", "read";//sysinfo
+  
+  // unit tests (e.g. store/T_RecoverFullLog) set this property 
+  // (called from derbyTesting.jar through code in derby.jar)
+  permission java.util.PropertyPermission "derbyTesting.unittest.*", "write";
+
+  permission java.lang.RuntimePermission "createClassLoader";
+
+  // getProtectionDomain is an optional permission needed for printing classpath
+  // information to derby.log
+  permission java.lang.RuntimePermission "getProtectionDomain";
+
+  // permissions so that we can set the context class loader to
+  // null for daemon threads to avoid class loader leak.
+  // DERBY-3745
+  permission java.lang.RuntimePermission "getClassLoader";
+  permission java.lang.RuntimePermission "setContextClassLoader";
+
+  permission java.security.SecurityPermission "getPolicy";
+  
+  permission java.io.FilePermission "${derby.system.home}${/}derby.properties", "read";
+  permission java.io.FilePermission "${derby.system.home}${/}derby.log", "read, write, delete";
+  // [DERBY-2000] The write permission was added to allow creation of the
+  // derby.system.home directory when running tests under a security manager.
+  permission java.io.FilePermission "${derby.system.home}", "read, write";
+  
+  // all databases under derby.system.home 
+  permission java.io.FilePermission "${derby.system.home}${/}-", "read, write, delete";
+
+  // Add permission
+  permission java.io.FilePermissioi "${user.dir}${/}-", "read, write, delete";
+  // Import/export and other support files from these locations in tests
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
+  permission java.io.FilePermission "${user.dir}${/}extinout${/}-", "read,  write, delete";
+  permission java.io.FilePermission "${user.dir}${/}extout${/}-", "read,write";
+  permission java.io.FilePermission "${user.dir}${/}extinout", "read,write";
+  
+  // These permissions are needed to load the JCE for encryption with Sun and IBM JDK131.
+  // JDK14 has the JCE  preloaded
+  permission java.security.SecurityPermission "insertProvider.SunJCE";
+  permission java.security.SecurityPermission "insertProvider.IBMJCE";
+  
+//
+// Permissions needed for JMX based management and monitoring, which is only
+// available for JVMs supporting "platform management", that is J2SE 5.0 or better.
+//
+// Allows this code to create an MBeanServer:
+//
+  permission javax.management.MBeanServerPermission "createMBeanServer";
+//
+// Allows access to Derby's built-in MBeans, within the domain org.apache.derby.
+// Derby must be allowed to register and unregister these MBeans.
+// To fine tune this permission, see the javadoc of javax.management.MBeanPermission
+// or the JMX Instrumentation and Agent Specification.
+//
+  permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]","registerMBean,unregisterMBean";
+//
+// Trusts Derby code to be a source of MBeans and to register these in the MBean server.
+//
+  permission javax.management.MBeanTrustPermission "register";
+
+  // Gives permission for jmx to be used against Derby but
+  // only if JMX authentication is not being used.
+  // In that case the application would need to create
+  // a whole set of fine-grained permissions to allow specific
+  // users access to MBeans and actions they perform.
+  permission org.apache.derby.security.SystemPermission "jmx", "control";
+  permission org.apache.derby.security.SystemPermission "engine", "monitor";
+  permission org.apache.derby.security.SystemPermission "server", "monitor";  
+ 
+  // These permissions are needed when testing code instrumented with EMMA.
+  // They will only be used if the emma.active system property property is set,
+  // which should be set to "" for the permissions to be correct.
+  permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+  permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+  permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+  
+  // These permissions are needed by AssertFailure to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+};
+
+//
+// Permissions for the network server (derbynet.jar)
+//
+grant codeBase "${derbyTesting.codejar}derbynet.jar" {
+  permission java.util.PropertyPermission "java.class.path", "read";//sysinfo
+  permission java.util.PropertyPermission "java.runtime.version", "read";//sysinfo
+  permission java.util.PropertyPermission "java.fullversion", "read";//sysinfo
+  
+  // accept is needed for the server accepting connections
+  // connect is needed for ping command (which is in the server jar)
+  permission java.net.SocketPermission "127.0.0.1", "accept,connect";
+  permission java.net.SocketPermission "localhost", "accept,connect";
+  permission java.net.SocketPermission "${derbyTesting.clienthost}", "accept,connect";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "accept,connect";
+  // Need to be able to write to trace file for NetworkServerControlApiTest
+  permission java.io.FilePermission "${user.dir}${/}system${/}trace", "write"; 
+  permission java.io.FilePermission "${user.dir}${/}system${/}trace${/}-", "write"; 
+    // Needed for NetworkServerMBean access (see JMX section above)
+  permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+  
+};
+
+//
+// Permissions for the network client (derbyclient.jar)
+//
+grant codeBase "${derbyTesting.clientjar}derbyclient.jar" {
+  permission java.net.SocketPermission "127.0.0.1", "connect,resolve";
+  permission java.net.SocketPermission "localhost", "connect,resolve";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "connect,resolve";
+
+  // DERBY-1883: Since some classes that are included in both derby.jar and
+  // derbyclient.jar read properties, derbyclient.jar needs permission to read
+  // derby.* properties to avoid failures when it is listed before derby.jar in
+  // the classpath.
+  permission java.util.PropertyPermission "derby.*", "read";
+
+  // DERBY-2302: derbyclient.jar needs to be able to read the user.dir property in order to
+  // do tracing in that directory. Also, it needs read/write permissions in user.dir in order
+  // to create the trace files in that directory.
+  permission java.util.PropertyPermission "user.dir", "read";
+  permission java.io.FilePermission "${user.dir}${/}-", "read, write"; 
+  
+  // These permissions are needed by AssertFailure to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+
+};
+
+//
+// Permissions for the tools (derbytools.jar)
+// Ideally this would be more secure, for now the
+// focus is on getting the engine & network server secure.
+//
+grant codeBase "${derbyTesting.codejar}derbytools.jar" {
+  // Access all properties using System.getProperties -
+  // ij enumerates the properties in order to open connections
+  // for any property set in ij.connection.* and set protocols
+  // for any property in ij.protocol.*
+  permission java.util.PropertyPermission "*", "read, write";
+  
+  // Read all files under ${user.dir}
+  permission java.io.FilePermission "${user.dir}${/}-", "read";
+  
+  // IjTestCases read, write, and delete ij's output in the extinout dir
+  permission java.io.FilePermission "${user.dir}${/}extinout${/}-", "read, write, delete";
+ 
+  // ij needs permission to read the sql files in this jar
+  permission java.io.FilePermission "${derbyTesting.testjarpath}", "read";
+  
+};
+
+//
+// Permissions for the tests (derbyTesting.jar)
+// We are liberal here, it's not a goal to make the test harness
+// or tests secure.
+//
+grant codeBase "${derbyTesting.testjar}derbyTesting.jar" {
+  // Access all properties using System.getProperties
+  permission java.util.PropertyPermission "*", "read, write";
+  
+  //Need to read and delete file for user.dir (Derby3980DeadlockTest)
+  permission java.io.FilePermission "${user.dir}", "read"; 
+  permission java.io.FilePermission "${user.dir}${/}*.txt", "read,write,delete";
+  // Access all files under ${user.dir}to write the test directory structure
+  permission java.io.FilePermission "${user.dir}${/}-", "read,write,delete"; 
+
+  // When running with useprocess=false need to install and uninstall
+  // the security manager and allow setIO to change the system err and out
+  // streams. Currently the nist suite runs with useprocess=false.
+  permission java.lang.RuntimePermission "setSecurityManager";
+  permission java.security.SecurityPermission "getPolicy";
+  permission java.lang.RuntimePermission "setIO";  
+
+  // These permissions are needed to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+  
+  // Allow MBeanTest to register the application management MBean.
+  permission javax.management.MBeanServerPermission "createMBeanServer";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#[org.apache.derby:type=Management]","registerMBean,unregisterMBean";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#-[-]", "instantiate";
+  permission javax.management.MBeanTrustPermission "register";
+   
+  // And to find and use Derby's MBeans
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#[org.apache.derby:*]", "getAttribute,invoke";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "getMBeanInfo";
+  permission javax.management.MBeanPermission "-#-[-]", "queryNames";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "queryNames";
+  
+  // Test code needs this as well for the platform MBeanServer
+  // tests where the testing code is in the stack frame.
+  permission org.apache.derby.security.SystemPermission "jmx", "control";
+  permission org.apache.derby.security.SystemPermission "engine", "monitor";
+  permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+  
+  // These permissions are needed when testing code instrumented with EMMA.
+  permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+};
+
+//
+// super-set of the jar permissions for running out of the classes directory
+//
+grant codeBase "${derbyTesting.codeclasses}" {
+  // Access all properties using System.getProperties
+  permission java.util.PropertyPermission "*", "read, write";
+  
+  permission java.util.PropertyPermission "derby.*", "read";
+  permission java.lang.RuntimePermission "createClassLoader";
+
+  // permissions so that we can set the context class loader to
+  // null for daemon threads to avoid class loader leak.
+  // DERBY-3745
+  permission java.lang.RuntimePermission "getClassLoader";
+  permission java.lang.RuntimePermission "setContextClassLoader";
+
+  permission java.security.SecurityPermission "getPolicy";
+   
+  permission java.io.FilePermission "${derby.system.home}${/}derby.properties", "read";
+  permission java.io.FilePermission "${derby.system.home}${/}derby.log", "read, write, delete";
+  permission java.io.FilePermission "${derby.system.home}", "read";
+  permission java.io.FilePermission "${derby.system.home}${/}-", "read, write, delete";
+
+  // combination of client and server side.
+  permission java.net.SocketPermission "127.0.0.1", "accept,connect,resolve";
+  permission java.net.SocketPermission "localhost", "accept,connect,resolve";
+  permission java.net.SocketPermission "${derbyTesting.clienthost}", "accept,connect";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "connect,resolve";
+  
+  // Access all files under ${user.dir}to write the test directory structure
+  // Also covers extin, extout and extinout locations
+  permission java.io.FilePermission "${user.dir}${/}-", "read,write,delete"; 
+    
+  // These permissions are needed to load the JCE for encryption with Sun and IBM JDK131.
+  // JDK14 has the JCE  preloaded
+  permission java.security.SecurityPermission "insertProvider.SunJCE";
+  permission java.security.SecurityPermission "insertProvider.IBMJCE";
+
+  // When running with useprocess=false need to install and uninstall
+  // the security manager and allow setIO to change the system err and out
+  // 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";
+  
+    // Allow MBeanTest to register the application management MBean.
+  permission javax.management.MBeanServerPermission "createMBeanServer";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#[org.apache.derby:type=Management]","registerMBean,unregisterMBean";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#-[-]", "instantiate";
+  permission javax.management.MBeanTrustPermission "register";
+  
+  // Allows access to Derby's built-in MBeans, within the domain org.apache.derby.
+  permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]","registerMBean,unregisterMBean";
+  
+   
+  // And to find and use Derby's MBeans
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#[org.apache.derby:*]", "getAttribute,invoke";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "getMBeanInfo";
+  permission javax.management.MBeanPermission "-#-[-]", "queryNames";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "queryNames";
+  
+  // Test code needs this as well for the platform MBeanServer
+  // tests where the testing code is in the stack frame.
+  permission org.apache.derby.security.SystemPermission "jmx", "control";
+  permission org.apache.derby.security.SystemPermission "engine", "monitor";
+  permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+};
+
+// JUnit jar file tries to read junit.properties in the user's
+// home directory and seems to require permission to read the
+// property user.home as well.
+// junit.swingui.TestRunner writes to .junitsession on exit.
+grant codeBase "${derbyTesting.junit}" {
+    permission java.util.PropertyPermission "user.home", "read";
+    permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
+    permission java.io.FilePermission "${user.home}${/}.junitsession", "write";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}-", "read, write, delete";
+  
+    // These permissions are needed when testing code instrumented with EMMA.
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+};
+
+// Due to a problem running tests/derbynet/CompatibilityTest in the old test
+// harness, permission to read junit.properties is granted to all. This can be 
+// removed when CompatibilityTest is rewritten to conform to our current Junit
+// usage. See DERBY-2076.
+grant {
+    permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
+};
+
+// Ant's junit runner requires setOut to redirect the System output streams
+// to the forked JVM used when running junit tests inside Ant. Ant requires
+// forking the JVM if you want to run tests in a different directory than the
+// current one.
+grant codeBase "${derbyTesting.antjunit}" {
+    permission java.lang.RuntimePermission "setIO";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+
+    // These permissions are needed when testing code instrumented with EMMA.
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+};
+
+// functionTests.tests.lang.RoutineSecurityTest requires this grant
+// to check to see if permissions are granted through generated code
+// through this mechanism.
+grant {
+    permission java.util.PropertyPermission "derbyRoutineSecurityTest.yes", "read";
+};
+
+// When inserting XML values that use external DTD's, the JAXP parser
+// needs permission to read the DTD files.  We assume that all DTD
+// files will be copied to extin/ by whichever tests need them.  So
+// grant the JAXP parser permissions to read that directory.
+grant codeBase "${derbyTesting.jaxpjar}" {
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
+};
+
+
+// These permissions are needed when testing code instrumented with EMMA.
+// They are all related to writing coverage statistics to a file that by default
+// is named coverage.ec placed in the directory where the test is executed.
+grant codeBase "${derbyTesting.emma}" {
+    permission java.util.PropertyPermission "user.dir", "read";
+    permission java.io.FilePermission "${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "writeFileDescriptor";
+};
+
+// Permissions for package-private tests run from 'classes.pptesting'
+grant codeBase "${derbyTesting.ppcodeclasses}" {
+
+  // Needed for ProtocolTest - allows connection to a server
+  permission java.net.SocketPermission "127.0.0.1", "connect,resolve";
+  permission java.net.SocketPermission "localhost", "connect,resolve";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "connect,resolve";
+
+  // Allows reading support files in 'extin'
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
+};

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/MaxLogNumberRecovery.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/MaxLogNumberRecovery.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/MaxLogNumberRecovery.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/MaxLogNumberRecovery.java Thu Jan 13 03:56:34 2011
@@ -20,6 +20,7 @@
  */
 
 package org.apache.derbyTesting.functionTests.tests.store;
+import java.security.AccessController;
 import java.sql.Connection;
 import java.sql.SQLException;
 import org.apache.derby.tools.ij;
@@ -84,11 +85,37 @@ public class MaxLogNumberRecovery extend
 		logMessage("End MaxLogNumberRecovery Test");
 	}
 
-	
+
+    /**
+     * Set system property
+     *
+     * @param name name of the property
+     * @param value value of the property
+     */
+    private static void setSystemProperty(final String name, 
+                        final String value)
+    {
+    
+    AccessController.doPrivileged
+        (new java.security.PrivilegedAction(){
+            
+            public Object run(){
+            System.setProperty( name, value);
+            return null;
+            
+            }
+            
+        }
+         );
+    
+    }
 	public static void main(String[] argv) throws Throwable {
 		
         MaxLogNumberRecovery test = new MaxLogNumberRecovery();
    		ij.getPropertyArg(argv); 
+        //DERBY -4856 will cause XSLAK create diagnostic information set the
+        //extenedDiagSeverityLevel higher so no thread dump or diagnostic info
+        setSystemProperty("derby.stream.error.extendedDiagSeverityLevel","50000");
         Connection conn = ij.startJBMS();
         conn.setAutoCommit(false);
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Thu Jan 13 03:56:34 2011
@@ -29,6 +29,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -290,6 +291,32 @@ public abstract class BaseTestCase
     }
     
     /**
+     * Get files in a directory which contain certain prefix
+     * 
+     * @param dir
+     *        The directory we are checking for files with certain prefix
+     * @param prefix
+     *        The prefix pattern we are interested.
+     * @retrun String[] The list indicates files with certain prefix.
+     */
+    protected static String[] getFilesWith(final File dir, String prefix) {
+        return (String[]) AccessController
+                .doPrivileged(new java.security.PrivilegedAction() {
+                    public Object run() {
+                        //create a FilenameFilter and override its accept-method to file
+                        //files start with "javacore"*
+                        FilenameFilter filefilter = new FilenameFilter() {
+                            public boolean accept(File dir, String name) {
+                                //if the file has prefix javacore return true, else false
+                                return name.startsWith("javacore");
+                            }
+                        };
+                        return dir.list(filefilter);
+                    }
+                });
+    }
+    
+    /**
      * Obtain the URL for a test resource, e.g. a policy
      * file or a SQL script.
      * @param name Resource name, typically - org.apache.derbyTesing.something
@@ -623,7 +650,15 @@ public abstract class BaseTestCase
     {
         DropDatabaseSetup.removeDirectory(dir);
     }
-
+ 
+    /**
+     * Remove all the files in the list
+     * @param list the list contains all the files
+     */
+    public static void removeFiles(String[] list)
+    {
+        DropDatabaseSetup.removeFiles(list);
+    }
     /**
      * Fail; attaching an exception for more detail on cause.
      *

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java Thu Jan 13 03:56:34 2011
@@ -134,4 +134,19 @@ class DropDatabaseSetup extends BaseTest
 
         assertTrue(dir.getPath(), dir.delete());
     }
+    
+    /**
+     * Remove all the files in the list
+     * @param list the list of files that will be deleted
+     **/
+    static void removeFiles(String[] list) {
+        for (int i = 0; i < list.length; i++) {
+             try {
+                 File dfile = new File(list[i].toString());            
+                 assertTrue(list[i].toString(), dfile.delete());
+             } catch (IllegalArgumentException e) {
+                 fail("open file error");
+             }
+        }
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_FileSystemData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_FileSystemData.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_FileSystemData.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_FileSystemData.java Thu Jan 13 03:56:34 2011
@@ -183,7 +183,8 @@ public class T_FileSystemData extends T_
 
 		} catch (StandardException se) {
 
-			cm1.cleanupOnError(se);
+            //Assume database is not active. DERBY-4856 thread dump
+            cm1.cleanupOnError(se, false);
 			throw T_Fail.exceptionFail(se);
 		}
 		finally {
@@ -209,7 +210,8 @@ public class T_FileSystemData extends T_
 		}
 		catch (StandardException se) {
 
-			cm1.cleanupOnError(se);
+            //Assume database is not active. DERBY-4856 thread dump
+            cm1.cleanupOnError(se, false);
 			throw T_Fail.exceptionFail(se);
 		}
 		finally {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java Thu Jan 13 03:56:34 2011
@@ -21,6 +21,7 @@
 
 package org.apache.derbyTesting.unitTests.store;
 
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.store.raw.*;
 
 // impl imports are the preferred way to create unit tests.
@@ -34,6 +35,7 @@ import org.apache.derby.iapi.services.mo
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
 import org.apache.derby.catalog.UUID;
+import org.apache.derby.iapi.db.Database;
 import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.iapi.error.ExceptionSeverity;
 import org.apache.derby.iapi.error.StandardException;
@@ -258,7 +260,8 @@ public class T_RawStoreFactory extends T
 
 		} catch (StandardException se) {
 
-			cm1.cleanupOnError(se);
+            //Assume database is not active. DERBY-4856 thread dump
+            cm1.cleanupOnError(se, false);
 			throw T_Fail.exceptionFail(se);
 		}
 		finally {
@@ -5480,7 +5483,8 @@ public class T_RawStoreFactory extends T
 			catch (StandardException se)
 			{
 				REPORT("cleanup on error");
-				cm1.cleanupOnError(se);
+                //Assume database is not active. DERBY-4856 thread dump
+                cm1.cleanupOnError(se, false);
 				REPORT("done cleanup on error");
 			}
 
@@ -7255,11 +7259,12 @@ public class T_RawStoreFactory extends T
 			t.printStackTrace(System.err);
 
 			if (cm1 != null)
-				cm1.cleanupOnError(t);
+                //Assume database is not active. DERBY-4856 thread dump
+                cm1.cleanupOnError(t, false);
 			if (cm2 != null)
-				cm2.cleanupOnError(t);
+                cm2.cleanupOnError(t, false);
 			//		if (cpm != null)
-			//			cpm.cleanupOnError(t);
+            //			cpm.cleanupOnError(t, false);
 
 		} finally {
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_StreamFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_StreamFile.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_StreamFile.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_StreamFile.java Thu Jan 13 03:56:34 2011
@@ -216,7 +216,8 @@ public class T_StreamFile extends T_Mult
 
 		} catch (StandardException se) {
 
-			cm1.cleanupOnError(se);
+            //Assume database is not active. DERBY-4856 thread dump
+            cm1.cleanupOnError(se, false);
 			throw T_Fail.exceptionFail(se);
 		}
 		finally {
@@ -241,7 +242,8 @@ public class T_StreamFile extends T_Mult
 		}
 		catch (StandardException se) {
 
-			cm1.cleanupOnError(se);
+            //Assume database is not active. DERBY-4856 thread dump
+            cm1.cleanupOnError(se, false);
 			throw T_Fail.exceptionFail(se);
 		}
 		finally {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java?rev=1058404&r1=1058403&r2=1058404&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java Thu Jan 13 03:56:34 2011
@@ -43,7 +43,9 @@ import org.apache.derby.iapi.services.co
 import org.apache.derby.iapi.services.context.ContextManager;
 import org.apache.derby.iapi.services.io.FormatIdUtil;
 
+import org.apache.derby.iapi.db.Database;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
 import org.apache.derby.iapi.store.access.AccessFactory;
 import org.apache.derby.iapi.store.access.ConglomerateController;
@@ -208,7 +210,7 @@ public class T_b2i extends T_MultiIterat
 			REPORT(msg);
 
             e.printStackTrace(out.getPrintWriter());
-            cm1.cleanupOnError(e);
+            cm1.cleanupOnError(e, isdbActive());
 
             pass = false;
 		}
@@ -220,7 +222,7 @@ public class T_b2i extends T_MultiIterat
 			REPORT(msg);
 
             t.printStackTrace(out.getPrintWriter());
-            cm1.cleanupOnError(t);
+            cm1.cleanupOnError(t, isdbActive());
 
             pass = false;
         }
@@ -861,7 +863,7 @@ public class T_b2i extends T_MultiIterat
                 if (SanityManager.DEBUG)
                     SanityManager.ASSERT(cm != null);
 
-                cm.cleanupOnError(e);
+                cm.cleanupOnError(e, isdbActive());
                 
                 // RESOLVE (mikem) - when split abort works come up with 
                 // a good sanity check here.
@@ -3267,7 +3269,7 @@ public class T_b2i extends T_MultiIterat
                 if (SanityManager.DEBUG)
                     SanityManager.ASSERT(cm != null);
 
-                cm.cleanupOnError(e);
+                cm.cleanupOnError(e, isdbActive());
             }
         }
 
@@ -5089,6 +5091,16 @@ public class T_b2i extends T_MultiIterat
 
 		return s;
 	}
+    
+    /** Check wheather the database is active or not
+     * @return {@code true} if the database is active, {@code false} otherwise
+     */
+    public boolean isdbActive() {
+        LanguageConnectionContext lcc = (LanguageConnectionContext) ContextService
+                .getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
+        Database db = (Database) (lcc != null ? lcc.getDatabase() : null);
+        return (db != null ? db.isActive() : false);
+    }
 
 }
 



Mime
View raw message