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 km...@apache.org on 2009/06/03 00:46:58 UTC

svn commit: r781200 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/ testing/org/apache/derbyTesting/functionTests/util/ testing/org/apache/derbyTesting/...

Author: kmarsden
Date: Tue Jun  2 22:46:58 2009
New Revision: 781200

URL: http://svn.apache.org/viewvc?rev=781200&view=rev
Log:
DERBY-4223 Provide the ability to use properties with ij.runScript()
adds a new runScript method that allows use of system properties with runScript.
DERBY-4217 (partial) adds use derby.tests.port system property when initializing TestConfiguration.

Contributed by Tiago Espinha (tiago at espinhas dot net)


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testclientij.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetIjTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testclientij.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
    db/derby/code/trunk/java/tools/org/apache/derby/tools/ij.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testclientij.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testclientij.out?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testclientij.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testclientij.out Tue Jun  2 22:46:58 2009
@@ -16,8 +16,8 @@
 --
 driver 'org.apache.derby.jdbc.ClientDriver';
 ij> --Bug 4632  Make the db italian to make sure string selects  are working
-connect 'jdbc:derby://localhost:1527/testij;create=true;territory=it' USER 'dbadmin' PASSWORD 'dbadmin';
-ij(CONNECTION1)> connect 'jdbc:derby://localhost:1527/testij' USER 'dbadmin' PASSWORD 'dbadbmin';
+connect 'testij;create=true;territory=it' USER 'dbadmin' PASSWORD 'dbadmin';
+ij(CONNECTION1)> connect 'testij' USER 'dbadmin' PASSWORD 'dbadbmin';
 ij(CONNECTION2)> -- this is a comment, a comment in front of a select should not cause an error
 select * from sys.systables where 1=0;
 TABLEID                             |TABLENAME                                                                                                                       |&|SCHEMAID                            |&
@@ -29,39 +29,39 @@
 1          
 ij(CONNECTION2)> -- Try some URL attributes
 disconnect all;
-ij> connect 'jdbc:derby://localhost:1527/testij2;create=true' USER 'dbadmin' PASSWORD 'dbadbmin';
+ij> connect 'testij2;create=true' USER 'dbadmin' PASSWORD 'dbadbmin';
 ij> select * from APP.notthere;
 ERROR 42X05: Table/View 'APP.NOTTHERE' does not exist.
 ij> -- examples from the docs
 
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=judy;password=judy';
-ij(CONNECTION1)> connect 'jdbc:derby://localhost:1527/./testij2;user=judy;password=judy';
-ij(CONNECTION2)> connect 'jdbc:derby://localhost:1527/toursDB';
+connect 'testij2;create=true;user=judy;password=judy';
+ij(CONNECTION1)> connect './testij2;user=judy;password=judy';
+ij(CONNECTION2)> connect 'toursDB';
 ERROR 08004: The connection was refused because the database toursDB was not found.
-ij(CONNECTION2)> connect 'jdbc:derby://localhost:1527/toursDB' USER 'dbadmin' PASSWORD 'dbadbmin';
+ij(CONNECTION2)> connect 'toursDB' USER 'dbadmin' PASSWORD 'dbadbmin';
 ERROR 08004: The connection was refused because the database toursDB was not found.
-ij(CONNECTION2)> connect 'jdbc:derby://localhost:1527/wombat' USER 'APP' PASSWORD 'APP';
-ij(CONNECTION3)> connect  'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd';
-ij(CONNECTION4)> connect 'jdbc:derby://localhost:1527/testij2;upgrade=true;user=usr;password=pwd';
-ij(CONNECTION5)> connect 'jdbc:derby://localhost:1527/testij2;shutdown=true;user=usr;password=pwd';
+ij(CONNECTION2)> connect 'wombat' USER 'APP' PASSWORD 'APP';
+ij(CONNECTION3)> connect  'testij2;create=true;user=usr;password=pwd';
+ij(CONNECTION4)> connect 'testij2;upgrade=true;user=usr;password=pwd';
+ij(CONNECTION5)> connect 'testij2;shutdown=true;user=usr;password=pwd';
 ERROR 08006: DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'testij2' shutdown.
