db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r472722 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbc4/ConnectionTest.java functionTests/tests/jdbc4/PreparedStatementTest.java junit/TestConfiguration.java junit/XADataSourceConnector.java
Date Thu, 09 Nov 2006 00:56:20 GMT
Author: djd
Date: Wed Nov  8 16:56:20 2006
New Revision: 472722

URL: http://svn.apache.org/viewvc?view=rev&rev=472722
Log:
DERBY-2047 DERBY-1952 (partial) Implement the ability to run with the default connction coming
from
an XADataSource as a decorator via the utility method TestConfiguration.connectionXADecorator.
This will replace the functionality driven by the property derbyTesting.xa.single.
Improved jdbc4.ConnectionTest and PreparedStatementTest to also run their test fixtures with
this XA decorator. This will replace the old harness suite jdbcxa40 which does not seem to
be part
of derbyall but the new runs are part of jdbc4._Suite.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.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/jdbc4/ConnectionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java?view=diff&rev=472722&r1=472721&r2=472722
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
Wed Nov  8 16:56:20 2006
@@ -300,11 +300,28 @@
         embedded.addTestSuite(ConnectionTest.class);
         embedded.addTest(embeddedSuite("ConnectionTest:embedded-only"));
         connSuite.addTest(embedded);
+        
+        // repeat the embedded tests obtaining a connection from
+        // an XA data source.
+        embedded = new TestSuite("ConnectionTest:embedded XADataSource");
+        embedded.addTestSuite(ConnectionTest.class);
+        embedded.addTest(embeddedSuite("ConnectionTest:embedded-only XADataSource"));
+        connSuite.addTest(TestConfiguration.connectionXADecorator(embedded));
+        
 
         TestSuite client = new TestSuite("ConnectionTest:client");
         client.addTestSuite(ConnectionTest.class);
         client.addTest(clientSuite("ConnectionTest:client-only"));
         connSuite.addTest(TestConfiguration.clientServerDecorator(client));
+
+        // repeat the client tests obtaining a connection from
+        // an XA data source.
+        client = new TestSuite("ConnectionTest:client XADataSource");
+        client.addTestSuite(ConnectionTest.class);
+        client.addTest(clientSuite("ConnectionTest:client-only XADataSource"));
+        connSuite.addTest(
+                TestConfiguration.clientServerDecorator(
+                        TestConfiguration.connectionXADecorator(client)));
 
         return connSuite;
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?view=diff&rev=472722&r1=472721&r2=472722
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
Wed Nov  8 16:56:20 2006
@@ -25,6 +25,7 @@
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -152,55 +153,35 @@
     public static Test suite() {
         TestSuite suite = new TestSuite("PreparedStatementTest suite");
         suite.addTest(baseSuite("PreparedStatementTest:embedded"));
+        suite.addTest(
+                TestConfiguration.connectionXADecorator(
+                        baseSuite("PreparedStatementTest:embedded XADataSource")));
+        
         suite.addTest(TestConfiguration.clientServerDecorator(
             baseSuite("PreparedStatementTest:client")));
+
+        suite.addTest(
+                TestConfiguration.clientServerDecorator(
+                TestConfiguration.connectionXADecorator(
+                baseSuite("PreparedStatementTest:client XXXXADataSource"))));
+
         return suite;
     }
 
     private static Test baseSuite(String name) {
         TestSuite suite = new TestSuite(name);
         suite.addTestSuite(PreparedStatementTest.class);
-        return new BaseJDBCTestSetup(suite) {
-                public void setUp()
-                        throws java.lang.Exception {
-                        try {
-                            create();
-                        } catch (SQLException sqle) {
-                            if (sqle.getSQLState().equals("X0Y32")) {
-                                drop();
-                                create();
-                            } else {
-                                throw sqle;
-                            }
-                        }
-                }
-
-                public void tearDown()
-                        throws java.lang.Exception {
-                    drop();
-                    super.tearDown();
-                }
-
-                private void create()
-                        throws SQLException {
-                    Statement stmt = getConnection().createStatement();
+        return new CleanDatabaseTestSetup(suite) {
+
+            protected void decorateSQL(Statement stmt) throws SQLException
+            {
                     stmt.execute("create table " + BLOBTBL +
                             " (sno int, dBlob BLOB(1M))");
                     stmt.execute("create table " + CLOBTBL +
                             " (sno int, dClob CLOB(1M))");
                     stmt.execute("create table " + LONGVARCHAR  +
                             " (sno int, dLongVarchar LONG VARCHAR)");
-                    stmt.close();
-                }
-
-                private void drop()
-                        throws SQLException {
-                    Statement stmt = getConnection().createStatement();
-                    stmt.execute("drop table " + BLOBTBL);
-                    stmt.execute("drop table " + CLOBTBL);
-                    stmt.execute("drop table " + LONGVARCHAR);
-                    stmt.close();
-                }
+                 }
             };
     }
     

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=472722&r1=472721&r2=472722
==============================================================================
--- 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
Wed Nov  8 16:56:20 2006
@@ -333,6 +333,37 @@
     }
     
     /**
+     * Return a decorator that changes the configuration to obtain
+     * connections from an XADataSource using
+     * <code>
+     * getXAConnection().getConnection()
+     * </code>
+     * The connection is not connected to any global transaction,
+     * thus it is in local connection mode.
+     * The tearDown reverts the configuration to the previous
+     * configuration.
+     */
+    public static Test connectionXADecorator(Test test)
+    {
+        // Copy the current configuration by creating one
+        // with the same database name
+        TestConfiguration config = TestConfiguration.getCurrent();
+        TestConfiguration newConfig = 
+            new TestConfiguration(config, config.getDatabaseName());
+        
+        try {
+            newConfig.connector = (Connector) Class.forName(
+              "org.apache.derbyTesting.junit.XADataSourceConnector").newInstance();
+        } catch (Exception e) {
+            Assert.fail(e.getMessage());
+        }
+        
+        newConfig.connector.setConfiguration(newConfig);
+       
+        return new ChangeConfigurationSetup(newConfig, test);
+    }
+    
+    /**
      * Default embedded configuration
      *
      */
