db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r1545935 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/engine/ErrorStreamTest.java junit/BaseTestCase.java
Date Wed, 27 Nov 2013 06:14:25 GMT
Author: myrnavl
Date: Wed Nov 27 06:14:25 2013
New Revision: 1545935

URL: http://svn.apache.org/r1545935
Log:
DERBY-6380; Rolling log files do not get copied in failed directory when a junit test fails
   adjusting ErrorStreamTest to copy files created in it on fail, and BaseTestCase to copy
defaults on fail.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ErrorStreamTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ErrorStreamTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ErrorStreamTest.java?rev=1545935&r1=1545934&r2=1545935&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ErrorStreamTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ErrorStreamTest.java
Wed Nov 27 06:14:25 2013
@@ -28,6 +28,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
@@ -36,7 +37,9 @@ import java.sql.SQLException;
 import junit.framework.Test;
 import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.Utilities;
 
 
 /**
@@ -59,6 +62,8 @@ public class ErrorStreamTest extends Bas
     private static final String DERBY_0_LOG = "derby-0.log";
     private static final String DERBYLANGUAGELOG_QUERY_PLAN = "derby.language.logQueryPlan";
     
+    private static final String LOGFILESDIR = "logfilesdir";
+    
     /**
      * runNo keeps track of which run we are in to generate unique (within a
      * JUnit run) names for files that are used in the test. Has to be static.
@@ -112,7 +117,7 @@ public class ErrorStreamTest extends Bas
 
     public void tearDown() throws Exception {
         resetProps();
-        deleteStreamFiles();
+        closeStreams();
         nullFields();
         super.tearDown();
     }
@@ -580,7 +585,7 @@ public class ErrorStreamTest extends Bas
         assertIsEmpty(errStreamFile);
 
         boolean deleted = deleteFile(derby0log);
-        assertTrue("File " + derby0log + " could not be deleted", deleted);    
+        assertTrue("File " + derby0log + " could not be deleted", deleted);
     }
 
     /**
@@ -598,14 +603,16 @@ public class ErrorStreamTest extends Bas
 
     private void openStreams() throws IOException{
         String systemHome = getSystemProperty("derby.system.home");
+        String logFilesHome=systemHome + File.separatorChar + LOGFILESDIR;
         makeDirIfNotExisting(systemHome);
+        makeDirIfNotExisting(logFilesHome);
 
         runNo += 1;
 
-        methodStreamFile = new File(systemHome, makeStreamFilename("method"));
-        fileStreamFile = new File(systemHome, makeStreamFilename("file"));
-        fieldStreamFile = new File(systemHome, makeStreamFilename("field"));
-        errStreamFile = new File(systemHome, makeStreamFilename("err"));
+        methodStreamFile = new File(logFilesHome, makeStreamFilename("method"));
+        fileStreamFile = new File(logFilesHome, makeStreamFilename("file"));
+        fieldStreamFile = new File(logFilesHome, makeStreamFilename("field"));
+        errStreamFile = new File(logFilesHome, makeStreamFilename("err"));
 
         methodStream = newFileOutputStream(methodStreamFile);
         fieldStream = newFileOutputStream(fieldStreamFile);
@@ -784,4 +791,67 @@ public class ErrorStreamTest extends Bas
         getConnection().close();
     }
 
+    /**
+     * <p>
+     * Run the bare test, including {@code setUp()} and {@code tearDown()}.
+     * </p>
+     *
+     * <p>
+     * This is overriding BaseJDBCTestCase.runBareOverridable and thereby
+     * BaseJDBCTestCase.runBare(), so we can copy any log files created by this
+     * test if any of the fixtures fail. 
+     * </p>
+     */
+    public void runBareOverridable() throws Throwable {
+        PrintStream out = System.out;
+        TestConfiguration config = getTestConfiguration();
+        boolean stopAfterFirstFail = config.stopAfterFirstFail();
+        try {
+            super.runBareOverridable();   
+        }
+        // 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());
+                // Copy the logfiles dir
+                File origLogFilesDir = new File(DEFAULT_DB_DIR, LOGFILESDIR);
+                File newLogFilesDir = new File (failPath, LOGFILESDIR);
+                PrivilegedFileOpsForTests.copy(origLogFilesDir,newLogFilesDir);
+                nullFields();
+                removeDirectory(origLogFilesDir);
+           }
+            catch (IOException ioe) {
+                // We need to throw the original exception so if there
+                // 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();
+                }
+                if (stopAfterFirstFail) {
+                    // if run with -Dderby.tests.stopAfterFirstFail=true
+                    // exit after reporting failure. Useful for debugging
+                    // cascading failures or errors that lead to hang.
+                    running.printStackTrace(out);
+                    System.exit(1);
+                }
+                else
+                    throw running;
+            }
+        }
+        finally{
+            File origLogFilesDir = new File(DEFAULT_DB_DIR, LOGFILESDIR);
+            nullFields();
+            removeDirectory(origLogFilesDir);
+        }
+    }
 }

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=1545935&r1=1545934&r2=1545935&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 Wed Nov
27 06:14:25 2013
@@ -135,6 +135,15 @@ public abstract class BaseTestCase
                 File origLog = new File(DEFAULT_DB_DIR, DERBY_LOG);
                 File newLog = new File(failPath, DERBY_LOG);
                 PrivilegedFileOpsForTests.copy(origLog, newLog);
+                // Copy some other likely files, the rolling log files
+                // These might occur if the tests are run with 
+                // derby.stream.error.style=rollingFile
+                for (int i=0; i < 10; i++) {
+                    String logName = "derby-" + i + ".log";
+                    File origRolLog = new File(DEFAULT_DB_DIR, logName);
+                    File newRolLog = new File(failPath, logName);
+                    PrivilegedFileOpsForTests.copy(origRolLog, newRolLog);
+                }
                 // Copy the database.
                 String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
                 File dbDir = new File(DEFAULT_DB_DIR, dbName );



Mime
View raw message