db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r942286 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/suites/ functionTests/tests/store/ junit/
Date Sat, 08 May 2010 00:37:26 GMT
Author: dag
Date: Sat May  8 00:37:25 2010
New Revision: 942286

URL: http://svn.apache.org/viewvc?rev=942286&view=rev
Log:
DERBY-4179 bootLock.java fails with missing exception on z/OS with pmz3160sr2ifix-20081021_01(SR2+IZ32776+IZ33456),
and Windows Vista

Patch derby-4179-junit-5:

* Rewrite of boot lock test to JUnit, this also solves the problem
  with running with jars in relative classpaths.

* Added test of effectiveness of derby.database.forceDatabaseLock for
  phoneME platforms, until we implement DERBY-4646. (I could not find
  any other such test).

* Fixed JUnit harness to correctly fork a Sun phoneME vm (image name
  is cvm, not java),

* Added logic to capture what happens to minion (if it fails) by
  capturing its stderr (if it ever gets started, that is), cf. example enclosed.

* Added socket logic to communicate to parent when minion has booted
  the "dual boot" candidate to avoid having to wait for 30 seconds or
  more to be sure it has done so. Test now runs in a few seconds.

* Skips test for j9 for now, since this platform fails on the fork
  operation according to Kathey, cf DERBY-4647.


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/bootLock.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/bootLock.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/bootLock1.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/bootLock_app.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall?rev=942286&r1=942285&r2=942286&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
Sat May  8 00:37:25 2010
@@ -22,7 +22,6 @@ store/rollForwardRecovery.sql
 store/readlocks.sql
 store/backupRestore.sql
 store/backupRestore1.java
-store/bootLock.java
 store/bug3498.sql
 store/Beetle6038.java
 store/TestDurabilityProperty.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java?rev=942286&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java