-ij(CONNECTION5)> connect 'jdbc:derby://localhost:1527/./testij2;create=true;user=usr;password=pwd';
-ij(CONNECTION6)> connect 'jdbc:derby://localhost:1527/./testij2;create=true;user=usr;password=pwd';
-ij(CONNECTION7)> connect  'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd';
-ij(CONNECTION8)> connect 'jdbc:derby://localhost:1527/testij2;upgrade=true;user=usr;password=pwd';
-ij(CONNECTION9)> connect 'jdbc:derby://localhost:1527/testij2;shutdown=true;user=usr;password=pwd';
+ij(CONNECTION5)> connect './testij2;create=true;user=usr;password=pwd';
+ij(CONNECTION6)> connect './testij2;create=true;user=usr;password=pwd';
+ij(CONNECTION7)> connect  'testij2;create=true;user=usr;password=pwd';
+ij(CONNECTION8)> connect 'testij2;upgrade=true;user=usr;password=pwd';
+ij(CONNECTION9)> connect 'testij2;shutdown=true;user=usr;password=pwd';
 ERROR 08006: DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'testij2' shutdown.
 ij(CONNECTION9)> -- retrieveMessageText Testing
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd;retrieveMessageText=false';
+connect 'testij2;create=true;user=usr;password=pwd;retrieveMessageText=false';
 ij(CONNECTION10)> -- Should not get message text
 select * from APP.notthere;
 ERROR 42X05: DERBY SQL error: SQLCODE: -1, SQLSTATE: 42X05, SQLERRMC: APP.NOTTHERE42X05
-ij(CONNECTION10)> connect 'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd;retrieveMessageText=true';
+ij(CONNECTION10)> connect 'testij2;create=true;user=usr;password=pwd;retrieveMessageText=true';
 ij(CONNECTION11)> -- Should see message text
 select * from APP.notthere;
 ERROR 42X05: Table/View 'APP.NOTTHERE' does not exist.
 ij(CONNECTION11)> -- just user security mechanism
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=usr;retrieveMessageText=true';
-ij(CONNECTION12)> connect 'jdbc:derby://localhost:1527/wombat' USER 'APP';
+connect 'testij2;create=true;user=usr;retrieveMessageText=true';
+ij(CONNECTION12)> connect 'wombat' USER 'APP';
 ij(CONNECTION13)> disconnect all;
-ij> 
\ No newline at end of file
+ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetIjTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetIjTest.java?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetIjTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetIjTest.java Tue Jun  2 22:46:58 2009
@@ -20,11 +20,13 @@
 
 package org.apache.derbyTesting.functionTests.tests.derbynet;
 
