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 ka...@apache.org on 2006/09/25 15:03:17 UTC

svn commit: r449674 - in /db/derby/code/branches/10.2/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ testing/org/apache/derbyTesting/junit/

Author: kahatlen
Date: Mon Sep 25 06:03:16 2006
New Revision: 449674

URL: http://svn.apache.org/viewvc?view=rev&rev=449674
Log:
DERBY-1751: derbynet/testSecMec.java fails with ShutdownException in
DerbyNetClient framework

Merged fix from trunk.

Modified:
    db/derby/code/branches/10.2/java/drda/org/apache/derby/impl/drda/DRDAProtocolException.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestConnectionMethods.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java

Modified: db/derby/code/branches/10.2/java/drda/org/apache/derby/impl/drda/DRDAProtocolException.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/drda/org/apache/derby/impl/drda/DRDAProtocolException.java?view=diff&rev=449674&r1=449673&r2=449674
==============================================================================
--- db/derby/code/branches/10.2/java/drda/org/apache/derby/impl/drda/DRDAProtocolException.java (original)
+++ db/derby/code/branches/10.2/java/drda/org/apache/derby/impl/drda/DRDAProtocolException.java Mon Sep 25 06:03:16 2006
@@ -323,7 +323,7 @@
 		int svrcod, String rdbnam, String srvdgn)
 	{
         if ( SanityManager.DEBUG )
-            System.out.println("agentError in " + agent);
+            agent.trace("agentError in " + agent);
 		Object[] oa = {new Integer(svrcod), rdbnam, srvdgn};
 		return new DRDAProtocolException(DRDA_AgentError,
 										agent,

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java?view=diff&rev=449674&r1=449673&r2=449674
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java Mon Sep 25 06:03:16 2006
@@ -64,13 +64,7 @@
 	private static String hostName;
 	private static NetworkServerControl networkServer = null;
     
-    private SwitchablePrintStream consoleLogStream_;
-    private PrintStream originalStream_;
-    private FileOutputStream shutdownLogStream_;
-
-    private SwitchablePrintStream consoleErrLogStream_;
-    private PrintStream originalErrStream_;
-    private FileOutputStream shutdownErrLogStream_;
+    private static FileOutputStream serverOutput;
     
 	public static void main(String[] args) throws Exception {
 
@@ -94,31 +88,16 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-		
-		PrintStream originalStream = System.out;
-		FileOutputStream shutdownLogStream = 
-		    new FileOutputStream("dataSourcePermissions_net." + 
-					 System.getProperty("framework","") + "." + 
-					 "shutdown.std.log");
-		SwitchablePrintStream consoleLogStream = 
-		    new SwitchablePrintStream( originalStream );
-
-		PrintStream originalErrStream = System.err;
-		FileOutputStream shutdownErrLogStream = 
-		    new FileOutputStream("dataSourcePermissions_net." + 
-					 System.getProperty("framework","") + "." + 
-					 "shutdown.err.log");
-		SwitchablePrintStream consoleErrLogStream = 
-		    new SwitchablePrintStream( originalErrStream );
-		
-		System.setOut( consoleLogStream );
-		System.setErr( consoleErrLogStream );
+
+		String fileName = System.getProperty( "derby.system.home", "")
+			+ "serverConsoleOutput.log";
+		serverOutput = new FileOutputStream(fileName);
 
 		if (hostName.equals("localhost"))
 		{
 			// Start the NetworkServer on another thread
 			networkServer = new NetworkServerControl(InetAddress.getByName("localhost"),NETWORKSERVER_PORT);
-			networkServer.start(null);
+			networkServer.start(new PrintWriter(serverOutput));
 
 			// Wait for the NetworkServer to start.
 			if (!isServerStarted(networkServer, 60))
@@ -129,22 +108,12 @@
 		// Now, go ahead and run the test.
 		try {
 		    dataSourcePermissions_net tester = 
-			new dataSourcePermissions_net( consoleLogStream ,
-						       originalStream ,
-						       shutdownLogStream ,
-						       consoleErrLogStream ,
-						       originalErrStream,
-						       shutdownErrLogStream);
+			new dataSourcePermissions_net();
 			tester.setProperties();
 			tester.runTest();
 			if (TestUtil.isDerbyNetClientFramework())
 				tester.testClientDataSourceProperties();
-			new dataSourcePermissions_net( consoleLogStream , 
-						       originalStream ,
-						       shutdownLogStream ,
-						       consoleErrLogStream ,
-						       originalErrStream ,
-						       shutdownErrLogStream ).cleanUp();
+			new dataSourcePermissions_net().cleanUp();
 
 		} catch (Exception e) {
 		// if we catch an exception of some sort, we need to make sure to
@@ -159,15 +128,8 @@
 		// Shutdown the server.
 		if (hostName.equals("localhost"))
 		{
-		    
-			consoleLogStream.switchOutput( shutdownLogStream );
-			consoleErrLogStream.switchOutput( shutdownErrLogStream );
 			
 			networkServer.shutdown();
-			consoleLogStream.flush();
-			
-			consoleLogStream.switchOutput( originalStream );
-			consoleErrLogStream.switchOutput( originalErrStream );
 			
 			// how do we do this with the new api?
 			//networkServer.join();
@@ -175,29 +137,13 @@
 		}
 		System.out.println("Completed dataSourcePermissions_net");
 		
-		originalStream.close();
-		shutdownLogStream.close();
-
-		originalErrStream.close();
-		shutdownErrLogStream.close();
+		serverOutput.close();
 
 	}
 
 
-	public dataSourcePermissions_net( SwitchablePrintStream consoleLogStream,
-					  PrintStream originalStream,
-					  FileOutputStream shutdownLogStream,
-					  SwitchablePrintStream consoleErrLogStream,
-					  PrintStream originalErrStream, 
-					  FileOutputStream shutdownErrLogStream ) {
-	    
-	    consoleLogStream_ = consoleLogStream;
-	    originalStream_ = originalStream;
-	    shutdownLogStream_ = shutdownLogStream;
-
-	    consoleErrLogStream_ = consoleErrLogStream;
-	    originalErrStream_ = originalErrStream;
-	    shutdownErrLogStream_ = shutdownErrLogStream;
+	public dataSourcePermissions_net() {
+
 	    
 	}
     
@@ -308,32 +254,19 @@
 
 	public void shutdown() {
 	    
-	    try{
 		try {
-
-		    consoleLogStream_.switchOutput( shutdownLogStream_ );
-		    consoleErrLogStream_.switchOutput( shutdownErrLogStream_ );
 		    
 		    DriverManager.getConnection(TestUtil.getJdbcUrlPrefix(hostName,
 															  NETWORKSERVER_PORT) +
 										"wombat;shutdown=true",
 				"EDWARD", "noodle");
 		    
-		    consoleLogStream_.switchOutput( originalStream_ );
-		    consoleErrLogStream_.switchOutput( originalErrStream_);
-		    
 			System.out.println("FAIL - Shutdown returned connection");
 
 		} catch (SQLException sqle) {
-		    consoleLogStream_.switchOutput( originalStream_ );
-		    consoleErrLogStream_.switchOutput( originalErrStream_ );
 		    
 			System.out.println("EXPECTED SHUTDOWN " + sqle.getMessage());
 		}
-		
-	    } catch (IOException ioe){
-		originalStream_.println("Switching stream was failed. Could not complete test ... ");
-	    }
 		
 	}
 

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java?view=diff&rev=449674&r1=449673&r2=449674
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java Mon Sep 25 06:03:16 2006
@@ -153,21 +153,8 @@
 	private static int NETWORKSERVER_PORT;
 
 	private static NetworkServerControl networkServer = null;
-
-    private testSecMec(SwitchablePrintStream consoleLogStream,
-		       PrintStream originalStream,
-		       FileOutputStream shutdownLogStream,
-		       SwitchablePrintStream consoleErrLogStream, 
-		       PrintStream originalErrStream,
-		       FileOutputStream shutdownErrLogStream){
-	
-	super(consoleLogStream,
-	      originalStream,
-	      shutdownLogStream,
-	      consoleErrLogStream,
-	      originalErrStream,
-	      shutdownErrLogStream);
-    }
+    
+    private static FileOutputStream serverOutput;
 
 	public static void main(String[] args) throws Exception {
 		// Load harness properties.
@@ -189,24 +176,9 @@
 			e.printStackTrace();
 		}
 		
-		PrintStream originalStream = System.out;
-		FileOutputStream shutdownLogStream = 
-		    new FileOutputStream("testSecMec." + 
-					 System.getProperty("framework","") + "." + 
-					 "shutdown.std.log");
-		SwitchablePrintStream consoleLogStream = 
-		    new SwitchablePrintStream( originalStream );
-		
-		PrintStream originalErrStream = System.err;
-		FileOutputStream shutdownErrLogStream = 
-		    new FileOutputStream("testSecMec." + 
-					 System.getProperty("framework","") + "." + 
-					 "shutdown.err.log");
-		SwitchablePrintStream consoleErrLogStream = 
-		    new SwitchablePrintStream( originalErrStream );
-
-		System.setOut( consoleLogStream );
-		System.setErr( consoleErrLogStream );
+		String fileName = System.getProperty( "derby.system.home", "")
+				+ "serverConsoleOutput.log";
+		serverOutput = new FileOutputStream(fileName);
            
         // Start server with a specific value for derby.drda.securityMechanism
         // and run tests. Note connections will be successful or not depending on
@@ -227,7 +199,7 @@
 		        try
 		        {
 		            networkServer = new NetworkServerControl(InetAddress.getByName(hostName),NETWORKSERVER_PORT);
-		            networkServer.start(null);
+		            networkServer.start(new PrintWriter(serverOutput));
 		        }catch(Exception e)
 		        {
 		            if ( derby_drda_securityMechanism[i].equals("INVALID_VALUE")||
@@ -257,12 +229,7 @@
 		    // Now, go ahead and run the test.
 		    try {
 		        testSecMec tester = 
-		            new testSecMec(consoleLogStream,
-		                    originalStream,
-		                    shutdownLogStream,
-		                    consoleErrLogStream,
-		                    originalErrStream,
-		                    shutdownErrLogStream);
+		            new testSecMec();
                 // Now run the test, note connections will be successful or 
                 // throw an exception depending on derby.drda.securityMechanism 
                 // property specified on the server
@@ -281,29 +248,19 @@
 		    // Shutdown the server.
 		    if (hostName.equals("localhost"))
 		    {
-		        consoleLogStream.switchOutput( shutdownLogStream );
-		        consoleErrLogStream.switchOutput( shutdownErrLogStream );
-		        
+                
 		        networkServer.shutdown();
-		        consoleLogStream.flush();
 		        // how do we do this with the new api?
 		        //networkServer.join();
 		        Thread.sleep(5000);
 		        
-		        consoleLogStream.switchOutput( originalStream );
-		        consoleErrLogStream.switchOutput( originalErrStream );
-		        
 		    }
 
             // Now we want to test 
 		}
 		System.out.println("Completed testSecMec");
 
-		originalStream.close();
-		shutdownLogStream.close();
-
-		originalErrStream.close();
-		shutdownErrLogStream.close();
+		serverOutput.close();
 	}
     
 	// Indicates userid/encrypted password security mechanism.

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestConnectionMethods.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestConnectionMethods.java?view=diff&rev=449674&r1=449673&r2=449674
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestConnectionMethods.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestConnectionMethods.java Mon Sep 25 06:03:16 2006
@@ -24,9 +24,11 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.PrintWriter;
 import java.net.InetAddress;
 import java.sql.Blob;
 import java.sql.Clob;
@@ -50,6 +52,8 @@
 public class TestConnectionMethods {
     Connection conn = null;
     
+    private FileOutputStream serverOutput;
+    
     /**
      * Constructor for an object that is used for running test of the
      * new connection methods defined by JDBC 4.
@@ -322,6 +326,9 @@
         try {
             NetworkServerControl networkServer = new NetworkServerControl();
             networkServer.shutdown();
+            if (serverOutput != null) {
+                serverOutput.close();
+            }
         } catch(Exception e) {
             System.out.println("INFO: Network server shutdown returned: " + e);
         }
@@ -346,10 +353,14 @@
         }
 
         try {
+            String fileName = System.getProperty( "derby.system.home", "")
+                    + "serverConsoleOutput.log";
+            serverOutput = new FileOutputStream(fileName);
+
             NetworkServerControl networkServer = 
                      new NetworkServerControl(InetAddress.getByName(serverName), 
                                               serverPort);
-            networkServer.start(null);
+            networkServer.start(new PrintWriter(serverOutput));
 
             // Wait for the network server to start
             boolean started = false;

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?view=diff&rev=449674&r1=449673&r2=449674
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java Mon Sep 25 06:03:16 2006
@@ -19,8 +19,12 @@
  */
 package org.apache.derbyTesting.junit;
 
+import java.io.FileNotFoundException;
 import java.net.InetAddress;
+import java.io.FileOutputStream;
 import java.io.PrintWriter;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 import org.apache.derby.drda.NetworkServerControl;
@@ -38,6 +42,8 @@
  */
 final public class NetworkServerTestSetup extends TestSetup {
 
+    private FileOutputStream serverOutput;
+    
     /**
      * Decorator this test with the NetworkServerTestSetup
      */
@@ -54,10 +60,27 @@
         
         if (!config.getJDBCClient().isEmbedded()) {
             BaseTestCase.println("Starting network server:");
+
+            
+            serverOutput = (FileOutputStream)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    String fileName = System.getProperty("derby.system.home") + 
+                            "serverConsoleOutput.log";
+                    FileOutputStream fos = null;
+                    try {
+                        fos = (new FileOutputStream(fileName));
+                    } catch (FileNotFoundException ex) {
+                        ex.printStackTrace();
+                    }
+                    return fos;
+                }
+            });
+
             networkServerController = new NetworkServerControl
                 (InetAddress.getByName(config.getHostName()), config.getPort());
             
-            networkServerController.start(null);
+            networkServerController.start(new PrintWriter(serverOutput));
             
             final long startTime = System.currentTimeMillis();
             while (true) {
@@ -81,6 +104,7 @@
     protected void tearDown() throws Exception {
         if (networkServerController != null) {
             networkServerController.shutdown();
+            serverOutput.close();
         }
     }