Sat May  8 00:37:25 2010
@@ -0,0 +1,76 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.store.BootLockMinion
+
+   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.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.store;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.net.Socket;
+import java.lang.Integer;
+
+import org.apache.derby.jdbc.EmbeddedSimpleDataSource;
+/**
+ * Create and boot the supplied db argument. This auxiliary program is used by
+ * {@code BootLockTest.java} to boot a db in a different jvm and subsequently
+ * attempt a boot to from the original VM to detect dual boot attempt.
+* <p>
+ * You can verify this subprogram by invoking it directly as:
+ * </p>
+ * <p>
+ * {@code java org.apache.derbyTesting.functionTests.tests.store.BootLockMinion <dbname>}
+ * </p>
+ */
+
+public class BootLockMinion {
+    public static void main(String[] args) {
+        String dbName = args[0];
+        int portNumber = Integer.decode(args[1]).intValue();
+        Connection con;
+        Statement stmt;
+        System.setProperty("derby.stream.error.file",
+                           "BootLockMinion.log");
+        try
+        {
+            EmbeddedSimpleDataSource ds = new EmbeddedSimpleDataSource();
+            ds.setDatabaseName(dbName);
+            ds.setCreateDatabase("create");
+
+            con = ds.getConnection();
+            stmt = con.createStatement();
+
+            stmt.execute("create table t1(i int)");
+
+            // Signal to parent that we have booted dbName, so it can try,
+            // too..
+            Socket parentS;
+            parentS = new Socket("localhost", portNumber);
+
+            //infinite loop until we get killed by BootLockTest.java
+            for(;;)
+            {
+                Thread.sleep(30000);
+            }
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java?rev=942286&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java
Sat May  8 00:37:25 2010
@@ -0,0 +1,280 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.store.BootLockTest
+
+   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.
+
+ */
+package org.apache.derbyTesting.functionTests.tests.store;
+
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.lang.Integer;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.net.SocketTimeoutException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+
+import org.apache.derby.iapi.store.raw.data.DataFactory;
+
+/**
+ * Testing for FileLocks that prevent Derby Double Boot.
+ * <p/>
+ * For Sun phoneME, test that the property {@code
+ * derby.database.forceDatabaseLock} protects us.
+ * <p/>
+ * FIXME: If DERBY-4646 is fixed, the special handling for phoneME
+ * should be removed.
+ */
+
+public class BootLockTest extends BaseJDBCTestCase {
+
+    private final static String dbName = "BootLockTestDB";
+
+    private static String[] cmd = new String[]{
+        "org.apache.derbyTesting.functionTests.tests.store.BootLockMinion",
+        DEFAULT_DB_DIR + File.separator + dbName,
+        ""
+    };
+
+    private final static String DATA_MULTIPLE_JBMS_ON_DB = "XSDB6";
+    private final static String DATA_MULTIPLE_JBMS_FORCE_LOCK = "XSDB8";
+
+    /**
+     * Constructor
+     *
+     * @param name
+     */
+    public BootLockTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Creates a suite with two testcases, with and without some extra
+     * system properties.
+     *
+     * @return The test suite with both English and German locales.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("BootLockTest");
+
+        if (BaseTestCase.isJ9Platform()) {
+            // forking currently not working, cf. DERBY-4179.
+            return suite;
+        }
+
+        suite.addTest(decorateTest());
+        return suite;
+    }
+
+
+    /**
+     * Decorate test with singleUseDatabaseDecorator and noSecurityManager.
+     *
+     * @return the decorated test
+     */
+    private static Test decorateTest() {
+
+        Test test = new TestSuite(BootLockTest.class);
+
+        test = TestConfiguration.singleUseDatabaseDecorator(test, dbName);
+
+        test = SecurityManagerSetup.noSecurityManager(test);
+
+        return test;
+    }
+
+    String oldPropValue = null;
+
+    protected void setUp() throws Exception {
+
+        super.setUp();
+
+        // For phoneMe, we won't see DATA_MULTIPLE_JBMS_ON_DB, but instead we
+        // can check that we get DATA_MULTIPLE_JBMS_FORCE_LOCK if we set
+        // derby.database.forceDatabaseLock.
+
+        // FIXME: I tried to use the DatabasePropertyTestSetup.singleProperty,
+        // but for some reason it failed to do the job, no matter where in the
+        // decorator stack in decorateTest I placed it. Should be investigated
+        // so this manual set/reset code of the property can be removed.
+
+        if (JDBC.vmSupportsJSR169()) {
+            oldPropValue =
+                System.getProperty("derby.database.forceDatabaseLock");
+            System.setProperty("derby.database.forceDatabaseLock", "true");
+        }
+    }
+
+
+    protected void tearDown() throws Exception {
+
+        if (JDBC.vmSupportsJSR169()) {
+
+            if (oldPropValue != null) {
+                System.setProperty("derby.database.forceDatabaseLock",
+                                   oldPropValue);
+            } else {
+                // FIXME: Java 1.5 only: improve code when we move to that
+                // source level.
+                // System.clearProperty("derby.database.forceDatabaseLock");
+                System.setProperty("derby.database.forceDatabaseLock",
+                                   "false");
+            }
+
+
+        }
+
+        super.tearDown();
+    }
+
+
+    public void testBootLock() throws Exception {
+
+        ServerSocket parentService = null;
+        Socket clientSocket = null;
+        BufferedReader minionSysErr = null;
+        Process p = null;
+
+        try {
+            int port = TestConfiguration.getCurrent().getPort();
+            cmd[2] = (new Integer(port)).toString();
+
+            p = execJavaCmd(cmd);
+
+            // Attempt to catch any errors happening in minion for better test
+            // diagnosis.
+            minionSysErr = new BufferedReader(
+                new InputStreamReader(p.getErrorStream()));
+
+            // Create a socket so we know when subprogram has booted.  Since we
+            // run this test only in embedded mode, (re)use derby server port.
+            parentService = new ServerSocket(port);
+            parentService.setSoTimeout(60000); // max we wait is 60s
+
+            try {
+
+                clientSocket = parentService.accept();
+
+            } catch (SocketTimeoutException e) {
+                p.destroy();
+                p.waitFor();
+
+                StringBuffer failmsg = new StringBuffer();
+                failmsg.append(
+                    "Minion did not start or boot db in 60 seconds.\n" +
+                    "----Minion's stderr:\n");
+
+                String minionErrLine= null ;
+                do {
+                    try {
+                        minionErrLine = minionSysErr.readLine();
+                    } catch (Exception ioe) {
+                        // may not always work, so just bail out.
+                        failmsg.append("could not read minion's stderr");
+                    }
+
+                    if (minionErrLine != null) {
+                        failmsg.append(minionErrLine);
+                    }
+                } while (minionErrLine != null);
+
+                failmsg.append("\n----Minion's stderr ended");
+
+                fail(failmsg.toString());
+            }
+
+            // We now know minion has booted
+
+
+            try {
+                Connection c = getConnection();
+                fail("Dual boot not detected: check BootLockMinion.log");
+            } catch (SQLException e) {
+                if (JDBC.vmSupportsJSR169()) {
+                    assertSQLState(
+                        "Dual boot not detected: check BootLockMinion.log",
+                        DATA_MULTIPLE_JBMS_FORCE_LOCK,
+                        e);
+                } else {
+                    assertSQLState(
+                        "Dual boot not detected: check BootLockMinion.log",
+                        DATA_MULTIPLE_JBMS_ON_DB,
+                        e);
+                }
+            }
+
+            p.destroy();
+            p.waitFor();
+
+            // Since all went OK, no need to keep the minion log file.
+            File minionLog = new File("BootLockMinion.log");
+            assertTrue(minionLog.delete());
+
+        } finally {
+            // Make sure we free up any socket resources
+            if (clientSocket != null) {
+                clientSocket.close();
+            }
+
+            if (parentService != null) {
+                parentService.close();
+            }
+
+            if (minionSysErr != null) {
+                minionSysErr.close();
+            }
+
+            // Get rid of minion in case test fails, otherwise redundant.
+            if (p != null) {
+                p.destroy();
+                p.waitFor();
+            }
+
+
+            if (JDBC.vmSupportsJSR169()) {
+                // Delete lock files so JUnit machinery can clean up the
+                // one-off database without further warnings on System.err
+                // (phoneMe).
+                File db_lockfile_name = new File(
+                    DEFAULT_DB_DIR + File.separator +
+                    dbName + File.separator +
+                    DataFactory.DB_LOCKFILE_NAME);
+
+                File db_ex_lockfile_name = new File(
+                    DEFAULT_DB_DIR + File.separator +
+                    dbName + File.separator +
+                    DataFactory.DB_EX_LOCKFILE_NAME);
+
+                db_lockfile_name.delete();
+                db_ex_lockfile_name.delete();
+            }
+        }
+    }
+
+}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java?rev=942286&r1=942285&r2=942286&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
Sat May  8 00:37:25 2010
@@ -57,6 +57,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(StreamingColumnTest.suite());
         suite.addTest(Derby3625Test.suite());
         suite.addTest(Derby151Test.suite());
+        suite.addTest(BootLockTest.suite());
         suite.addTest(PositionedStoreStreamTest.suite());
         suite.addTest(OSReadOnlyTest.suite());
         suite.addTest(BackupRestoreTest.suite());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml?rev=942286&r1=942285&r2=942286&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
Sat May  8 00:37:25 2010
@@ -84,26 +84,6 @@
         <pathelement path="${junit}"/>
       </classpath>
       <include name="${this.dir}/*.java"/>
-      <exclude name="${this.dir}/bootLock.java"/>
-    </javac>
-    <javac
-      source="1.4"
-      target="1.4"
-      bootclasspath="${empty}"
-      nowarn="on"
-      debug="true"
-      depend="${depend}"
-      deprecation="${deprecation}"
-      optimize="${optimize}"
-      proceed="${proceed}"
-      verbose="${verbose}" 
-      srcdir="${derby.testing.src.dir}"
-      destdir="${out.dir}">
-      <classpath>
-        <!--pathelement location="${oro}"/-->
-        <pathelement path="${java14compile.classpath}"/>
-      </classpath>
-      <include name="${this.dir}/bootLock.java"/>
     </javac>
   </target>
 

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=942286&r1=942285&r2=942286&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 Sat May
 8 00:37:25 2010
@@ -526,20 +526,38 @@ public abstract class BaseTestCase
 	    return pr;
 	}
 
-	/**
-         * Return the executable name for spawning java commands.
-         * This will be <path to j9>/j9  for j9 jvms.
-	 * @return full path to java executable.
-         */
-         public static final String getJavaExecutableName() {
-             String vmname = getSystemProperty("com.ibm.oti.vm.exe");
-             if (vmname == null)
-                 vmname = getSystemProperty("java.home") + File.separator + "bin" +
-                 File.separator +"java";
-             return vmname;
-         }
-          
-   
+    /**
+     * Return the executable name for spawning java commands.
+     * This will be <path to j9>/j9  for j9 jvms.
+     * @return full path to java executable.
+     */
+    public static final String getJavaExecutableName() {
+        String vmname = getSystemProperty("com.ibm.oti.vm.exe");
+
+        if (vmname == null) {
+            vmname = getSystemProperty("java.vm.name");
+
+            // Sun phoneME
+            if ("CVM".equals(vmname)) {
+                vmname = getSystemProperty("java.home") +
+                    File.separator + "bin" +
+                    File.separator + "cvm";
+            } else {
+                vmname = getSystemProperty("java.home") +
+                    File.separator + "bin" +
+                    File.separator + "java";
+            }
+        }
+        return vmname;
+    }
+
+    /**
+     * @return true if this is a j9 VM
+     */
+    public static final boolean isJ9Platform() {
+        return getSystemProperty("com.ibm.oti.vm.exe") != null;
+    }
+
    /**
     * Reads output from a process and returns it as a string.
     * This will block until the process terminates.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java?rev=942286&r1=942285&r2=942286&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
Sat May  8 00:37:25 2010
@@ -1,6 +1,6 @@
 /*
  *
- * Derby - Class org.apache.derbyTesting.functionTests.util.DatabasePropertyTestSetup
+ * Derby - Class org.apache.derbyTesting.junit.DatabasePropertyTestSetup
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=942286&r1=942285&r2=942286&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Sat May  8 00:37:25 2010
@@ -664,6 +664,26 @@ public class TestConfiguration {
         return new DatabaseChangeSetup(new DropDatabaseSetup(test, dbName), dbName, dbName,
true);
     }
 
+
+    /**
+     * Decorate a test to use a new database that is created upon the first
+     * connection request to the database and shutdown & deleted at
+     * tearDown. The configuration differs only from the current configuration
+     * by the list of used databases. The generated database name is added at
+     * the end of <code>usedDbNames</code> and assigned as a default database
+     * name.  This decorator expects the database file to be local so it can be
+     * removed.
+     * @param test Test to be decorated
+     * @param dbName We sometimes need to know outside to be able topass it on
+     *               to other VMs/processes.
+     * @return decorated test.
+     */
+    public static TestSetup singleUseDatabaseDecorator(Test test, String dbName)
+    {
+        return new DatabaseChangeSetup(
+            new DropDatabaseSetup(test, dbName), dbName, dbName, true);
+    }
+
     /**
      * Decorate a test to use a new database that is created upon the
      * first connection request to the database and deleted at



Mime
View raw message