@@ -414,7 +445,7 @@
         this.url = createJDBCUrlWithDatabaseName(dbName);
         initConnector();
     }
-    
+  
     /**
      * This constructor creates a TestConfiguration from a Properties object.
      *

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java?view=auto&rev=472722
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
Wed Nov  8 16:56:20 2006
@@ -0,0 +1,108 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.junit.XADataSourceConnector
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, 
+ * software distributed under the License is distributed on an 
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
+ * either express or implied. See the License for the specific 
+ * language governing permissions and limitations under the License.
+ */
+package org.apache.derbyTesting.junit;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+
+import javax.sql.XADataSource;
+
+import junit.framework.Assert;
+
+/**
+ * Connection factory using javax.sql.XADataSource.
+ * Returns a connection in local mode obtained from
+ * getXAConnection().getConnection().
+ *
+ */
+public class XADataSourceConnector implements Connector {
+    
+    private TestConfiguration config;
+    /**
+     * DataSource that maps to the database for the
+     * configuration. The no-arg getXAConnection() method
+     * maps to the default user and password for the
+     * configuration.
+     */
+    private XADataSource ds;
+
+    public void setConfiguration(TestConfiguration config) {
+        
+        this.config = config;
+        ds = J2EEDataSource.getXADataSource(config, (HashMap) null);
+    }
+
+    public Connection openConnection() throws SQLException {
+        try {
+            return ds.getXAConnection().getConnection();
+        } catch (SQLException e) {
+            // Expected state for database not found.
+            // For the client the generic 08004 is returned,
+            // will just retry on that.
+            String expectedState = 
+                config.getJDBCClient().isEmbedded() ? "XJ004" : "08004";
+
+            // If there is a database not found exception
+            // then retry the connection request with
+            // a new DataSource with the createDtabase property set.
+            if (!expectedState.equals(e.getSQLState()))
+                throw e;
+            return singleUseDS("createDatabase", "create").
+                   getXAConnection().getConnection(); 
+       }
+    }
+
+    public Connection openConnection(String user, String password)
+            throws SQLException {
+        try {
+            return ds.getXAConnection(user, password).getConnection();
+        } catch (SQLException e) {
+            // If there is a database not found exception
+            // then retry the connection request with
+            // a new DataSource with the createDatabase property set.
+            if (!"XJ004".equals(e.getSQLState()))
+                throw e;
+            return singleUseDS("createDatabase", "create").
+                         getXAConnection(user, password).getConnection(); 
+       }
+    }
+
+    public void shutDatabase() throws SQLException {
+        singleUseDS("shutdownDatabase", "shutdown").getXAConnection().getConnection();  
  
+    }
+
+    public void shutEngine() throws SQLException {
+        Assert.fail("shutdown engine not implemened");
+    }
+    
+    /**
+     * Get a connection from a single use XADataSource configured
+     * from the configuration but with the passed in property set.
+     */
+    private XADataSource singleUseDS(String property, String value)
+       throws SQLException {
+        HashMap hm = JDBCDataSource.getDataSourceProperties(config);
+        hm.put(property, value);
+        XADataSource sds = J2EEDataSource.getXADataSource(config, hm);
+        return sds;
+    }
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message