+import java.util.Properties;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.functionTests.util.ScriptTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -68,14 +70,22 @@
      * Return the suite that runs all the derbynet scripts.
      */
     public static Test suite() {
-
         TestSuite suite = new TestSuite("NetScripts");
 
         // Set up the scripts run with the network client
         TestSuite clientTests = new TestSuite("NetScripts:client");
         clientTests.addTest(getSuite(CLIENT_TESTS));
-        Test client = TestConfiguration.clientServerDecorator(clientTests);
 
+        int port = TestConfiguration.getCurrent().getPort();
+
+        Properties prop = new Properties();
+        prop.setProperty("ij.protocol",
+                "jdbc:derby://localhost:"+port+"/");
+
+        Test client = new SystemPropertyTestSetup(
+                TestConfiguration.clientServerDecoratorWithPort(clientTests,port),
+                prop);
+                    
         // add those client tests into the top-level suite.
         suite.addTest(client);
 
@@ -86,7 +96,7 @@
      * A single JUnit test that runs a single derbynet script.
      */
     private NetIjTest(String netTest){
-        super(netTest);
+        super(netTest,true);
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testclientij.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testclientij.sql?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testclientij.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testclientij.sql Tue Jun  2 22:46:58 2009
@@ -16,9 +16,9 @@
 --
 driver 'org.apache.derby.jdbc.ClientDriver';
 --Bug 4632  Make the db italian to make sure string selects  are working
-connect 'jdbc:derby://localhost:1527/testij;create=true;territory=it' USER 'dbadmin' PASSWORD 'dbadmin';
+connect 'testij;create=true;territory=it' USER 'dbadmin' PASSWORD 'dbadmin';
 
-connect 'jdbc:derby://localhost:1527/testij' USER 'dbadmin' PASSWORD 'dbadbmin';
+connect 'testij' USER 'dbadmin' PASSWORD 'dbadbmin';
 -- this is a comment, a comment in front of a select should not cause an error
 select * from sys.systables where 1=0;
 -- this is a comment, a comment in front of a values clauses should not cause an error
@@ -26,52 +26,52 @@
 
 -- Try some URL attributes
 disconnect all;
-connect 'jdbc:derby://localhost:1527/testij2;create=true' USER 'dbadmin' PASSWORD 'dbadbmin';
+connect 'testij2;create=true' USER 'dbadmin' PASSWORD 'dbadbmin';
 select * from APP.notthere;
 
 
 -- examples from the docs
 
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=judy;password=judy';
+connect 'testij2;create=true;user=judy;password=judy';
 
-connect 'jdbc:derby://localhost:1527/./testij2;user=judy;password=judy';
+connect './testij2;user=judy;password=judy';
 
-connect 'jdbc:derby://localhost:1527/toursDB';
+connect 'toursDB';
 
-connect 'jdbc:derby://localhost:1527/toursDB' USER 'dbadmin' PASSWORD 'dbadbmin';
+connect 'toursDB' USER 'dbadmin' PASSWORD 'dbadbmin';
 
-connect 'jdbc:derby://localhost:1527/wombat' USER 'APP' PASSWORD 'APP';
+connect 'wombat' USER 'APP' PASSWORD 'APP';
 
-connect  'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd';
+connect  'testij2;create=true;user=usr;password=pwd';
 
-connect 'jdbc:derby://localhost:1527/testij2;upgrade=true;user=usr;password=pwd';
+connect 'testij2;upgrade=true;user=usr;password=pwd';
 
-connect 'jdbc:derby://localhost:1527/testij2;shutdown=true;user=usr;password=pwd';
+connect 'testij2;shutdown=true;user=usr;password=pwd';
 
-connect 'jdbc:derby://localhost:1527/./testij2;create=true;user=usr;password=pwd';
+connect './testij2;create=true;user=usr;password=pwd';
 
-connect 'jdbc:derby://localhost:1527/./testij2;create=true;user=usr;password=pwd';
+connect './testij2;create=true;user=usr;password=pwd';
 
-connect  'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd';
+connect  'testij2;create=true;user=usr;password=pwd';
 
-connect 'jdbc:derby://localhost:1527/testij2;upgrade=true;user=usr;password=pwd';
+connect 'testij2;upgrade=true;user=usr;password=pwd';
 
-connect 'jdbc:derby://localhost:1527/testij2;shutdown=true;user=usr;password=pwd';
+connect 'testij2;shutdown=true;user=usr;password=pwd';
 
 -- retrieveMessageText Testing
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd;retrieveMessageText=false';
+connect 'testij2;create=true;user=usr;password=pwd;retrieveMessageText=false';
 
 -- Should not get message text
 select * from APP.notthere;
 
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=usr;password=pwd;retrieveMessageText=true';
+connect 'testij2;create=true;user=usr;password=pwd;retrieveMessageText=true';
 
 -- Should see message text
 select * from APP.notthere;
 
 -- just user security mechanism
-connect 'jdbc:derby://localhost:1527/testij2;create=true;user=usr;retrieveMessageText=true';
+connect 'testij2;create=true;user=usr;retrieveMessageText=true';
 
-connect 'jdbc:derby://localhost:1527/wombat' USER 'APP';
+connect 'wombat' USER 'APP';
 
 disconnect all;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java Tue Jun  2 22:46:58 2009
@@ -37,6 +37,20 @@
 
 	private final String inputEncoding;
 	private final String user;
+    private boolean useSystemProperties = false;
+
+    /**
+	 * Create a ScriptTestCase to run a single test
+     * using a connection obtained from getConnection()
+	 * @param script Base name of the .sql script
+     * @param useSystemProperties Whether to use system properties for this test
+	 * excluding the .sql suffix.
+	 */
+	public ScriptTestCase(String script, boolean useSystemProperties)
+	{
+        this(script, null, null, null);
+        this.useSystemProperties = useSystemProperties;
+	}
 
 	/**
 	 * Create a ScriptTestCase to run a single test
@@ -167,13 +181,14 @@
             // encoding to use.
             outputEnc = outputEncoding;
         }
-
+        
 		org.apache.derby.tools.ij.runScript(
 				conn,
 				sqlIn,
 				inputEncoding,
                 getOutputStream(),
-				outputEnc);
+				outputEnc,
+                useSystemProperties);
 		
 		if (!conn.isClosed() && !conn.getAutoCommit())
 		    conn.commit();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Tue Jun  2 22:46:58 2009
@@ -454,6 +454,26 @@
             
         return defaultServerDecorator(test);
     }
+
+    /**
+     * Return a decorator for the passed in tests that sets the
+     * configuration for the client to be Derby's JDBC client
+     * and to start the network server at setUp.
+     * <BR>
+     * The database configuration (name etc.) is based upon
+     * the previous configuration.
+     * <BR>
+     * The previous TestConfiguration is restored at tearDown and
+     * the network server is shutdown.
+     * @param suite the suite to decorate
+     */
+    public static Test clientServerDecoratorWithPort(Test suite, int port)
+    {
+        Test test = new NetworkServerTestSetup(suite, false);
+
+        return existingServerDecorator(test,"localhost",port);
+    }
+
     /**
      * Wrapper to use the alternative port number.
      */
@@ -895,7 +915,12 @@
         this.userName = DEFAULT_USER_NAME;
         this.userPassword = DEFAULT_USER_PASSWORD;
         this.hostName = null;
-        this.port = -1;
+        String port = BaseTestCase.getSystemProperty("derby.tests.port");
+        if (port == null) {
+        	this.port = DEFAULT_PORT;
+        } else {
+        	this.port = Integer.parseInt(port);
+        }
         this.isVerbose = Boolean.valueOf(
             getSystemProperties().getProperty(KEY_VERBOSE)).
             booleanValue();

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java Tue Jun  2 22:46:58 2009
@@ -200,6 +200,18 @@
 		return new utilMain(numConnections, out);
 	}
 
+    /**
+	 * Get the right utilMain (according to
+	 * the JDBC version. This overload allows the choice of whether
+     * the system properties will be used or not.
+	 *
+	 * @return	The right utilMain (according to the JDBC version).
+	 */
+    public utilMain getutilMain(int numConnections, LocalizedOutput out, boolean loadSystemProperties)
+	{
+		return new utilMain(numConnections, out, loadSystemProperties);
+	}
+
 	/**
 		Give a shortcut to go on the utilInstance so
 		we don't expose utilMain.

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java Tue Jun  2 22:46:58 2009
@@ -100,6 +100,22 @@
 		this(numConnections, out, (Hashtable)null);
 	}
 
+    /**
+	 * Set up the test to run with 'numConnections' connections/users.
+     * This overload allows the choice of whether the system properties
+     * will be used or not.
+	 *
+	 * @param numConnections	The number of connections/users to test.
+	 */
+    utilMain(int numConnections, LocalizedOutput out, boolean loadSystemProperties)
+		throws ijFatalException
+	{
+		this(numConnections, out, (Hashtable)null);
+        if (loadSystemProperties) {
+            initFromEnvironment();
+        }
+	}
+
 	/**
 	 * Set up the test to run with 'numConnections' connections/users.
 	 *

Modified: db/derby/code/trunk/java/tools/org/apache/derby/tools/ij.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/tools/ij.java?rev=781200&r1=781199&r2=781200&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/tools/ij.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/tools/ij.java Tue Jun  2 22:46:58 2009
@@ -80,23 +80,49 @@
 		  String outputEncoding)
 		  throws UnsupportedEncodingException
   {
-	  LocalizedOutput lo = 
-		  outputEncoding == null ?
-				  LocalizedResource.getInstance().
-		            getNewOutput(sqlOut)
-	             :  
-		          LocalizedResource.getInstance().
+	  return ij.runScript(conn, sqlIn, inputEncoding, sqlOut, outputEncoding,false);
+  }
+
+    /**
+    * Run a SQL script from an InputStream and write
+    * the resulting output to the provided PrintStream.
+    * SQL commands are separated by a semi-colon ';' character.
+    *
+    * @param conn Connection to be used as the script's default connection.
+    * @param sqlIn InputStream for the script.
+    * @param inputEncoding Encoding of the script.
+    * @param sqlOut OutputStream for the script's output
+    * @param outputEncoding Output encoding to use.
+    * @param loadSystemProperties Whether to use the system properties.
+    * @return Number of SQLExceptions thrown during the execution, -1 if not known.
+    * @throws UnsupportedEncodingException
+    */
+    public static int runScript(
+		  Connection conn,
+		  InputStream sqlIn,
+		  String inputEncoding,
+		  OutputStream sqlOut,
+		  String outputEncoding,
+          boolean loadSystemProperties)
+		  throws UnsupportedEncodingException
+    {
+        LocalizedOutput lo =
+          outputEncoding == null ?
+                  LocalizedResource.getInstance().
+                    getNewOutput(sqlOut)
+                 :
+                  LocalizedResource.getInstance().
                     getNewEncodedOutput(sqlOut, outputEncoding);
 
-	  Main ijE = new Main(false);
-	  
-	  LocalizedInput li = LocalizedResource.getInstance().
-	            getNewEncodedInput(sqlIn, inputEncoding);
-	  
-	  utilMain um = ijE.getutilMain(1, lo);
+        Main ijE = new Main(false);
 
-	  return um.goScript(conn, li);
-  }
+        LocalizedInput li = LocalizedResource.getInstance().
+                getNewEncodedInput(sqlIn, inputEncoding);
+
+        utilMain um = ijE.getutilMain(1, lo, loadSystemProperties);
+
+        return um.goScript(conn, li);
+    }
 
   private ij() { // no instances allowed
   }