db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r473123 - in /db/derby/code/trunk: ./ java/testing/org/apache/derbyTesting/functionTests/suites/ java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ java/testing/org/apache/derbyTesting/junit/
Date Thu, 09 Nov 2006 22:49:57 GMT
Author: djd
Date: Thu Nov  9 14:49:55 2006
New Revision: 473123

URL: http://svn.apache.org/viewvc?view=rev&rev=473123
Log:
DERBY-2063 (partial) Change ShutdownDBWhenNSShutsDown from being a JUnit test run under the
old
harness to one that is run as a regular JUnit tests. Add a new _Suite for derbynet and hook
it
into suites.All and the ant junit-all target. Required fixing some bugs in the DriverManager
connection handling. Also refactored NetworkServerTestSetup to allow starting the server
from the "command line" and to provide some utility methods for tests, e.g. to get
a correctly setup NetworkServerControl.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ShutDownDBWhenNSShutsDownTest_app.properties
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ShutDownDBWhenNSShutsDownTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?view=diff&rev=473123&r1=473122&r2=473123
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Thu Nov  9 14:49:55 2006
@@ -1640,6 +1640,10 @@
   <target name="junit-all" depends="junit-init,junit-jdbc4">
     <antcall target="junit-oneclass">
       <param name="derby.junit.testname"
+             value="org.apache.derbyTesting.functionTests.tests.derbynet._Suite"/>
+    </antcall>
+    <antcall target="junit-oneclass">
+      <param name="derby.junit.testname"
              value="org.apache.derbyTesting.functionTests.tests.tools._Suite"/>
     </antcall>
     <antcall target="junit-oneclass">

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java?view=diff&rev=473123&r1=473122&r2=473123
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
Thu Nov  9 14:49:55 2006
@@ -51,6 +51,7 @@
 
         TestSuite suite = new TestSuite("AllPackages");
         
+        suite.addTest(org.apache.derbyTesting.functionTests.tests.derbynet._Suite.suite());
         suite.addTest(org.apache.derbyTesting.functionTests.tests.lang._Suite.suite());
         suite.addTest(org.apache.derbyTesting.functionTests.tests.jdbcapi._Suite.suite());
         suite.addTest(org.apache.derbyTesting.functionTests.tests.tools._Suite.suite());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall?view=diff&rev=473123&r1=473122&r2=473123
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
Thu Nov  9 14:49:55 2006
@@ -12,7 +12,6 @@
 derbynet/maxthreads.java
 derbynet/prepStmt.java
 derbynet/runtimeinfo.java
-derbynet/ShutDownDBWhenNSShutsDownTest.junit
 derbynet/sysinfo.java
 derbynet/sysinfo_withproperties.java
 derbynet/testProtocol.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ShutDownDBWhenNSShutsDownTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ShutDownDBWhenNSShutsDownTest.java?view=diff&rev=473123&r1=473122&r2=473123
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ShutDownDBWhenNSShutsDownTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ShutDownDBWhenNSShutsDownTest.java
Thu Nov  9 14:49:55 2006
@@ -20,18 +20,19 @@
 
 package org.apache.derbyTesting.functionTests.tests.derbynet;
 
-import java.util.Properties;
-import org.apache.derbyTesting.functionTests.util.TestUtil;
-import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.BaseTestCase;
-import org.apache.derbyTesting.junit.TestConfiguration;
-import org.apache.derby.drda.NetworkServerControl;
-
-import junit.framework.*;
-import java.sql.*;
-import java.io.PrintWriter;
 import java.io.File;
 import java.security.AccessController;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+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.NetworkServerTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
  * Derby-1274 - Network Server should shutdown the databases it has booted when
