db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
Subject svn commit: r628073 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/AnsiTrimTest.java functionTests/tests/lang/CreateTableFromQueryTest.java junit/CleanDatabaseTestSetup.java junit/TestConfiguration.java
Date Fri, 15 Feb 2008 14:44:36 GMT
Author: oysteing
Date: Fri Feb 15 06:44:35 2008
New Revision: 628073

URL: http://svn.apache.org/viewvc?rev=628073&view=rev
Log:
DERBY-3163: Derby JUnit test framework adaptions to run existing tests against replicated
databases
Contributed by Ole Solberg.

- TestConfiguration:
Add decorators which takes server host and port, for running tests in a
server/client configuration, where a server has already
been started on a that host and port.

- CleanDatabaseTestSetup:
Added a constructor which takes server host and port, for an already started server in a
client/server configuration, to run the SQL decoration on that server.

- AnsiTrimTest, CreateTableFromQueryTest:
Factored out the SQL statement execution for database content setup to
be able to reuse the same code in other TestCases which add the same
test method in their 'suite()' method. 

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiTrimTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CreateTableFromQueryTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiTrimTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiTrimTest.java?rev=628073&r1=628072&r2=628073&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiTrimTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiTrimTest.java
Fri Feb 15 06:44:35 2008
@@ -46,16 +46,28 @@
         super(name);
     }
 
-    public static Test suite() {
+    /*
+     * Factored out for reuse in other TestCases which add
+     * the same test method in their suite() method.
+     *
+     * Currently done for a few testcases reused in replication testing:
+     * o.a.dT.ft.tests.replicationTests.StandardTests.
+     */
+    public static void decorate(Statement s)
+    throws SQLException
+    {
+        s.executeUpdate("create table tt (id int, v varchar(16), c char(16), cl clob(10240))");
+        s.executeUpdate("insert into tt values (1, 'abcaca', 'abcaca', 'abcaca')");
+        s.executeUpdate("create table nt (v varchar(2))");
+        s.executeUpdate("insert into nt values (null)");
+    }
+   public static Test suite() {
         TestSuite suite = new TestSuite("AnsiTrimTest");
         suite.addTestSuite(AnsiTrimTest.class);
         return new CleanDatabaseTestSetup(suite) {
             public void decorateSQL(Statement s)
                     throws SQLException {
-                s.executeUpdate("create table tt (id int, v varchar(16), c char(16), cl clob(10240))");
-                s.executeUpdate("insert into tt values (1, 'abcaca', 'abcaca', 'abcaca')");
-                s.executeUpdate("create table nt (v varchar(2))");
-                s.executeUpdate("insert into nt values (null)");
+                decorate(s);
             }
 
         };

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CreateTableFromQueryTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CreateTableFromQueryTest.java?rev=628073&r1=628072&r2=628073&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CreateTableFromQueryTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CreateTableFromQueryTest.java
Fri Feb 15 06:44:35 2008
@@ -50,6 +50,24 @@
         super(name);
     }
 
+    /*
+     * Factored out for reuse in other TestCases which add
+     * the same test method in their suite() method.
+     *
+     * Currently done for a few testcases reused in replication testing:
+     * o.a.dT.ft.tests.replicationTests.StandardTests.
+     */
+    public static void decorate(Statement stmt)
+         throws SQLException
+    {
+        // create base tables t1 and t2
+        stmt.executeUpdate(
+                "create table t1(i int not null, s smallint, f float, dp "
+                + "double precision, v varchar(10) not null)");
+        
+        stmt.executeUpdate("create table t2 (a int, s varchar(5))");
+    }
+    
     /**
      * Create a suite of tests.
     */
@@ -60,13 +78,7 @@
 
             protected void decorateSQL(Statement stmt) throws SQLException
             {
-                // create base tables t1 and t2       
-                stmt.executeUpdate(
-                    "create table t1(i int not null, s smallint, f float, dp "
-                    + "double precision, v varchar(10) not null)");
-
-                stmt.executeUpdate("create table t2 (a int, s varchar(5))");
-
+                decorate(stmt);
             }
         };
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?rev=628073&r1=628072&r2=628073&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
Fri Feb 15 06:44:35 2008
@@ -58,6 +58,33 @@
     public CleanDatabaseTestSetup(Test test) {
         super(test);
     }
