db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1396606 - in /db/derby/code/branches/10.9: ./ java/engine/org/apache/derby/impl/store/raw/log/ java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ java/testing/org/apache/derbyTesting/junit/
Date Wed, 10 Oct 2012 14:03:01 GMT
Author: kahatlen
Date: Wed Oct 10 14:03:00 2012
New Revision: 1396606

URL: http://svn.apache.org/viewvc?rev=1396606&view=rev
Log:
DERBY-5937: File handle is leaked when a Slave replication is shutdown with failover=true

Merged revisions 1392847, 1394407 and 1395482 from trunk, and manually
copied a missing method in TestConfiguration from trunk.

Added:
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java
      - copied, changed from r1392847, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.policy
      - copied unchanged from r1392847, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.policy
Modified:
    db/derby/code/branches/10.9/   (props changed)
    db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/build.xml
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Propchange: db/derby/code/branches/10.9/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1392847,1394407,1395482

Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=1396606&r1=1396605&r2=1396606&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
(original)
+++ db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
Wed Oct 10 14:03:00 2012
@@ -1182,7 +1182,15 @@ public final class LogToFile implements 
 				}
 
 				if (theLog != null)
+                {
+                    if (logOut != null)
+                    {
+                        // Close the currently open log file, if there is
+                        // one. DERBY-5937.
+                        logOut.close();
+                    }
 					logOut = new LogAccessFile(this, theLog, logBufferSize);
+                }
 				
 				if(logSwitchRequired)
 					switchLogFile();

