db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r497549 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/AutoloadTest.java functionTests/tests/jdbcapi/JDBCDriversEmbeddedTest.java junit/NetworkServerTestSetup.java
Date Thu, 18 Jan 2007 19:48:59 GMT
Author: djd
Date: Thu Jan 18 11:48:59 2007
New Revision: 497549

URL: http://svn.apache.org/viewvc?view=rev&rev=497549
Log:
DERBY-1952 (partial) Add a test case to the AutoloadTest that sees if when
auto-loading the embedded driver via jdbc.drivers the network server is booted
correctly depending on the state of the property derby.drda.startNetworkServer.
Make the ping network server method in NetworkServerSetup more useful by
splitting it into two, one that pings for 60 seconds and returns if it
made contact, and the previous version which 'fails' if contact could not be made.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCDriversEmbeddedTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java?view=diff&rev=497549&r1=497548&r2=497549
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
Thu Jan 18 11:48:59 2007
@@ -28,8 +28,11 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.Derby;
 import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -119,6 +122,15 @@
         TestSuite suite = new TestSuite("AutoloadTest: " + which);
         
         suite.addTest(new AutoloadTest("testRegisteredDriver"));
+        if ("embedded".equals(which))
+        {
+            // Tests to see if the full engine is booted correctly
+            // when the embedded driver is autoloading
+            if (Derby.hasServer())
+                suite.addTest(new AutoloadTest("testAutoNetworkServerBoot"));
+
+        }
+            
         suite.addTest(new AutoloadTest("testSuccessfulConnect"));
         suite.addTest(new AutoloadTest("testUnsuccessfulConnect"));
         suite.addTest(new AutoloadTest("testExplicitLoad"));
@@ -212,6 +224,55 @@
             fail("Derby junit setup code is loading driver!");
         } catch (SQLException e) {
         }
+    }
+
+    /**
+     * Test that the auto-load of the network server is as expected.
+     * <P>
+     * derby.drda.startNetworkServer=false or not set
+     * <BR>
+     *     network server should not auto boot.
+     * <P>
+     * derby.drda.startNetworkServer=true
+     * <BR>
+     * If jdbc.drivers contains the name of the embedded driver
+     * then the server must be booted.
+     * <BR>
+     * Otherwise even if auto-loading the embedded driver due to JDBC 4
+     * auto-loading the network server must not boot. This is because
+     * the auto-loaded driver for JDBC 4 is a proxy driver that registers
+     * a driver but does not boot the complete embedded engine.
+     * @throws Exception 
+     * 
+     *
+     */
+    public void testAutoNetworkServerBoot() throws Exception
+    {
+        boolean nsAutoBoot = "true".equalsIgnoreCase(
+                getSystemProperty("derby.drda.startNetworkServer"));
+        
+        boolean serverShouldBeUp =
+            nsAutoBoot && fullEngineAutoBoot();
+        
+        NetworkServerControl control = new NetworkServerControl();
+        
+        boolean isServerUp = NetworkServerTestSetup.pingForServerStart(control);
+        
+        assertEquals("Network Server state incorrect",
+                serverShouldBeUp, isServerUp);
+        
+        if (isServerUp)
+            control.shutdown();
+    }
+    
+    /**
+     * Return true if a full auto-boot of the engine is expected
+     * due to jdbc.drivers containing the name of the embedded driver.
+     */
+    private boolean fullEngineAutoBoot()
+    {
+        String jdbcDrivers = getSystemProperty("jdbc.drivers");
+        return jdbcDrivers.indexOf("org.apache.derby.jdbc.EmbeddedDriver") != -1;
     }
 }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCDriversEmbeddedTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCDriversEmbeddedTest.java?view=diff&rev=497549&r1=497548&r2=497549
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCDriversEmbeddedTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCDriversEmbeddedTest.java
Thu Jan 18 11:48:59 2007
@@ -32,6 +32,11 @@
     
     public static Test suite() throws Exception
     {
+        // Also test that the network server comes up automatically
+        // when this property is set and the embedded driver
+        // is autoloaded by jdbc.drivers
+        System.setProperty("derby.drda.startNetworkServer", "true");
+ 
         return getSuite("org.apache.derby.jdbc.EmbeddedDriver");
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?view=diff&rev=497549&r1=497548&r2=497549
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
Thu Jan 18 11:48:59 2007
@@ -166,17 +166,29 @@
      * if the server has not started within sixty seconds.
      */
     public static void waitForServerStart(NetworkServerControl networkServerController)
-        throws InterruptedException {
+       throws InterruptedException 
+    {
+        if (!pingForServerStart(networkServerController))
+            fail("Timed out waiting for network server to start");
+    }
+    
+    /**
+     * Ping server for upto sixty seconds. If the server responds
+     * in that time then return true, otherwise return false.
+     * 
+     */
+    public static boolean pingForServerStart(NetworkServerControl networkServerController)
+        throws InterruptedException
+    {
         final long startTime = System.currentTimeMillis();
         while (true) {
             Thread.sleep(SLEEP_TIME);
             try {
                 networkServerController.ping();
-                break;
+                return true;
             } catch (Exception e) {
                 if (System.currentTimeMillis() - startTime > WAIT_TIME) {
-                    e.printStackTrace();
-                    fail("Timed out waiting for network server to start");
+                    return false;
                 }
             }
         }



Mime
View raw message