db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r464785 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/ functionTests/tests/lang/ junit/
Date Tue, 17 Oct 2006 03:48:50 GMT
Author: djd
Date: Mon Oct 16 20:48:49 2006
New Revision: 464785

URL: http://svn.apache.org/viewvc?view=rev&rev=464785
Log:
DERBY-1952 (partial) Add some utility methods in TestConfiguration to allow test classes to
easily implement
suite() methods that run in embedded and/or client server.
Convert some tests to use these utility methods. Change NetworkServerTestSetup to create a
server console
output file in the logs folder in append mode.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobLengthTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobStreamsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TimeHandlingTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.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/jdbcapi/LobLengthTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobLengthTest.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobLengthTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobLengthTest.java
Mon Oct 16 20:48:49 2006
@@ -31,6 +31,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
  * This tests a fix for a defect (DERBY-121) where the server and
@@ -42,10 +43,6 @@
 
 public class LobLengthTest extends BaseJDBCTestCase {
 
-
-    /* Connection to be used in test */
-    private Connection conn = null; 
-
     /**
      * Creates a new instance of LobLengthTest
      *
@@ -59,11 +56,7 @@
     
     public static Test suite() 
     {
-        final TestSuite suite = new TestSuite();
-        
-        suite.addTest(new LobLengthTest("testLongLobLengths"));
-
-        return suite;
+        return TestConfiguration.defaultSuite(LobLengthTest.class);
     }
 
 
@@ -73,11 +66,10 @@
      */
     public void setUp() throws Exception
     {
-        conn = getConnection();
-        conn.setAutoCommit(false);
+        getConnection().setAutoCommit(false);
 
         // Create a test table.
-        Statement st = conn.createStatement();
+        Statement st = createStatement();
         st.execute("create table lobTable100M(bl blob(100M))");
         st.close();
     }
@@ -88,12 +80,12 @@
      */
     public void tearDown() throws Exception 
     {
-        Statement st = conn.createStatement();
+        Statement st = createStatement();
         st.execute("drop table lobTable100M");
         st.close();
 
-        conn.commit();
-        conn.close();
+        commit();
+        super.tearDown();
     }
 
 
@@ -106,7 +98,7 @@
      */
     public void testLongLobLengths() throws Exception
     {
-        PreparedStatement pSt = conn.prepareStatement(
+        PreparedStatement pSt = prepareStatement(
             "insert into lobTable100M(bl) values (?)");
 
         // The error we're testing occurs when the server

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobStreamsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobStreamsTest.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobStreamsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LobStreamsTest.java
Mon Oct 16 20:48:49 2006
@@ -36,6 +36,7 @@
 
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 public class LobStreamsTest extends BaseJDBCTestCase {
 
@@ -51,9 +52,6 @@
         streamSize[1] =  10000;
     }
 
-    private Connection con = null;
-
-
     /** Creates a new instance of LobStreamsTest */
     public LobStreamsTest(String name) {
         super(name);
@@ -63,10 +61,9 @@
      * Set up the connection to the database.
      */
     public void setUp() throws Exception {
-        con = getConnection();
-        con.setAutoCommit(false);
+        getConnection().setAutoCommit(false);
 
-        Statement stmt1 = con.createStatement();
+        Statement stmt1 = createStatement();
         stmt1.execute("create table testBlobX1 (" +
                 "a integer, " +
                 "b blob(300K), " +
@@ -76,7 +73,7 @@
         byte[] b2 = new byte[1];
         b2[0] = (byte)64;
         String c2 = "c";
-        PreparedStatement stmt2 = con.prepareStatement(
+        PreparedStatement stmt2 = prepareStatement(
                 "INSERT INTO testBlobX1(a, b, c) " +
                 "VALUES (?, ?, ?)");
         stmt2.setInt(1, 1);
@@ -86,11 +83,6 @@
         stmt2.close();
     }
 
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        con = null;
-    }
-
     /**
      * Tests the BlobOutputStream.write(byte  b[], int off, int len) method
      **/
@@ -98,7 +90,7 @@
         InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
         assertTrue("FAIL -- file not found", streamIn != null);
 
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT b FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -115,7 +107,7 @@
         outstream.close();
         streamIn.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET b = ? WHERE a = 1");
         stmt4.setBlob(1,  blob);
         stmt4.executeUpdate();
@@ -147,7 +139,7 @@
     public void testBlobWrite1Param() throws Exception {
         InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);
 
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT b FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -163,7 +155,7 @@
         outstream.close();
         streamIn.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET b = ? WHERE a = 1");
         stmt4.setBlob(1,  blob);
         stmt4.executeUpdate();
@@ -196,7 +188,7 @@
     {
         InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);
 
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT c FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -211,7 +203,7 @@
         outstream.close();
         streamIn.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET c = ? WHERE a = 1");
         stmt4.setClob(1,  clob);
         stmt4.executeUpdate();
@@ -241,7 +233,7 @@
         InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
         assertTrue("FAIL -- file not found", streamIn != null);
 
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT c FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -258,7 +250,7 @@
         outstream.close();
         streamIn.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET c = ? WHERE a = 1");
         stmt4.setClob(1,  clob);
         stmt4.executeUpdate();
@@ -291,7 +283,7 @@
     {
         char[] testdata = unicodeTestString.toCharArray();
 
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT c FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -301,7 +293,7 @@
         clobWriter.write(testdata, 0, testdata.length);
         clobWriter.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET c = ? WHERE a = 1");
         stmt4.setClob(1,  clob);
         stmt4.executeUpdate();
@@ -330,7 +322,7 @@
      **/
     public void testClobCharacterWrite3ParamString() throws Exception
     {
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT c FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -340,7 +332,7 @@
         clobWriter.write(unicodeTestString, 0, unicodeTestString.length());
         clobWriter.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET c = ? WHERE a = 1");
         stmt4.setClob(1,  clob);
         stmt4.executeUpdate();
@@ -369,7 +361,7 @@
      **/
     public void testClobCharacterWrite1ParamString() throws Exception
     {
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT c FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -379,7 +371,7 @@
         clobWriter.write(unicodeTestString);
         clobWriter.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET c = ? WHERE a = 1");
         stmt4.setClob(1,  clob);
         stmt4.executeUpdate();
@@ -410,7 +402,7 @@
     {
         char testchar = 'a';
 
-        PreparedStatement stmt3 = con.prepareStatement(
+        PreparedStatement stmt3 = prepareStatement(
             "SELECT c FROM testBlobX1 WHERE a = 1");
         ResultSet rs3 = stmt3.executeQuery();
         rs3.next();
@@ -421,7 +413,7 @@
         clobWriter.write(testchar);
         clobWriter.close();
 
-        PreparedStatement stmt4 = con.prepareStatement(
+        PreparedStatement stmt4 = prepareStatement(
             "UPDATE testBlobX1 SET c = ? WHERE a = 1");
         stmt4.setClob(1,  clob);
         stmt4.executeUpdate();
@@ -444,26 +436,13 @@
         stmt3.close();
     }
 
+    /**
+     * Run with DerbyNetClient only.
+     * @return
+     */
     public static Test suite() {
-        final TestSuite suite = new TestSuite();
-
-        // Run with DerbyNetClient only
-        if (usingDerbyNetClient()) {
-            suite.addTest(new LobStreamsTest("testBlobWrite1Param"));
-            suite.addTest(new LobStreamsTest("testBlobWrite3Param"));
-            suite.addTest(new LobStreamsTest("testClobAsciiWrite1Param"));
-            suite.addTest(new LobStreamsTest("testClobAsciiWrite3Param"));
-            suite.addTest(new
-                    LobStreamsTest("testClobCharacterWrite1Char"));
-            suite.addTest(new
-                    LobStreamsTest("testClobCharacterWrite1ParamString"));
-            suite.addTest(new
-                    LobStreamsTest("testClobCharacterWrite3ParamChar"));
-            suite.addTest(new
-                    LobStreamsTest("testClobCharacterWrite3ParamString"));
-        }
-
-        return suite;
+                
+        return TestConfiguration.clientServerSuite(LobStreamsTest.class);
     }
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
Mon Oct 16 20:48:49 2006
@@ -68,9 +68,6 @@
 			suite.addTest(LobStreamsTest.suite());
 		}
         
-        if (TestConfiguration.runningInDerbyHarness())
-            return new NetworkServerTestSetup(suite);
-        
         return suite;
 	}
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
Mon Oct 16 20:48:49 2006
@@ -94,7 +94,7 @@
         TestSuite clientTests = new TestSuite();
         clientTests.addTest(getSuite(SQL_LANGUAGE_TESTS));
         clientTests.addTest(getSuite(DERBY_TESTS));
-        Test client = TestConfiguration.derbyClientServerDecorator(clientTests);
+        Test client = TestConfiguration.clientServerDecorator(clientTests);
         
         // add those client tests into the top-level suite.
         suite.addTest(client);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
Mon Oct 16 20:48:49 2006
@@ -26,6 +26,7 @@
 
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 public class MathTrigFunctionsTest extends BaseJDBCTestCase {
 
@@ -993,10 +994,13 @@
 		super(name);
 	}
 
+    /**
+     * Runs the tests in the embedded and client server configuration
+     * as the JDBC escape function testing is relevant for both drivers.
+     * @return
+     */
 	public static Test suite() {
-		TestSuite suite = new TestSuite();
-		suite.addTestSuite(MathTrigFunctionsTest.class);
-		return suite;
+        return TestConfiguration.defaultSuite(MathTrigFunctionsTest.class);
 	}
 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TimeHandlingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TimeHandlingTest.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TimeHandlingTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TimeHandlingTest.java
Mon Oct 16 20:48:49 2006
@@ -81,7 +81,7 @@
         suite.addTest(new TimeHandlingTest("derby889testInertTime"));
         suite.addTest(new TimeHandlingTest("derby889testCurrentTime"));
         
-        suite.addTest(TestConfiguration.derbyClientServerDecorator(TimeHandlingTest.class));
+        suite.addTest(TestConfiguration.clientServerSuite(TimeHandlingTest.class));
         
         return new CleanDatabaseTestSetup(suite) {
             protected void decorateSQL(Statement s) throws SQLException {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
Mon Oct 16 20:48:49 2006
@@ -21,6 +21,7 @@
 
 import java.io.FileNotFoundException;
 import java.net.InetAddress;
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.PrintWriter;
 import java.security.AccessController;
@@ -58,18 +59,18 @@
         
         TestConfiguration config = TestConfiguration.getCurrent();
         
-        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";
+                    File logs = new File("logs");
+                    logs.mkdir();
+                    File console = new File(logs, "serverConsoleOutput.log");
                     FileOutputStream fos = null;
                     try {
-                        fos = (new FileOutputStream(fileName));
+                        fos = new FileOutputStream(console.getPath(), true);
                     } catch (FileNotFoundException ex) {
                         ex.printStackTrace();
                     }
@@ -95,7 +96,6 @@
                     }
                 }
             }
-        }
     }
 
     /**

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?view=diff&rev=464785&r1=464784&r2=464785
==============================================================================
--- 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
Mon Oct 16 20:48:49 2006
@@ -155,22 +155,49 @@
     {
         CURRENT_CONFIG.set(config);
     }
+    
+    
     /**
-     * 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 and shut it
-     * down at tearDown.
+     * Return a Test suite that contains all the text fixtures
+     * for the passed in class running in embedded and the
+     * default client server configuration.
      * <BR>
-     * The database configuration (name etc.) is based upon
-     * the previous configuration.
+     * The complete set of embedded and set of client server tests
+     * is decorated with a CleanDatabaseTestSetup.
      * <BR>
-     * The previous TestConfiguration is restored at tearDown.
-     * @param tests
-     * @return
+     * The client server configuration is setup using clientServerSuite
      */
-    public static Test derbyClientServerDecorator(Class suiteClass)
+    public static Test defaultSuite(Class testClass)
+    {
+        final TestSuite suite = new TestSuite();
+        
+        suite.addTest(embeddedSuite(testClass));            
+        suite.addTest(clientServerSuite(testClass));
+ 
+        return new CleanDatabaseTestSetup(suite);
+    }
+    
+    /**
+     * Create a suite for the passed test class that includes
+     * all the default fixtures from the class, wrapped
+     * in a single CleanDatabaseTestSetup.
+      */
+    public static Test embeddedSuite(Class testClass)
+    {
+        return new TestSuite(testClass);
+    }
+    
+    /**
+     * Create a suite for the passed test class that includes
+     * all the default fixtures from the class, wrapped in
+     * a derbyClientServerDecorator.
+     * 
+     * @param withCleanDB True if the 
+      */
+    public static Test clientServerSuite(Class testClass)
     {           
-        return derbyClientServerDecorator(new TestSuite(suiteClass));
+        TestSuite suite = new TestSuite(testClass);
+        return clientServerDecorator(suite);
     }
     /**
      * Return a decorator for the passed in tests that sets the
@@ -185,7 +212,7 @@
      * @param tests
      * @return
      */
-    public static Test derbyClientServerDecorator(Test suite)
+    public static Test clientServerDecorator(Test suite)
     {
         if (JDBC.vmSupportsJSR169())
             return new TestSuite();



Mime
View raw message