Copied: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java
(from r1392847, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java)
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java?p2=db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java&r1=1392847&r2=1396606&rev=1396606&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java
(original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/Derby5937SlaveShutdownTest.java
Wed Oct 10 14:03:00 2012
@@ -24,12 +24,11 @@ package org.apache.derbyTesting.function
 import java.io.File;
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.Properties;
+import javax.sql.DataSource;
 import junit.framework.Test;
-import junit.framework.TestSuite;
 import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -64,19 +63,14 @@ public class Derby5937SlaveShutdownTest 
     }
 
     public static Test suite() {
-        if (JDBC.vmSupportsJDBC3()) {
-            Class klass = Derby5937SlaveShutdownTest.class;
-            // The default security policy doesn't allow derby.jar to do
-            // networking, which is needed for replication, so install a custom
-            // policy for this test.
-            return new SecurityManagerSetup(
-                TestConfiguration.singleUseDatabaseDecorator(
-                    TestConfiguration.embeddedSuite(klass), MASTER_DB),
-                klass.getName().replace('.', '/') + ".policy", true);
-        } else {
-            // The test doesn't run on J2ME.
-            return new TestSuite("Derby5937SlaveShutdownTest - skipped");
-        }
+        Class klass = Derby5937SlaveShutdownTest.class;
+        // The default security policy doesn't allow derby.jar to do
+        // networking, which is needed for replication, so install a custom
+        // policy for this test.
+        return new SecurityManagerSetup(
+            TestConfiguration.singleUseDatabaseDecorator(
+                TestConfiguration.embeddedSuite(klass), MASTER_DB),
+            klass.getName().replace('.', '/') + ".policy", true);
     }
 
     public void testSlaveFailoverLeak() throws Exception {
@@ -94,23 +88,25 @@ public class Derby5937SlaveShutdownTest 
         PrivilegedFileOpsForTests.copy(new File(masterDb), new File(slaveDb));
 
         // And start the slave.
-        SlaveThread slave = new SlaveThread(config);
+        DataSource startSlaveDS = JDBCDataSource.getDataSource(SLAVE_DB);
+        JDBCDataSource.setBeanProperty(startSlaveDS, "connectionAttributes",
+                "startSlave=true;slaveHost=" + config.getHostName() +
+                ";slavePort=" + config.getPort());
+        SlaveThread slave = new SlaveThread(startSlaveDS);
         slave.start();
 
-        Properties p = new Properties();
-        p.setProperty("startMaster", "true");
-        p.setProperty("slaveHost", config.getHostName());
-        p.setProperty("slavePort", String.valueOf(config.getPort()));
-
         // Start the master. This will fail until the slave is up, so do
         // it in a loop until successful or time runs out.
+        DataSource startMasterDS = JDBCDataSource.getDataSource();
+        JDBCDataSource.setBeanProperty(startMasterDS, "connectionAttributes",
+                "startMaster=true;slaveHost=" + config.getHostName() +
+                ";slavePort=" + config.getPort());
         long giveUp =
             System.currentTimeMillis() + NetworkServerTestSetup.getWaitTime();
         Connection c = null;
         while (c == null) {
             try {
-                c = config.openPhysicalConnection(masterDb,
-                        config.getUserName(), config.getUserPassword(), p);
+                c = startMasterDS.getConnection();
             } catch (SQLException sqle) {
                 slave.checkError(); // Exit early if the slave has failed
                 if (System.currentTimeMillis() > giveUp) {
@@ -129,11 +125,11 @@ public class Derby5937SlaveShutdownTest 
         slave.checkError();
 
         // Perform fail-over.
-        p.clear();
-        p.setProperty("failover", "true");
+        DataSource failoverDS = JDBCDataSource.getDataSource();
+        JDBCDataSource.setBeanProperty(
+                failoverDS, "connectionAttributes", "failover=true");
         try {
-            config.openPhysicalConnection(masterDb,
-                    config.getUserName(), config.getUserPassword(), p);
+            failoverDS.getConnection();
             fail("failover should receive exception");
         } catch (SQLException sqle) {
             assertSQLState(FAILOVER_SUCCESS, sqle);
@@ -143,12 +139,12 @@ public class Derby5937SlaveShutdownTest 
         // complete, so do it in a loop until successful or time runs out.
         giveUp =
             System.currentTimeMillis() + NetworkServerTestSetup.getWaitTime();
-        p.clear();
-        p.setProperty("shutdown", "true");
+        DataSource slaveShutdownDS = JDBCDataSource.getDataSource(SLAVE_DB);
+        JDBCDataSource.setBeanProperty(
+                slaveShutdownDS, "shutdownDatabase", "shutdown");
         while (true) {
             try {
-                config.openPhysicalConnection(slaveDb,
-                        config.getUserName(), config.getUserPassword(), p);
+                slaveShutdownDS.getConnection();
                 fail("Shutdown of slave database didn't throw an exception");
             } catch (SQLException sqle) {
                 if (DB_SHUTDOWN_SUCCESS.equals(sqle.getSQLState())) {
@@ -175,11 +171,11 @@ public class Derby5937SlaveShutdownTest 
      */
     private class SlaveThread extends Thread {
 
-        private final TestConfiguration config;
+        private final DataSource ds;
         private volatile Throwable error;
 
-        SlaveThread(TestConfiguration config) {
-            this.config = config;
+        SlaveThread(DataSource ds) {
+            this.ds = ds;
         }
 
         public void run() {
@@ -193,14 +189,8 @@ public class Derby5937SlaveShutdownTest 
         private void run_() throws Exception {
             println("Slave thread started.");
 
-            Properties p = new Properties();
-            p.setProperty("startSlave", "true");
-            p.setProperty("slaveHost", config.getHostName());
-            p.setProperty("slavePort", String.valueOf(config.getPort()));
-
             try {
-                config.openPhysicalConnection(config.getDatabasePath(SLAVE_DB),
-                        config.getUserName(), config.getUserPassword(), p);
+                ds.getConnection();
                 fail("startSlave should throw exception");
             } catch (SQLException sqle) {
                 assertSQLState("XRE08", sqle);

Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java?rev=1396606&r1=1396605&r2=1396606&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
(original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationSuite.java
Wed Oct 10 14:03:00 2012
@@ -84,8 +84,11 @@ public class ReplicationSuite extends Ba
             suite.addTest(ReplicationRun_Local_3_p6.suite());
 
             suite.addTest(ReplicationRun_Local_Derby4910.suite());
+
         }
 
+        suite.addTest(Derby5937SlaveShutdownTest.suite());
+
 		return suite;
 	}
 }

Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/build.xml?rev=1396606&r1=1396605&r2=1396606&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/build.xml
(original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/build.xml
Wed Oct 10 14:03:00 2012
@@ -58,7 +58,7 @@
 
 <!--             ============ Begin Targets ==============                -->
  
-  <target name="FTOtestsubdir" depends="compilet1"/>
+  <target name="FTOtestsubdir" depends="compilet1,copyfiles"/>
 
   <!-- mkdir / init target may not be necessary, just here for reference... -->
   <target name="init">
@@ -87,6 +87,11 @@
     </javac>
   </target>
 
+  <target name="copyfiles">
+    <copy todir="${out.dir}/${this.dir}">
+      <fileset dir="${derby.testing.src.dir}/${this.dir}" includes="*.policy"/>
+    </copy>
+  </target>
 
 <!--             ============= End Targets ==============                -->
 

Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1396606&r1=1396605&r2=1396606&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Wed Oct 10 14:03:00 2012
@@ -2048,4 +2048,16 @@ public final class TestConfiguration {
     {
         return getPassword(user, passwordToken);
     }
+
+    public final String getDatabasePath(String physicalDatabaseName)
+    {
+        String dbName = physicalDatabaseName.replace('/', File.separatorChar);
+        String dsh = BaseTestCase.getSystemProperty("derby.system.home");
+        if (dsh == null) {
+            Assert.fail("not implemented");
+        } else {
+            dbName = dsh + File.separator + dbName;
+        }
+        return dbName;
+    }
 }



Mime
View raw message