+    /**
+     * Constructor to use when running in a client / server 
+     * with the server already started on a given host
+     * and port.
+     */
+    /*
+     * Currently only used in o.a.dT.ft.tests.replicationTests.StandardTests
+     * for running existing JUnit tests on a client server configuration.
+     * To avoid duplicating the code inside decorateSQL() methods
+     * public static decorate() methods have been factored out
+     * for reuse in test methods in StandardTests: e.g. as AnsiTrimTest.decorate(s);
+     */
+    public CleanDatabaseTestSetup(Test test, 
+            boolean useNetworkClient,
+            String hostName,
+            int portNo) {
+        super(test);
+        if ( useNetworkClient )
+        {
+            this.jdbcClient = JDBCClient.DERBYNETCLIENT;
+        }
+        this.hostName = hostName;
+        this.portNo = portNo;
+    }
+    private JDBCClient jdbcClient = null;
+    private String hostName = null;
+    private int portNo = -1;
 
     /**
      * Clean the default database using the default connection
@@ -65,6 +92,15 @@
      * initialize their schema requirments.
      */
     protected void setUp() throws Exception {
+        if (jdbcClient != null )
+        { // We have network client (useNetworkClient) on a given host and port.
+            TestConfiguration current = TestConfiguration.getCurrent();
+            TestConfiguration modified = new TestConfiguration(current, 
+                    jdbcClient,
+                    hostName, 
+                    portNo);
+            TestConfiguration.setCurrent(modified);
+        }
         Connection conn = getConnection();
         conn.setAutoCommit(false);
         

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=628073&r1=628072&r2=628073&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
Fri Feb 15 06:44:35 2008
@@ -245,12 +245,36 @@
     /**
      * Equivalent to "defaultSuite" as defined above, but assumes a server
      * has already been started. 
-     * Does NOT decorate for running in embedded mode.
+     * <BR>
+     * Does NOT decorate for running in embedded mode, only for running on
+     * the already started server.
+     * <BR>
+     * Return a Test suite that contains all the test fixtures
+     * for the passed in class running in client server configuration
+     * on an already started server.
+     * <BR>
+     * The set of client server tests
+     * is decorated with a CleanDatabaseTestSetup.
+     * <BR>
+     * The client server configuration is setup using clientExistingServerSuite
      */
     public static Test defaultExistingServerSuite(Class testClass)
     {
         return defaultExistingServerSuite(testClass, true);
     }
+    
+    /**
+     * Does the work of "defaultExistingServerSuite" as defined above.  Takes
+     * a boolean argument to determine whether or not to "clean"
+     * the test database before each suite.  If the resultant
+     * suite is going to be wrapped inside a TestSetup that creates
+     * database objects to be used throughout the tests, then the
+     * cleanDB parameter should be "false" to prevent cleanup of the
+     * database objects that TestSetup created.
+     * <BR>
+     * Does NOT decorate for running in embedded mode, only for running on
+     * an already started server.
+     */
     public static Test defaultExistingServerSuite(Class testClass, boolean cleanDB)
     {
          final TestSuite suite = new TestSuite(suiteName(testClass));
@@ -269,6 +293,49 @@
 
     /**
      * Return a Test suite that contains all the test fixtures
+     * for the passed in class running in client server configuration
+     * on an already started server on a given host and port number.
+     * <BR>
+     * Takes a boolean argument to determine whether or not to "clean"
+     * the test database before each suite.  If the resultant
+     * suite is going to be wrapped inside a TestSetup that creates
+     * database objects to be used throughout the tests, then the
+     * cleanDB parameter should be "false" to prevent cleanup of the
+     * database objects that TestSetup created.
+     * <BR>
+     * Takes a String argument to specify which host the server runs on, and
+     * takes an int argument to specify the port number to use.
+     * <BR>
+     * Does NOT decorate for running in embedded mode, only for running on
+     * an already started server.
+     * <BR>
+     * The set of client server tests
+     * is decorated with a CleanDatabaseTestSetup.
+     * <BR>
+     * The client server configuration is setup using clientExistingServerSuite
+     */
+    public static Test existingServerSuite(Class testClass, 
+            boolean cleanDB,
+            String hostName,
+            int portNumber)
+    {
+         final TestSuite suite = new TestSuite(suiteName(testClass));
+         
+        if (cleanDB)
+        {
+            suite.addTest(new CleanDatabaseTestSetup(
+                    clientExistingServerSuite(testClass, hostName, portNumber)));
+        }
+        else
+        {
+            suite.addTest(clientExistingServerSuite(testClass, hostName, portNumber));
+        }
+
+        return (suite);
+    }
+
+    /**
+     * Return a Test suite that contains all the test fixtures
      * for the passed in class running in embedded and client-
      * server *JDBC3* configurations.
      * <BR>
@@ -351,6 +418,23 @@
                 suiteName(testClass)+":client");
         return defaultExistingServerDecorator(suite); // Will not start server and does not
stop it when done!.
     }
+    
+    /**
+     * Create a suite for the passed test class that includes
+     * all the default fixtures from the class, wrapped in
+     * a existingServerDecorator.
+     * <BR>
+     * Equivalent to 'clientServerSuite' above, but assumes server is
+     * already running. Will also NOT shut down the server.
+     *
+     */
+    public static Test clientExistingServerSuite(Class testClass, String hostName, int portNumber)
+    {
+        TestSuite suite = new TestSuite(testClass,
+                suiteName(testClass)+":client");
+        return existingServerDecorator(suite, hostName, portNumber); 
+               // Will not start server and does not stop it when done!.
+    }
 
     /**
      * Return a decorator for the passed in tests that sets the
@@ -419,6 +503,19 @@
         //
         return new ServerSetup(test, DEFAULT_HOSTNAME, DEFAULT_PORT);
     }
+   /**
+    * A variant of defaultServerDecorator allowing 
+    * non-default hostname and portnumber.
+    */
+    public static Test existingServerDecorator(Test test, 
+            String hostName, int PortNumber)
+    {
+        Test r =
+                new ServerSetup(test, hostName, PortNumber);
+        ((ServerSetup)r).setJDBCClient(JDBCClient.DERBYNETCLIENT);
+        return r;
+    }
+   
     /**
      * Decorate a test to use suite's default host and Alternative port.
      */



Mime
View raw message