db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r380099 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet: dataSourcePermissions_net.java testSecMec.java
Date Thu, 23 Feb 2006 11:49:32 GMT
Author: tmnk
Date: Thu Feb 23 03:49:23 2006
New Revision: 380099

URL: http://svn.apache.org/viewcvs?rev=380099&view=rev
Log:
- DERBY-273_2 The derbynet/dataSourcePermissions_net.java test fails intermittently - Patch
by Tomohito Nakayama (tomonaka@basil.ocn.ne.jp)

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java?rev=380099&r1=380098&r2=380099&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java
Thu Feb 23 03:49:23 2006
@@ -62,7 +62,15 @@
 	private static int NETWORKSERVER_PORT;
 	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_;
+    
 	public static void main(String[] args) throws Exception {
 
 		hostName = TestUtil.getHostName();
@@ -85,7 +93,25 @@
 		} 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 );
 
 		if (hostName.equals("localhost"))
 		{
@@ -97,15 +123,27 @@
 			if (!isServerStarted(networkServer, 60))
 				System.exit(-1);
 		}
-
+		
+		
 		// Now, go ahead and run the test.
 		try {
-			dataSourcePermissions_net tester = new dataSourcePermissions_net();
+		    dataSourcePermissions_net tester = 
+			new dataSourcePermissions_net( consoleLogStream ,
+						       originalStream ,
+						       shutdownLogStream ,
+						       consoleErrLogStream ,
+						       originalErrStream,
+						       shutdownErrLogStream);
 			tester.setProperties();
 			tester.runTest();
 			if (TestUtil.isDerbyNetClientFramework())
 				tester.testClientDataSourceProperties();
-			new dataSourcePermissions_net().cleanUp();
+			new dataSourcePermissions_net( consoleLogStream , 
+						       originalStream ,
+						       shutdownLogStream ,
+						       consoleErrLogStream ,
+						       originalErrStream ,
+						       shutdownErrLogStream ).cleanUp();
 
 		} catch (Exception e) {
 		// if we catch an exception of some sort, we need to make sure to
@@ -120,21 +158,48 @@
 		// 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();
 			Thread.sleep(5000);
 		}
 		System.out.println("Completed dataSourcePermissions_net");
+		
+		originalStream.close();
+		shutdownLogStream.close();
 
-		System.out.close();
-		System.err.close();
+		originalErrStream.close();
+		shutdownErrLogStream.close();
 
 	}
 
 
-	public dataSourcePermissions_net() {
+	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 void setProperties() {
 		// Set required server properties.
@@ -241,16 +306,34 @@
 	}
 
 	public void shutdown() {
+	    
+	    try{
 		try {
-			DriverManager.getConnection(TestUtil.getJdbcUrlPrefix(hostName,
+
+		    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 ... ");
+	    }
+		
 	}
 
 	protected static boolean isServerStarted(NetworkServerControl server, int ntries)
@@ -525,6 +608,21 @@
 }
 
 
+class SwitchablePrintStream extends PrintStream {
+    
+    public SwitchablePrintStream( OutputStream firstStream ){
+	super( firstStream );
+    }
+    
+    
+    public void switchOutput( OutputStream newStream ) throws IOException{
+	
+	out.flush();
+	out = newStream ;
+	
+    }
+    
+}
 
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java?rev=380099&r1=380098&r2=380099&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java
Thu Feb 23 03:49:23 2006
@@ -56,12 +56,28 @@
 	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);
+	
+    }
 
 	public static void main(String[] args) throws Exception {
 
 		// Load harness properties.
 		ij.getPropertyArg(args);
-
+		
 		String hostName = TestUtil.getHostName();
 		if (hostName.equals("localhost"))
 			NETWORKSERVER_PORT = 20000;
@@ -77,6 +93,25 @@
 		} catch (Exception e) {
 			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 );
 
 		// Start the NetworkServer on another thread, unless it's a remote host
 		if (hostName.equals("localhost"))
@@ -88,10 +123,16 @@
 			if (!isServerStarted(networkServer, 60))
 				System.exit(-1);
 		}
-
+		
 		// Now, go ahead and run the test.
 		try {
-			testSecMec tester = new testSecMec();
+			testSecMec tester = 
+			    new testSecMec(consoleLogStream,
+					   originalStream,
+					   shutdownLogStream,
+					   consoleErrLogStream,
+					   originalErrStream,
+					   shutdownErrLogStream);
 			tester.runTest();
 
 		} catch (Exception e) {
@@ -106,16 +147,26 @@
 
 		// Shutdown the server.
 		if (hostName.equals("localhost"))
-		{
+		    {
+			consoleLogStream.switchOutput( shutdownLogStream );
+			consoleErrLogStream.switchOutput( shutdownErrLogStream );
+
 			networkServer.shutdown();
 			// how do we do this with the new api?
 			//networkServer.join();
 			Thread.sleep(5000);
+
+			consoleLogStream.switchOutput( originalStream );
+			consoleErrLogStream.switchOutput( originalErrStream );
+
 		}
 		System.out.println("Completed testSecMec");
 
-		System.out.close();
-		System.err.close();
+		originalStream.close();
+		shutdownLogStream.close();
+
+		originalErrStream.close();
+		shutdownErrLogStream.close();
 
 	}
 



Mime
View raw message