db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r627356 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: testData/ testData/serialized-data-sources/ tests/jdbcapi/
Date Wed, 13 Feb 2008 11:06:49 GMT
Author: kristwaa
Date: Wed Feb 13 03:06:29 2008
New Revision: 627356

URL: http://svn.apache.org/viewvc?rev=627356&view=rev
Log:
DERBY-1318: Add an upgrade test to verify that DataSources can be serialized by the previous
release and then correctly deserialized by the current release.
Added a test that performs basic tests on serialized data sources from old Derby releases.
The data files added were generated by running testData/serialized-data-sources/SerializeDataSources.java
with Derby versions 10.0.2.1, 10.1.3.1, 10.2.2.0 and 10.3.2.1 on the classpath (one version
at a time).
Patch file: derby-1318-1b-for_comments.diff + serialized-data-sources.zip

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_1_3_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_2_2_0.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_3_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_1_3_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_2_2_0.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_3_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_1_3_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_2_2_0.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_3_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_0_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_1_3_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_2_2_0.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_3_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_0_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_1_3_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_2_2_0.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_3_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_0_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_1_3_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_2_2_0.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_3_2_1.ser
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/SerializeDataSources.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/build.xml?rev=627356&r1=627355&r2=627356&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/build.xml
Wed Feb 13 03:06:29 2008
@@ -55,6 +55,10 @@
       <fileset dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/testData/ConnectionMethods"
         includes="*.txt"/>
     </copy>
