db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r718616 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java
Date Tue, 18 Nov 2008 14:30:55 GMT
Author: myrnavl
Date: Tue Nov 18 06:30:55 2008
New Revision: 718616

URL: http://svn.apache.org/viewvc?rev=718616&view=rev
Log:
DERBY-1465; NetworkServerControl.start() should throw an exception - not just
  print an exception - if the server fails to start
  Patch initially contributed by Kathey Marsden.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=718616&r1=718615&r2=718616&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Tue Nov 18 06:30:55 2008
@@ -232,6 +232,7 @@
 	private String encPrvArg;
 	private String hostArg = DEFAULT_HOST;	
 	private InetAddress hostAddress;
+	private Exception runtimeException=null;
 	private int sessionArg;
 	private boolean unsecureArg;
 
@@ -332,6 +333,13 @@
 	private static final int SSL_PEER_AUTHENTICATION = 2;
 
 	private int sslMode = SSL_OFF;
+    
+	/* object to wait on and notify; so we can monitor if a server
+	 * was successfully started */
+	private Object serverStartComplete = new Object();
+
+	/* for flagging complete boot */
+	private boolean completedBoot = false;
 
     /**
      * Can EUSRIDPWD security mechanism be used with 
@@ -636,14 +644,37 @@
 	 *		   
 	 * @exception Exception	throws an exception if an error occurs
 	 */
-	public void start(PrintWriter consoleWriter)
+	public void start(final PrintWriter consoleWriter)
 		throws Exception
 	{
-		DRDAServerStarter starter = new DRDAServerStarter();
-		starter.setStartInfo(hostAddress,portNumber,consoleWriter);
-        this.setLogWriter(consoleWriter);
-		startNetworkServer();
-		starter.boot(false,null);
+		// creating a new thread and calling blockingStart on it
+		// This is similar to calling DRDAServerStarter.boot().
+		// We save any exception from the blockingStart and 
+		// return to the user later. See DERBY-1465.
+		Thread t = new Thread("NetworkServerControl") {
+
+		public void run() {
+			try {
+				blockingStart(consoleWriter);
+			} catch (Exception e) {
+				runtimeException = e;
+			}
+		}
+	};
+		// make it a daemon thread so it exits when the jvm exits
+		t.setDaemon(true);
+		// if there was an immediate error like
+		// another server already running, throw it here.
+		// ping is still required to verify the server is
+		// up.     
+
+		t.start();
+		synchronized(serverStartComplete){
+		while (!completedBoot )
+			serverStartComplete.wait();
+		}
+		if (runtimeException != null)
+			throw runtimeException; 
 	}
 
 	/**
@@ -700,8 +731,8 @@
 	public void blockingStart(PrintWriter consoleWriter)
 		throws Exception
 	{
-		startNetworkServer();
 		setLogWriter(consoleWriter);
+		startNetworkServer();
 		cloudscapeLogWriter = Monitor.getStream().getPrintWriter();
 		if (SanityManager.DEBUG && debugOutput)
 		{
@@ -746,6 +777,11 @@
 		// If we find other (unexpected) errors, we ultimately exit--so make
 		// sure we print the error message before doing so (Beetle 5033).
 			throwUnexpectedException(e);
+		} finally {
+			synchronized (serverStartComplete) {
+				completedBoot = true;
+				serverStartComplete.notifyAll();
+			}
 		}
         
 		switch (getSSLMode()) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java?rev=718616&r1=718615&r2=718616&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java
Tue Nov 18 06:30:55 2008
@@ -54,6 +54,16 @@
         ResultSet rs = stmt
         .executeQuery("Select  tablename   from  sys.systables");
         JDBC.assertDrainResults(rs);
+        
+        // DERBY-1465 - starting another server on the same
+        // port fails and should throw an exception as well as log it
+        try { 
+            serverControl.start(null);
+            fail ("Should have gotten an exception - see DERBY-1465");
+        } catch (Exception e) {
+            assertTrue(e.getMessage().indexOf("java.net.BindException") > 1);
+        }
+        
         // Leave the connection open before shutdown
         serverControl.shutdown();
     }



Mime
View raw message