You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2010/06/18 20:11:48 UTC

svn commit: r956075 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store: BootLockMinion.java BootLockTest.java

Author: kmarsden
Date: Fri Jun 18 18:11:48 2010
New Revision: 956075

URL: http://svn.apache.org/viewvc?rev=956075&view=rev
Log:
DERBY-4667 BootLockTest.testBootLock() sometimes fails with connection refused.

Removed socket syncrhonization. Test will just wait for spawned java program
to create the lock file.


Modified:
    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

Modified: 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=956075&r1=956074&r2=956075&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockMinion.java Fri Jun 18 18:11:48 2010
@@ -54,12 +54,6 @@ public class BootLockMinion {
             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(;;)
             {

Modified: 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=956075&r1=956074&r2=956075&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootLockTest.java Fri Jun 18 18:11:48 2010
@@ -57,10 +57,15 @@ import org.apache.derby.iapi.store.raw.d
 public class BootLockTest extends BaseJDBCTestCase {
 
     private final static String dbName = "BootLockTestDB";
-
+    private final static String dbDir = DEFAULT_DB_DIR + File.separator + dbName;
+    private final static String dbLockFile = dbDir + File.separator +
+    DataFactory.DB_LOCKFILE_NAME;
+    private final static String dbExLockFile = dbDir + File.separator +
+    DataFactory.DB_EX_LOCKFILE_NAME;
+    
     private static String[] cmd = new String[]{
         "org.apache.derbyTesting.functionTests.tests.store.BootLockMinion",
-        DEFAULT_DB_DIR + File.separator + dbName,
+        dbDir,
         ""
     };
 
@@ -119,126 +124,97 @@ public class BootLockTest extends BaseJD
 
     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 the minion has booted the db.
-            // Since we run this test only in embedded mode, (re)use derby
-            // server port.
-            parentService = new ServerSocket(port);
-            parentService.setSoTimeout(60000); // maximally we wait 60s
-
-            try {
-
-                clientSocket = parentService.accept();
-
-            } catch (SocketTimeoutException e) {
-                p.destroy();
-                p.waitFor();
+        p = execJavaCmd(cmd);
+        waitForMinionBoot(p,60000);
 
-                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);
+        // We now know minion has booted
 
-                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(
+        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(
+            } else {
+                assertSQLState(
                         "Dual boot not detected: check BootLockMinion.log",
                         DATA_MULTIPLE_JBMS_ON_DB,
                         e);
-                }
             }
+        }
+        finally {
+            if (p!= null) {
+                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());
 
-            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(dbLockFile);                    
 
-            // Since all went OK, no need to keep the minion log file.
-            File minionLog = new File("BootLockMinion.log");
-            assertTrue(minionLog.delete());
+            File db_ex_lockfile_name = new File(dbExLockFile);                    
 
-        } finally {
-            // Make sure we free up any socket resources
-            if (clientSocket != null) {
-                clientSocket.close();
-            }
+            db_lockfile_name.delete();
+            db_ex_lockfile_name.delete();
+        }
+    }
 
-            if (parentService != null) {
-                parentService.close();
+    private void waitForMinionBoot(Process p, int waitmillis) throws InterruptedException {
+        StringBuffer failmsg = new StringBuffer();
+        // boolean set to true once we find the  lock file
+        File lockFile = new File(dbLockFile);
+        // Attempt to catch any errors happening in minion for better test
+        // diagnosis.
+        BufferedReader minionSysErr = new BufferedReader(
+            new InputStreamReader(p.getErrorStream()));
+        String minionErrLine= null ;
+        do {
+            if (lockFile.exists()) {
+                // if the lock file is there the database has booted, return
+                return;
             }
-
-            if (minionSysErr != null) {
-                minionSysErr.close();
+            // otherwise sleep for a second and try again
+            waitmillis -= 1000;
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                fail(e.getMessage());
+            }
+        } while (waitmillis > 0);
+        
+        // If we got here, the database did not boot. Try to print the error.
+        failmsg.append(
+                "Minion did not start or boot db in 60 seconds.\n" +
+                "----Minion's stderr:\n");
+        do {
+            try {
+                minionErrLine = minionSysErr.readLine();
+            } catch (Exception ioe) {
+                // may not always work, so just bail out.
+                failmsg.append("could not read minion's stderr");
             }
 
-            // Get rid of minion in case test fails, otherwise redundant.
-            if (p != null) {
-                p.destroy();
-                p.waitFor();
+            if (minionErrLine != null) {
+                failmsg.append(minionErrLine);
             }
+        } while (minionErrLine != null);
 
-
-            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();
-            }
-        }
+        failmsg.append("\n----Minion's stderr ended");
+        p.destroy();
+        p.waitFor();
+        fail(failmsg.toString());
     }
 
 }