+    <copy todir="${out.dir}/${derby.testing.functest.dir}/testData/serialized-data-sources">
+      <fileset dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/testData/serialized-data-sources"
+        includes="*.ser"/>
+    </copy>
   </target>
 
 </project>

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_1_3_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_1_3_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_1_3_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_2_2_0.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_2_2_0.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_2_2_0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_3_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_3_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientConnectionPoolDataSource-10_3_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_1_3_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_1_3_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_1_3_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_2_2_0.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_2_2_0.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_2_2_0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_3_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_3_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientDataSource-10_3_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_1_3_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_1_3_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_1_3_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_2_2_0.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_2_2_0.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_2_2_0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_3_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_3_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/ClientXADataSource-10_3_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_0_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_0_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_0_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_1_3_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_1_3_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_1_3_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_2_2_0.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_2_2_0.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_2_2_0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_3_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_3_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedConnectionPoolDataSource-10_3_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_0_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_0_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_0_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_1_3_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_1_3_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_1_3_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_2_2_0.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_2_2_0.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_2_2_0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_3_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_3_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedDataSource-10_3_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_0_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_0_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_0_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_1_3_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_1_3_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_1_3_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_2_2_0.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_2_2_0.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_2_2_0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_3_2_1.ser
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_3_2_1.ser?rev=627356&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/EmbeddedXADataSource-10_3_2_1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/SerializeDataSources.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/SerializeDataSources.java?rev=627356&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/SerializeDataSources.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/SerializeDataSources.java
Wed Feb 13 03:06:29 2008
@@ -0,0 +1,240 @@
+/*
+
+   Derby - Class SerializeDataSources
+
+   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.
+
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.sql.DataSource;
+
+import org.apache.derby.tools.sysinfo;
+
+/**
+ * Serializes and writes data sources to file, or prints information about
+ * a file assumed to be written by this program.
+ * <p>
+ * Four entities are written to the stream:
+ * <ol> <li>Derby version string - UTF</li>
+ *      <li>Derby build number - UTF</li>
+ *      <li>Derby data source - object</li>
+ *      <li>Derby data source reference - object</li>
+ * </ol>
+ * <p>
+ * Both embedded and client data sources are attempted serialized, and the data
+ * source class names are obtained from a predefined list. If another data
+ * source implementation is added to Derby, its class name must be added to the
+ * list if this class is supposed to serialize it and write it to file.
+ * <p>
+ * Existing files are overwritten, and the file name is constructed like this:
+ * <tt>&lt;ClassName&gt;-&lt;modifiedVersionString&gt;.ser</tt>
+ * The version string is modified by replacing punctuation marks with
+ * underscores.
+ */
+public class SerializeDataSources {
+
+    /** List of known data sources in the embedded driver. */
+    private static final String[] KNOWN_EMBEDDED_DATA_SOURCES ={
+            "org.apache.derby.jdbc.EmbeddedDataSource",
+            "org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource",
+            "org.apache.derby.jdbc.EmbeddedXADataSource"
+        };
+
+    /** List of known data sources in the client driver. */
+    private static final String[] KNOWN_CLIENT_DATA_SOURCES ={
+            "org.apache.derby.jdbc.ClientDataSource",
+            "org.apache.derby.jdbc.ClientConnectionPoolDataSource",
+            "org.apache.derby.jdbc.ClientXADataSource"
+        };
+    
+    /**
+     * Serialize and write data sources to file.
+     * 
+     * @param minorVersion Derby version string (i.e. 10.3.2.1)
+     * @param buildNumber Derby build number (svn)
+     * @param dataSourceClasses list of data source class names
+     * @return The number of data sources serialized and written to file.
+     * 
+     * @throws ClassNotFoundException required class is not on the classpath
+     * @throws InstantiationException if instantiating data source class fails
+     * @throws IllegalAccessException if instantiating data source class fails
+     * @throws IOException if writing to file fails
+     * @throws NamingException if creating a naming reference for the data
+     *      source fails
+     */
+    private static int serializeDataSources(String versionString,
+                                            String buildNumber,
+                                            String[] dataSourceClasses)
+            throws ClassNotFoundException, InstantiationException,
+                   IllegalAccessException, IOException, NamingException {
+        String modifiedVersionString = versionString.replaceAll("\\.", "_");
+        int dsCount = 0;
+        for (String dsClassName : dataSourceClasses) {
+            Class dsClass;
+            // Try to load the class.
+            try {
+                dsClass = Class.forName(dsClassName);
+            } catch (ClassNotFoundException cnfe) {
+                // Print error message, but keep going.
+                System.out.println("\tcouldn't load " + dsClassName);
+                continue;
+            }
+            // Create new instance.
+            DataSource ds = (DataSource)dsClass.newInstance();
+            // Generate file name.
+            File serialized = new File(dsClass.getSimpleName() + "-" +
+                    modifiedVersionString + ".ser");
+            System.out.println("\twriting " + serialized.getName());
+            OutputStream os = new FileOutputStream(serialized);
+            ObjectOutputStream oos = new ObjectOutputStream(os);
+            // Wrote version string, build number, the data source object and finally
+            // a {@link javax.naming.Reference} for the data source.
+            oos.writeUTF(versionString);
+            oos.writeUTF(buildNumber);
+            oos.writeObject(ds);
+            Reference dsRef = ((Referenceable)ds).getReference(); 
+            oos.writeObject(dsRef);
+            oos.flush();
+            oos.close();
+            dsCount++;
+        }
+        return dsCount;
+    }
+
+    /**
+     * Attempts to read information from a file assumed to contain a
+     * serialized data source.
+     * <p>
+     * All information is printed to the console.
+     *
+     * @param fileName the name of the file to read from
+     * @return {@code true} if the file was read successfully, {@code false} if
+     *      something went wrong.
+     */
+    private static boolean printInfoFromSerializedFile(String fileName) {
+        System.out.println(">>> File: " + fileName);
+        File file = new File(fileName);
+        if (!file.exists()) {
+            System.out.println("\tFile does not exist.");
+            return false;
+        }
+        if (!file.canRead()) {
+            System.out.println("\tCannot read file.");
+            return false;
+        }
+        try {
+            InputStream is = new FileInputStream(file);
+            ObjectInputStream ois = new ObjectInputStream(is);
+            String version = ois.readUTF();
+            System.out.println("\tversion: " + version);
+            String buildNr = ois.readUTF();
+            System.out.println("\tbuild  : " + buildNr);
+            Object obj = ois.readObject();
+            System.out.println("\tobject : " + obj);
+            obj = ois.readObject();
+            System.out.println("\tobject : " + obj);
+        } catch (Exception e) {
+            System.out.println("\t!! De-serialization failed: " + e.getMessage());
+            e.printStackTrace();
+            return false;
+        }
+        return true; 
+    }
+
+    /**
+     * Serializes and writes a number of Derby data sources to disk, or
+     * attempts to read information from existing files.
+     * 
+     * @param args arguments from the command line. If there are no arguments,
+     *      the program will write data sources to file. Otherwise all
+     *      arguments are assumed to be file names of files to read.
+     * @throws Exception if something goes wrong
+     */
+    public static void main(String[] args)
+            throws Exception {
+        // Obtain Derby version / information.
+        int majorVersionEmbedded = sysinfo.getMajorVersion(sysinfo.DBMS);
+        int minorVersionEmbedded = sysinfo.getMinorVersion(sysinfo.DBMS);
+        String buildNumberEmbedded = sysinfo.getBuildNumber(sysinfo.DBMS);
+        String versionEmbedded = sysinfo.getVersionString(sysinfo.DBMS);
+        int majorVersionClient = sysinfo.getMajorVersion(sysinfo.CLIENT);
+        int minorVersionClient = sysinfo.getMinorVersion(sysinfo.CLIENT);
+        String buildNumberClient = sysinfo.getBuildNumber(sysinfo.CLIENT);
+        String versionClient = sysinfo.getVersionString(sysinfo.CLIENT);
+
+        // Check if we should try to read files.
+        if (args.length > 0) {
+            System.out.println("Reading files with the Derby version(s):");
+            System.out.println("\tembedded: " + versionEmbedded);
+            System.out.println("\tclient  : " + versionClient);
+            System.out.println();
+            for (int i=0; i < args.length; i++) {
+                boolean status = printInfoFromSerializedFile(args[i]);
+                System.out.println("File read successfully: " + status);
+                System.out.println();
+            }
+            System.exit(0);
+        }
+
+        // We are writing data sources to file.
+
+        // Counts to print some simple statistics at the end.
+        int knownDsCount = KNOWN_EMBEDDED_DATA_SOURCES.length +
+                KNOWN_CLIENT_DATA_SOURCES.length;
+        int dsWritten = 0;
+
+        // Only try to serialize data sources if we know which Derby version we
+        // are dealing with.
+        if (majorVersionEmbedded != -1 && minorVersionEmbedded != -1) {
+            System.out.println("Serializing embedded data sources for Derby " +
+                    "version " + versionEmbedded);
+            dsWritten += serializeDataSources(versionEmbedded,
+                    buildNumberEmbedded,
+                    KNOWN_EMBEDDED_DATA_SOURCES);
+        } else {
+            System.err.println("No embedded data sources will be generated " +
+                    "because Derby version can't be determined.");
+        }
+
+        if (majorVersionClient != -1 && minorVersionClient != -1) {
+            System.out.println("Serializing client data sources for Derby " +
+                    "version " + versionClient);
+            dsWritten += serializeDataSources(versionClient,
+                    buildNumberClient,
+                    KNOWN_CLIENT_DATA_SOURCES);
+        } else {
+            System.err.println("No client data sources will be generated " +
+                    "because Derby version can't be determined.");
+        }
+
+        // Print some simple statistics.
+        System.out.println();
+        System.out.println("Known data sources:   " + knownDsCount);
+        System.out.println("Data sources written: " + dsWritten);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/testData/serialized-data-sources/SerializeDataSources.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java?rev=627356&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
Wed Feb 13 03:06:29 2008
@@ -0,0 +1,287 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.DataSourceSerializationTest
+
+   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.functionTests.tests.jdbcapi;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import javax.sql.DataSource;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.Derby;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+
+/**
+ * Makes sure that old serialized data sources can be de-serialized with the
+ * current version of the data souce.
+ * <p>
+ * Serialized data source from old versions are expected to be found in
+ * <tt>testData/serialized-data-sources</tt>, with the following filename
+ * format CLASSNAME-VERSION.ser, where CLASSNAME is the unqualified name of the
+ * data source class, and VERSION is the Derby version. An example:
+ * <tt>ClientPooledConnectionDataSource-10_1.ser</tt>
+ * <p>
+ * A separation between JDBC 4.0 specific classes and the other classes is not
+ * made.
+ * <p>
+ * This test should detect the typical incompatible changes in the current
+ * data source implementations, for instance deleting a field or changing its
+ * type.
+ */
+public class DataSourceSerializationTest
+        extends BaseJDBCTestCase {
+
+    /** Constant for Derby version 10.0.2.1. */
+    private static final String VERSION_10_0_2_1 = "10_0_2_1";
+    /** Constant for Derby version 10.1.3.1. */
+    private static final String VERSION_10_1_3_1 = "10_1_3_1";
+    /** Constant for Derby version 10.2.2.0 */
+    private static final String VERSION_10_2_2_0 = "10_2_2_0";
+    /** Constant for Derby version 10.3.2.1. */
+    private static final String VERSION_10_3_2_1 = "10_3_2_1";
+
+    public DataSourceSerializationTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Tests the de-serialization of the basic embedded data source.
+     *
+     * @throws Exception for a number of error conditions
+     */
+    public void serTestEmbeddedDataSource()
+            throws Exception {
+        final String EMBEDDED_CLASS = "EmbeddedDataSource";
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_0_2_1);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_1_3_1);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_2_2_0);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_3_2_1);
+    }
+
+    /**
+     * Tests the de-serialization of the embedded connection pool data source.
+     *
+     * @throws Exception for a number of error conditions
+     */
+    public void serTestEmbeddedConnectionPoolDataSource()
+            throws Exception {
+        final String EMBEDDED_CLASS = "EmbeddedConnectionPoolDataSource";
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_0_2_1);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_1_3_1);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_2_2_0);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_3_2_1);
+    }
+
+    /**
+     * Tests the de-serialization of the embedded XA data source.
+     *
+     * @throws Exception for a number of error conditions
+     */
+    public void serTestEmbeddedXADataSource()
+            throws Exception {
+        final String EMBEDDED_CLASS = "EmbeddedXADataSource";
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_0_2_1);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_1_3_1);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_2_2_0);
+        deSerializeDs(EMBEDDED_CLASS, VERSION_10_3_2_1);
+    }
+
+    /**
+     * Tests the de-serialization of the basic client data source.
+     *
+     * @throws Exception for a number of error conditions
+     */
+    public void serTestClientDataSource()
+            throws Exception {
+        final String CLIENT_CLASS = "ClientDataSource";
+        // No client driver for Derby 10.0
+        deSerializeDs(CLIENT_CLASS, VERSION_10_1_3_1);
+        deSerializeDs(CLIENT_CLASS, VERSION_10_2_2_0);
+        deSerializeDs(CLIENT_CLASS, VERSION_10_3_2_1);
+    }
+
+    /**
+     * Tests the de-serialization of the client connection pool data source.
+     *
+     * @throws Exception for a number of error conditions
+     */
+    public void serTestClientConnectionPoolDataSource()
+            throws Exception {
+        final String CLIENT_CLASS = "ClientConnectionPoolDataSource";
+        // No client driver for Derby 10.0
+        deSerializeDs(CLIENT_CLASS, VERSION_10_1_3_1);
+        deSerializeDs(CLIENT_CLASS, VERSION_10_2_2_0);
+        deSerializeDs(CLIENT_CLASS, VERSION_10_3_2_1);
+    }
+
+    /**
+     * Tests the de-serialization of the client XA data source.
+     *
+     * @throws Exception for a number of error conditions
+     */
+    public void serTestClientXADataSource()
+            throws Exception {
+        final String CLIENT_CLASS = "ClientXADataSource";
+        // No client driver for Derby 10.0
+        deSerializeDs(CLIENT_CLASS, VERSION_10_1_3_1);
+        deSerializeDs(CLIENT_CLASS, VERSION_10_2_2_0);
+        deSerializeDs(CLIENT_CLASS, VERSION_10_3_2_1);
+    }
+
+    /**
+     * Attempts to de-serialize a data source object from a file.
+     * <p>
+     * <ol> <li>Derby version string - UTF</li>
+     *      <li>Derby build number - UTF</li>
+     *      <li>Derby data source - object</li>
+     *      <li>Derby data source reference - object</li>
+     * </ol>
+     * <p>
+     * If the object is successfully instantiated and cast to
+     * {@link java.sql.DataSource}
+     *
+     * @param className name of the class to de-serialize
+     * @param version Derby version
+     *
+     * @throws Exception on a number of error conditions
+     */
+    private void deSerializeDs(String className, String version)
+            throws Exception {
+        // Construct the filename
+        final StringBuffer fname = new StringBuffer(className);
+        fname.append('-');
+        fname.append(version);
+        fname.append(".ser");
+
+        // De-serialize the data source.
+        InputStream is;
+        try {
+            is = (FileInputStream)AccessController.doPrivileged(
+                  new PrivilegedExceptionAction() {
+                public Object run() throws FileNotFoundException {
+                    return new FileInputStream(
+                            SupportFilesSetup.getReadOnly(fname.toString()));
+                }
+            });
+            } catch (PrivilegedActionException e) {
+                // e.getException() should be a FileNotFoundException.
+                throw (FileNotFoundException)e.getException();
+            }
+
+        ObjectInputStream ois = new ObjectInputStream(is);
+        String buildVersion = ois.readUTF();
+        String buildNumber = ois.readUTF();
+        println("Data source " + className + ", version " +
+                buildVersion + ", build " + buildNumber);
+        Object dsObj = ois.readObject();
+        assertNotNull("De-serialized data source is null", dsObj);
+        assertTrue("Unexpected class instantiated: " +
+                dsObj.getClass().getName(),
+                dsObj.getClass().getName().indexOf(className) > 0);
+        DataSource ds = (DataSource)dsObj;
+        // Just see if the object is usable.
+        int newTimeout = ds.getLoginTimeout() +9;
+        assertFalse(ds.getLoginTimeout() == newTimeout);
+        ds.setLoginTimeout(newTimeout);
+        assertEquals(newTimeout, ds.getLoginTimeout());
+
+        // Recreate the data source using reference.
+        Reference dsRef = (Reference)ois.readObject();
+        String factoryClassName = dsRef.getFactoryClassName();
+        ObjectFactory factory =
+            (ObjectFactory)Class.forName(factoryClassName).newInstance();
+        Object recreatedDs =
+            factory.getObjectInstance(dsRef, null, null, null);
+        ds = (DataSource)recreatedDs;
+        assertTrue("Unexpected class instantiated by Reference: " +
+                dsObj.getClass().getName(),
+                dsObj.getClass().getName().indexOf(className) > 0);
+    }
+
+    /**
+     * Returns an appropariate suite of tests to run.
+     *
+     * @return A test suite.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("DataSourceSerializationTest");
+        String filePrefix = "functionTests/testData/serialized-data-sources/";
+        // De-serialize embedded data sources only if we have the engine code.
+        if (Derby.hasEmbedded()) {
+            suite.addTest(new DataSourceSerializationTest(
+                    "serTestEmbeddedDataSource"));
+            suite.addTest(new DataSourceSerializationTest(
+                    "serTestEmbeddedConnectionPoolDataSource"));
+            suite.addTest(new DataSourceSerializationTest(
+                    "serTestEmbeddedXADataSource"));
+        }
+
+        // De-serialize client data sources only if we have the client code.
+        if (Derby.hasClient()) {
+            suite.addTest(new DataSourceSerializationTest(
+                    "serTestClientDataSource"));
+            suite.addTest(new DataSourceSerializationTest(
+                    "serTestClientConnectionPoolDataSource"));
+            suite.addTest(new DataSourceSerializationTest(
+                    "serTestClientXADataSource"));
+        }
+
+        return new SupportFilesSetup(suite, new String[] {
+                // 10.0 resources
+                filePrefix + "EmbeddedDataSource-10_0_2_1.ser",
+                filePrefix + "EmbeddedConnectionPoolDataSource-10_0_2_1.ser",
+                filePrefix + "EmbeddedXADataSource-10_0_2_1.ser",
+
+                // 10.1 resources
+                filePrefix + "EmbeddedDataSource-10_1_3_1.ser",
+                filePrefix + "EmbeddedConnectionPoolDataSource-10_1_3_1.ser",
+                filePrefix + "EmbeddedXADataSource-10_1_3_1.ser",
+                filePrefix + "ClientDataSource-10_1_3_1.ser",
+                filePrefix + "ClientConnectionPoolDataSource-10_1_3_1.ser",
+                filePrefix + "ClientXADataSource-10_1_3_1.ser",
+
+                // 10.2 resources
+                filePrefix + "EmbeddedDataSource-10_2_2_0.ser",
+                filePrefix + "EmbeddedConnectionPoolDataSource-10_2_2_0.ser",
+                filePrefix + "EmbeddedXADataSource-10_2_2_0.ser",
+                filePrefix + "ClientDataSource-10_2_2_0.ser",
+                filePrefix + "ClientConnectionPoolDataSource-10_2_2_0.ser",
+                filePrefix + "ClientXADataSource-10_2_2_0.ser",
+
+                // 10.3 resources
+                filePrefix + "EmbeddedDataSource-10_3_2_1.ser",
+                filePrefix + "EmbeddedConnectionPoolDataSource-10_3_2_1.ser",
+                filePrefix + "EmbeddedXADataSource-10_3_2_1.ser",
+                filePrefix + "ClientDataSource-10_3_2_1.ser",
+                filePrefix + "ClientConnectionPoolDataSource-10_3_2_1.ser",
+                filePrefix + "ClientXADataSource-10_3_2_1.ser",
+            });
+    }
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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?rev=627356&r1=627355&r2=627356&view=diff
==============================================================================
--- 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
Wed Feb 13 03:06:29 2008
@@ -116,6 +116,7 @@
 
             // Test uses JDBC 3.0 datasources, and javax.naming.Reference etc.
             suite.addTest(DataSourceReferenceTest.suite());
+            suite.addTest(DataSourceSerializationTest.suite());
 
             // Test uses DriverManager, Pooled and XADataSources, and
             // an inner class implements ConnectionEventListener.



Mime
View raw message