db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r785139 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/replicationTests/ReplicationRun.java junit/BaseTestCase.java
Date Tue, 16 Jun 2009 09:58:33 GMT
Author: dag
Date: Tue Jun 16 09:58:33 2009
New Revision: 785139

URL: http://svn.apache.org/viewvc?rev=785139&view=rev
Log:
DERBY-4270 Make replication tests save derby.log and database when a failure occurs

Patch derby-4270-2 adds an overload of TestCase.runBare to
ReplicationRun which does this desired copying on the same pattern as
done for "normal" tests in BaseTestCase.runBare.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.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/replicationTests/ReplicationRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java?rev=785139&r1=785138&r2=785139&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
Tue Jun 16 09:58:33 2009
@@ -21,6 +21,8 @@
 package org.apache.derbyTesting.functionTests.tests.replicationTests;
 
 
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
+import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derby.drda.NetworkServerControl;
 import java.net.InetAddress;
 import java.util.Properties;
@@ -186,6 +188,74 @@
         super.tearDown();
     }
     
+    /**
+     * Run the test. Extra logic in addition to BaseTestCase's similar logic,
+     * to save derby.log and database files for replication directories if a
+     * failure happens.
+     */
+    public void runBare() throws Throwable {
+
+        try {
+
+            super.runBare();
+
+        } catch (Throwable running) {
+
+            // Copy the master and slave's derby.log file and databases
+            //
+            PrintWriter stackOut = null;
+
+            try {
+                String failPath = PrivilegedFileOpsForTests.
+                    getAbsolutePath(getFailureFolder());
+
+                stackOut = new PrintWriter(
+                        PrivilegedFileOpsForTests.getFileOutputStream(
+                            new File(failPath, ERRORSTACKTRACEFILE), true));
+
+                String[] replPaths = new String[]{masterDbSubPath,
+                                                  slaveDbSubPath};
+
+                for (int i=0; i < 2; i++) {
+                    // Copy the derby.log file.
+                    //
+                    File origLog = new File(replPaths[i], DERBY_LOG);
+                    File newLog = new File(failPath,
+                                           replPaths[i] + "-" + DERBY_LOG);
+                    PrivilegedFileOpsForTests.copy(origLog, newLog);
+
+                    // Copy the database.
+                    //
+                    String dbName = TestConfiguration.getCurrent().
+                        getDefaultDatabaseName();
+                    File dbDir = new File(replPaths[i], dbName );
+                    File newDbDir = new File(failPath,
+                                             replPaths[i] + "-" + dbName);
+                    PrivilegedFileOpsForTests.copy(dbDir,newDbDir);
+                }
+            } 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 db_slave/db_master's " +
+                                     DERBY_LOG + " or database failed:");
+                    ioe.printStackTrace(stackOut);
+                    stackOut.println();
+                }
+            } finally {
+                if (stackOut != null) {
+                    stackOut.close();
+                }
+
+                // Let JUnit take over
+                throw running;
+            }
+        }
+    }
+
+
     String useEncryption(boolean create)
     {
         String encryptionString = "";

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=785139&r1=785138&r2=785139&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 Tue Jun
16 09:58:33 2009
@@ -50,7 +50,10 @@
  */
 public abstract class BaseTestCase
     extends TestCase {
-    
+
+    protected final static String ERRORSTACKTRACEFILE = "error-stacktrace.out";
+    protected final static String DEFAULT_DB_DIR      = "system";
+    protected final static String DERBY_LOG           = "derby.log";
     /**
      * No argument constructor made private to enforce naming of test cases.
      * According to JUnit documentation, this constructor is provided for
@@ -114,18 +117,18 @@
                 // Write the stack trace of the error/failure to file.
                 stackOut = new PrintWriter(
                         PrivilegedFileOpsForTests.getFileOutputStream(
-                            new File(failPath, "error-stacktrace.out"), true));
+                            new File(failPath, ERRORSTACKTRACEFILE), 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");
+                File origLog = new File(DEFAULT_DB_DIR, 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 dbDir = new File(DEFAULT_DB_DIR, dbName );
                 File newDbDir = new File(failPath, dbName);
                 PrivilegedFileOpsForTests.copy(dbDir,newDbDir);
            }



Mime
View raw message