Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 35332 invoked from network); 18 May 2009 11:49:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 May 2009 11:49:10 -0000 Received: (qmail 81480 invoked by uid 500); 18 May 2009 11:49:09 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 81431 invoked by uid 500); 18 May 2009 11:49:09 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 81422 invoked by uid 99); 18 May 2009 11:49:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 11:49:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 11:49:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0FEAB23888DC; Mon, 18 May 2009 11:48:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r775907 - in /db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting: functionTests/util/PrivilegedFileOpsForTests.java junit/BaseTestCase.java Date: Mon, 18 May 2009 11:48:44 -0000 To: derby-commits@db.apache.org From: kristwaa@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090518114845.0FEAB23888DC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kristwaa Date: Mon May 18 11:48:44 2009 New Revision: 775907 URL: http://svn.apache.org/viewvc?rev=775907&view=rev Log: DERBY-4199: Write exceptions to file in the fail directory as they occur with JUnit tests. Merged fix from trunk (revision 774729). Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java?rev=775907&r1=775906&r2=775907&view=diff ============================================================================== --- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java (original) +++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java Mon May 18 11:48:44 2009 @@ -259,6 +259,8 @@ /** * Returns a file output stream for the specified file. + *

+ * If the file already exists and is writable, it will be overwritten. * * @param file the file to create a stream for * @return An output stream. @@ -268,6 +270,22 @@ */ public static FileOutputStream getFileOutputStream(final File file) throws FileNotFoundException { + return getFileOutputStream(file, false); + } + + /** + * Returns a file output stream for the specified file. + * + * @param file the file to create a stream for + * @param append whether to append or overwrite an existing file + * @return An output stream. + * @throws FileNotFoundException if the specified file does not exist + * @throws SecurityException if the required permissions to write the file, + * or the path it is in, are missing + */ + public static FileOutputStream getFileOutputStream(final File file, + final boolean append) + throws FileNotFoundException { if (file == null) { throw new IllegalArgumentException("file cannot be "); } @@ -276,7 +294,7 @@ new PrivilegedExceptionAction() { public Object run() throws FileNotFoundException { - return new FileOutputStream(file); + return new FileOutputStream(file, append); } }); } catch (PrivilegedActionException pae) { Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=775907&r1=775906&r2=775907&view=diff ============================================================================== --- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original) +++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Mon May 18 11:48:44 2009 @@ -35,6 +35,7 @@ import java.io.OutputStream; import java.io.Reader; import java.io.PrintStream; +import java.io.PrintWriter; import java.net.URL; import java.sql.SQLException; import java.security.AccessController; @@ -104,13 +105,25 @@ try { super.runBare(); } - //To save the derby.log and database of failed tests. + // To log the exception to file, copy the derby.log file and copy + // the database of the failed test. catch (Throwable running) { + PrintWriter stackOut = null; try{ String failPath = PrivilegedFileOpsForTests.getAbsolutePath(getFailureFolder()); + // Write the stack trace of the error/failure to file. + stackOut = new PrintWriter( + PrivilegedFileOpsForTests.getFileOutputStream( + new File(failPath, "error-stacktrace.out"), true)); + stackOut.println("[Error/failure logged at " + + new java.util.Date() + "]"); + running.printStackTrace(stackOut); + stackOut.println(); // Add an extra blank line. + // Copy the derby.log file. File origLog = new File("system", "derby.log"); File newLog = new File(failPath, "derby.log"); PrivilegedFileOpsForTests.copy(origLog, newLog); + // Copy the database. String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName(); File dbDir = new File("system", dbName ); File newDbDir = new File(failPath, dbName); @@ -118,11 +131,19 @@ } catch (IOException ioe) { // We need to throw the original exception so if there - // is an exception saving the db or derby.log we will just - // print it. + // is an exception saving the db or derby.log we will print it + // and additionally try to log it to file. BaseTestCase.printStackTrace(ioe); + if (stackOut != null) { + stackOut.println("Copying derby.log or database failed:"); + ioe.printStackTrace(stackOut); + stackOut.println(); + } } finally { + if (stackOut != null) { + stackOut.close(); + } throw running; } }