@@ -42,9 +43,30 @@
  * when started from the API.
  */
 public class ShutDownDBWhenNSShutsDownTest extends BaseJDBCTestCase {
-
-
-    NetworkServerControl server = null;
+    
+    /**
+     * Only run the fixtures in network server mode as that's what they are testing.
+     * @return
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("ShutDownDBWhenNSShutsDownTest");
+        
+        suite.addTest(TestConfiguration.clientServerDecorator(
+           new ShutDownDBWhenNSShutsDownTest(
+                   "testEngineShutdownDoesNotTakeDownNSManualReload")));
+
+        /* DERBY-2066
+        suite.addTest(TestConfiguration.clientServerDecorator(
+                new ShutDownDBWhenNSShutsDownTest(
+                        "testEngineShutdownDoesNotTakeDownNSAutoReload")));
+        */
+        
+        suite.addTest(TestConfiguration.clientServerDecorator(
+                new ShutDownDBWhenNSShutsDownTest(
+                        "testDatabasesShutDownWhenNSShutdownAPI")));
+      
+        return suite;
+    }
 
 
     /**
@@ -53,14 +75,38 @@
     public ShutDownDBWhenNSShutsDownTest(String name) {
         super(name);
     }
-
+    
+    /**
+     * Test the scenario from scenarioEngineShutdownDoesNotTakeDownNS
+     * reloading the embedded driver after the network server has shutdown.
+     * @throws Exception
+     */
+    public void testEngineShutdownDoesNotTakeDownNSManualReload() throws Exception
+    {
+        scenarioEngineShutdownDoesNotTakeDownNS(true);
+    }
+ 
+    /**
+     * Test the scenario from scenarioEngineShutdownDoesNotTakeDownNS
+     * relying on the network server to reloading the embedded driver
+     * after the network server has shutdown.
+     * @throws Exception
+     */
+    public void testEngineShutdownDoesNotTakeDownNSAutoReload() throws Exception
+    {
+        scenarioEngineShutdownDoesNotTakeDownNS(false);
+    }
+    
     /**
      * Test that a shutdown of the engine does not take down the network
      * server. Before DERBY-1326 was fixed, shutting down the engine would
      * leave the network server in an inconsistent state which could make
      * clients hang infinitely.
      */
-    public void testEngineShutdownDoesNotTakeDownNS() throws Exception {
+    private void scenarioEngineShutdownDoesNotTakeDownNS(
+            boolean loadEmbeddedDriver) throws Exception {
+            
+        
         Connection[] conns = new Connection[20];
 
         // first make sure there are 20 active worker threads on the server
@@ -81,6 +127,9 @@
 
         // shut down the engine
         TestConfiguration.getCurrent().shutdownEngine();
+        
+        if (loadEmbeddedDriver)
+            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
 
         // see if it is still possible to connect to the server (before
         // DERBY-1326, this would hang)
@@ -88,35 +137,32 @@
             openDefaultConnection().close();
         }
     }
-
+    
+    /**
+     * Test that the NetworkServer does not shut down the
+     * databases it has booted when started from the API.
+     * This fixture must be run with a clientServerDecorator().
+     */
+    public void testDatabasesShutDownWhenNSShutdownAPI()
+            throws Exception
+    {
+        // Check that the databases will not be shutdown when the server is
+        // shut down.
+        shutdownServerCheckDBShutDown(false);
+    }
+    
     /**
      * Test that the NetworkServer shuts down the databases it has booted when
      * started from the command line, and that it does not shut down the
      * databases it has booted when started from the API.
      */
-    public void testDatabasesShutDownWhenNSShutdown()
+    public void XXtestDatabasesShutDownWhenNSShutdown()
             throws Exception
     {
-        server = new NetworkServerControl();
-        // The server was started from the command line when the test was
+         // The server was started from the command line when the test was
         // started. Check that the database will be shut down when the server
         // is shut down.
         shutdownServerCheckDBShutDown(true);
-
-        // Start the server form the API and test that the databases will not
-        // be shutdown when the server is shutdown
-        server.start(null);
-
-        // wait until the server accepts connections
-        int i = 0;
-        while (!pingServer() && i < 10 ) {
-            Thread.sleep(1000);
-            i++;
-        }
-
-        // Check that the databases will not be shutdown when the server is
-        // shut down.
-        shutdownServerCheckDBShutDown(false);
     }
 
     /**
@@ -137,13 +183,16 @@
     {
         // connect to database
         createDatabase();
+        
+        NetworkServerControl server = NetworkServerTestSetup.getNetworkServerControl();
 
         // shut down the server
-        shutdownServer();
+        server.shutdown();
 
         // check if db.lck exists
         String fileName = getSystemProperty("derby.system.home") +
-                java.io.File.separator + "wombat" +
+                java.io.File.separator +
+                TestConfiguration.getCurrent().getDatabaseName() +
                 java.io.File.separator + "db.lck";
 
         boolean fileNotFound = false;
@@ -169,16 +218,6 @@
         return b.booleanValue();
     }
 
-    private boolean pingServer() {
-		try {
-			server.ping();
-		}
-		catch (Exception e) {
-			return false;
-		}
-		return true;
-    }
-
     private void createDatabase() throws SQLException {
         Connection conn = getConnection();
         conn.setAutoCommit(false);
@@ -189,9 +228,4 @@
         conn.commit();
         conn.close();
     }
-
-    private void shutdownServer() throws Exception {
-        server.shutdown();
-    }
-
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java?view=auto&rev=473123
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
Thu Nov  9 14:49:55 2006
@@ -0,0 +1,52 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet._Suite
+
+       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.derbynet;
+
+import org.apache.derbyTesting.junit.BaseTestCase;
+
+import junit.framework.Test; 
+import junit.framework.TestSuite;
+
+/**
+ * Suite to run all JUnit tests in this package:
+ * org.apache.derbyTesting.functionTests.tests.derbynet
+ *
+ */
+public class _Suite extends BaseTestCase  {
+
+    /**
+     * Use suite method instead.
+     */
+    private _Suite(String name) {
+        super(name);
+    }
+    
+    public static Test suite() {
+
+        TestSuite suite = new TestSuite("derbynet");
+        
+        suite.addTest(ShutDownDBWhenNSShutsDownTest.suite());
+        
+        return suite;
+    }
+    
+}
\ No newline at end of file

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java?view=diff&rev=473123&r1=473122&r2=473123
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java Thu Nov
 9 14:49:55 2006
@@ -69,7 +69,9 @@
     abstract void shutDatabase() throws SQLException;
    
     /**
-     * Shutdown the running derby system.
+     * Shutdown the running derby engine (not the network server).
+     * This method can only be called when the
+     * engine is running embedded in this JVM.
      * @return Nothing, exception is expected to be thrown with SQLState XJ015
      */
     abstract void shutEngine() throws SQLException;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java?view=diff&rev=473123&r1=473122&r2=473123
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
Thu Nov  9 14:49:55 2006
@@ -22,6 +22,7 @@
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.util.Properties;
 
 /**
  * Connection factory using DriverManager.
@@ -79,8 +80,8 @@
             if (!expectedState.equals(e.getSQLState()))
                 throw e;
             
-            url = url.concat(";create=true");
-            return DriverManager.getConnection(url, user, password);
+            return getConnectionByAttributes(url,
+                    "create", "true");          
         }
     }
 
@@ -89,24 +90,37 @@
      * with the user and password defined by the configuration.
      */
     public void shutDatabase() throws SQLException {
-        String url = config.getJDBCUrl();
-        url = url.concat(";shutdown=true");
-        DriverManager.getConnection(url,
-                config.getUserName(),
-                config.getUserPassword());
+        getConnectionByAttributes(config.getJDBCUrl(),
+                "shutdown", "true");
     }
 
     /**
      * Shutdown the engine using the attributes shutdown=true
      * and no database name with the user and password defined
      * by the configuration.
+     * Always shutsdown using the embedded URL thus this
+     * method will not work in a remote testing environment.
      */
     public void shutEngine() throws SQLException {
-        String url = config.getJDBCClient().getUrlBase();
-        url = url.concat(";shutdown=true");
-        DriverManager.getConnection("jdbc:derby:;shutdown",
-                config.getUserName(),
-                config.getUserPassword());        
+        
+        getConnectionByAttributes("jdbc:derby:", "shutdown", "true");        
+    }
+    
+    /**
+     * Open a connection using JDBC attributes with a JDBC URL.
+     * The attributes user and password are set from the configuration
+     * and then the passed in attribute is set.
+     */
+    private Connection getConnectionByAttributes(String url, String key, String value)
+        throws SQLException
+    {
+        Properties attributes = new Properties();
+        
+        attributes.setProperty("user", config.getUserName());
+        attributes.setProperty("password", config.getUserPassword());
+        attributes.setProperty(key, value);
+        
+        return DriverManager.getConnection(url, attributes);
     }
 
     /**

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=473123&r1=473122&r2=473123
==============================================================================
--- 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 Nov  9 14:49:55 2006
@@ -21,6 +21,7 @@
 
 import java.io.FileNotFoundException;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.PrintWriter;
@@ -34,8 +35,6 @@
  * Test decorator that starts the network server on startup
  * and stops it on teardown.
  * 
- * It does not start it if the test is configured to run in
- * embedded mode.
  *
  * Currently it will start the network server in the same VM
  * and it does not support starting it from a remote 
@@ -44,23 +43,34 @@
 final public class NetworkServerTestSetup extends TestSetup {
 
     private FileOutputStream serverOutput;
+    private final boolean asCommand;
     
     /**
      * Decorator this test with the NetworkServerTestSetup
      */
-    public NetworkServerTestSetup(Test test) {
+    public NetworkServerTestSetup(Test test, boolean asCommand) {
         super(test);
+        this.asCommand = asCommand;
     }
 
     /**
      * Start the network server.
      */
     protected void setUp() throws Exception {
+        BaseTestCase.println("Starting network server:");
         
-        TestConfiguration config = TestConfiguration.getCurrent();
+        networkServerController = getNetworkServerControl();
+        
+        if (asCommand)
+            startWithCommand();
+        else
+            startWithAPI();
         
-            BaseTestCase.println("Starting network server:");
+        waitForServerStart(networkServerController);
+    }
 
+    private void startWithAPI() throws Exception
+    {
             
             serverOutput = (FileOutputStream)
             AccessController.doPrivileged(new PrivilegedAction() {
@@ -77,33 +87,49 @@
                     return fos;
                 }
             });
-
-            networkServerController = new NetworkServerControl
-                (InetAddress.getByName(config.getHostName()), config.getPort());
             
             networkServerController.start(new PrintWriter(serverOutput));
-            
-            final long startTime = System.currentTimeMillis();
-            while (true) {
-                Thread.sleep(SLEEP_TIME);
-                try {
-                    networkServerController.ping();
-                    break;
-                } catch (Exception e) {
-                    if (System.currentTimeMillis() - startTime > WAIT_TIME) {
-                        e.printStackTrace();
-                        fail("Timed out waiting for network server to start");
-                    }
-                }
+   
+    }
+    
+    private void startWithCommand() throws Exception
+    {
+        final TestConfiguration config = TestConfiguration.getCurrent();
+        
+        // start the server through the command line
+        // arguments using a new thread to do so.
+        new Thread(
+        new Runnable() {
+            public void run() {
+                org.apache.derby.drda.NetworkServerControl.main(
+                        new String[] {
+                                "start",
+                                "-h",
+                                config.getHostName(),
+                                "-p",
+                                Integer.toString(config.getPort())
+                        });                
             }
+            
+        }, "NetworkServerTestSetup command").start();
     }
 
     /**
-     * Stop the network server.
+     * Stop the network server if it still
+     * appears to be running.
      */
     protected void tearDown() throws Exception {
         if (networkServerController != null) {
-            networkServerController.shutdown();
+            boolean running = false;
+            try {
+                networkServerController.ping();
+                running = true;
+            } catch (Exception e) {
+            }
+      
+            if (running)
+                networkServerController.shutdown();
+ 
             serverOutput.close();
         }
     }
@@ -116,4 +142,41 @@
     
     /** Sleep for 50 ms before pinging the network server (again) */
     private static final int SLEEP_TIME = 50;
+    
+    
+    /*
+     * Utility methods related to controlling network server.
+     */
+    
+    /**
+     * Return a new NetworkServerControl for the current configuration.
+     */
+    public static NetworkServerControl getNetworkServerControl()
+        throws Exception
+    {
+        TestConfiguration config = TestConfiguration.getCurrent();
+        return new NetworkServerControl
+        (InetAddress.getByName(config.getHostName()), config.getPort());
+    }
+    
+    /**
+     * Ping the server until it has started. Asserts a failure
+     * if the server has not started within sixty seconds.
+     */
+    public static void waitForServerStart(NetworkServerControl networkServerController)
+        throws InterruptedException {
+        final long startTime = System.currentTimeMillis();
+        while (true) {
+            Thread.sleep(SLEEP_TIME);
+            try {
+                networkServerController.ping();
+                break;
+            } catch (Exception e) {
+                if (System.currentTimeMillis() - startTime > WAIT_TIME) {
+                    e.printStackTrace();
+                    fail("Timed out waiting for network server to start");
+                }
+            }
+        }
+    }
 }



Mime
View raw message