db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1055585 - in /db/derby/code/branches/10.5: ./ java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/
Date Wed, 05 Jan 2011 19:06:56 GMT
Author: kmarsden
Date: Wed Jan  5 19:06:55 2011
New Revision: 1055585

URL: http://svn.apache.org/viewvc?rev=1055585&view=rev
Log:
DERBY-4157 backport refactor of upgrade tests.
Contributed by Rick Hillegas

Backporting change 764912 which is just a code refactor. The remaining DERBY-4157 have not
been ported to 10.5.

Attaching derby-4157-01-aa-refactor.diff. This patch is a first step toward writing the new
test. This patch factors out some of the existing upgrade test machinery so that the new test
can re-use that machinery:
+
1) logic to discover old versions
2) logic to create class loaders out of those old versions
3) logic to use those class loaders



Added:
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/OldVersions.java
      - copied unchanged from r764912, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/OldVersions.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeClassLoader.java
      - copied unchanged from r764912, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeClassLoader.java
Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan  5 19:06:55 2011
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:942027,957000,962738,965351,987678
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716,965647,967304,980684,986689,986834,999119,1002291,1002682,1002853,1021426,1025795,1040658
+/db/derby/code/trunk:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716,965647,967304,980684,986689,986834,999119,1002291,1002682,1002853,1021426,1025795,1040658

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java?rev=1055585&r1=1055584&r2=1055585&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
Wed Jan  5 19:06:55 2011
@@ -79,7 +79,7 @@ final class PhaseChanger extends BaseTes
         
         if (loader != null) {
             previousLoader = Thread.currentThread().getContextClassLoader();
-            setThreadLoader(loader);
+            UpgradeClassLoader.setThreadLoader(loader);
         }
          
         DataSource ds = JDBCDataSource.getDataSource();
@@ -148,7 +148,7 @@ final class PhaseChanger extends BaseTes
         
        
         if (loader != null)
-            setThreadLoader(previousLoader);       
+            UpgradeClassLoader.setThreadLoader(previousLoader);       
         loader = null;
         previousLoader = null;
         
@@ -156,26 +156,4 @@ final class PhaseChanger extends BaseTes
         UpgradeChange.oldVersion.set(null);
     }
     
-    private void setThreadLoader(final ClassLoader which) {
-
-        AccessController.doPrivileged
-        (new java.security.PrivilegedAction(){
-            
-            public Object run()  { 
-                java.lang.Thread.currentThread().setContextClassLoader(which);
-              return null;
-            }
-        });
-    }
-    
-    private ClassLoader getThreadLoader() {
-
-        return (ClassLoader) AccessController.doPrivileged
-        (new java.security.PrivilegedAction(){
-            
-            public Object run()  { 
-                return Thread.currentThread().getContextClassLoader();
-            }
-        });
-    }
 }

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=1055585&r1=1055584&r2=1055585&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
Wed Jan  5 19:06:55 2011
@@ -50,14 +50,8 @@ import org.apache.derbyTesting.junit.Tes
  * connections.
  *
  */
-class UpgradeRun {
-    private static final String[] jarFiles = {
-            "derby.jar", 
-            //"derbynet.jar",
-            //"derbyclient.jar",
-            //"derbytools.jar"
-            };
-    
+class UpgradeRun extends UpgradeClassLoader
+{
     
     /**
      * Set of additional databases for tests that
@@ -82,60 +76,15 @@ class UpgradeRun {
         new AdditionalDb("ROLES_10_5", false)
     };
     
-    static final String oldVersionsPath;
-    static final String jarPath;
-    
-    static {
-         
-        oldVersionsPath = (String) AccessController.doPrivileged
-        (new java.security.PrivilegedAction(){
-
-            public Object run(){
-            return System.getProperty(_Suite.OLD_VERSIONS_PATH_PROPERTY);
-
-            }
-
-        }
-         );
-
-         jarPath = (String ) AccessController.doPrivileged
-        (new java.security.PrivilegedAction(){
-
-            public Object run(){
-            return System.getProperty(_Suite.OLD_RELEASE_PATH_PROPERTY);
-
-            }
-
-        }
-         );
-    }
-
-    private static String getTextVersion(int[] iv)
-    {
-        String version = iv[0] + "." + iv[1] +
-        "." + iv[2] + "." + iv[3];
-        return version;
-    }
-
     public final static Test suite(final int[] version) {
         
-        ClassLoader oldLoader = (ClassLoader )AccessController.doPrivileged
-        (new java.security.PrivilegedAction(){
-
-            public Object run(){
-            return createClassLoader(version);
-
-            }
-
-        }
-         );
+        ClassLoader oldLoader = makeClassLoader( version );
         
         // If no jars then just skip.
         if (oldLoader == null)
         {
             TestSuite suite = new TestSuite(
                     "Empty: Skipped upgrade Tests (no jars) for " + getTextVersion(version));
-            BaseTestCase.traceit("Empty: Skip upgrade Tests (no jars) for " + getTextVersion(version));
             return suite;
         }
         
@@ -283,101 +232,6 @@ class UpgradeRun {
         return TestConfiguration.connectionDSDecorator(suite);
     }
     
-    /**
-     * Get the location of jars of old release. The location is specified 
-     * in the property derbyTesting.oldReleasePath. If derbyTesting.oldReleasePath
-     * is set to the empty string it is ignored.
-     *  
-     * @return location of jars of old release
-     */
-    private static String getOldJarLocation(int[] oldVersion) {
-      
-        if (jarPath == null || jarPath.length() == 0)
-            return null;
-        
-        String version = getTextVersion(oldVersion);
-        String jarLocation = jarPath + File.separator + version;
-        
-        return jarLocation;
-    }
-
-    /**
-     * Get the location of jars of old release, using the url for svn at apache.
-     *  
-     * @return location of jars of old release
-     */
-    private static String getOldJarURLLocation(int[] oldVersion) {
-
-        String oldJarUrl = _Suite.OLD_JAR_URL;
-        
-        String version = getTextVersion(oldVersion);
-        String jarLocation = oldJarUrl + "/" + version;
-        
-        return jarLocation;       
-    }
-
-    /**
-     * Create a class loader using jars in the specified location. Add all jars 
-     * specified in jarFiles and the testing jar.
-     * 
-     * @param version the Derby version to create a classloader for.
-     * @return class loader
-     */
-    private static ClassLoader createClassLoader(int[] version)
-    {
-        URL[] url = new URL[jarFiles.length];
-        
-        String jarLocation = getOldJarLocation(version);
-        
-        if (jarLocation != null)
-        {
-            File lib = new File(jarLocation);
-
-            // If the jars do not exist then return null
-            // and the caller will set up to skip this.
-            if (!lib.exists()){
-                BaseTestCase.alarm("Non-existing location for jar files: '" 
-                    + jarLocation + "'. Upgrade tests can NOT be run!");
-                return null;
-            }
-
-            for (int i=0; i < jarFiles.length; i++) {
-                try {
-                    url[i] = new File(lib, jarFiles[i]).toURL();
-                } catch (MalformedURLException e) {
-                    Assert.fail(e.toString());
-                }
-            }
-        }
-        else
-        
-        // if the property was not set, attempt to access the jars from 
-        // the saved svn location.
-        // Note, this means the test fails if there is no network connection
-        // (or the server at apache is down) unless the property is set
-        // to a valid location
-        {
-            String oldURLJarLocation = getOldJarURLLocation(version);
-            for (int i=0; i < jarFiles.length; i++) {
-                try {
-                    url[i] = new URL(oldURLJarLocation + "/" + jarFiles[i]);
-                    Object dummy = url[i].getContent(); // IOException if not available.
-                } catch (MalformedURLException e) {
-                    Assert.fail(e.toString());
-                } catch (IOException e) {
-                    BaseTestCase.alarm("IOException msg: '" + e.getMessage() + "'." 
-                        + " Upgrade tests can NOT be run!");
-                    return null;
-                }
-
-            }
-        }
-        
-        // Specify null for parent class loader to avoid mixing up 
-        // jars specified in the system classpath
-        return new URLClassLoader(url, null);       
-    }
-    
     
     /**
      * When running against certains old releases in Java SE 6

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java?rev=1055585&r1=1055584&r2=1055585&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java
Wed Jan  5 19:06:55 2011
@@ -20,9 +20,6 @@ limitations under the License.
 */
 package org.apache.derbyTesting.functionTests.tests.upgradeTests;
 
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -115,7 +112,7 @@ public class _Suite extends BaseTestCase
      * when running tests.
      */
 
-    private static OldVersions old;
+    private static int[][] old;
 
     /**
      * Use suite method instead.
@@ -129,180 +126,15 @@ public class _Suite extends BaseTestCase
                 + OLD_RELEASE_PATH_PROPERTY + "=" + UpgradeRun.jarPath
                 + " / " + OLD_VERSIONS_PATH_PROPERTY + "=" + UpgradeRun.oldVersionsPath;
         TestSuite suite = new TestSuite(id);       
-        
-        if ( UpgradeRun.oldVersionsPath != null )
-        {
-            old = new OldVersions(UpgradeRun.oldVersionsPath);
-        }
-        OldVersions.show();
 
-        for (int i = 0; i < old.VERSIONS.length; i++) {
-            // JSR169 support was only added with 10.1, so don't
-            // run 10.0 to later upgrade if that's what our jvm is supporting.
-            if ((JDBC.vmSupportsJSR169() && 
-                (old.VERSIONS[i][0]==10) && (old.VERSIONS[i][1]==0))) {
-                traceit("Skipping 10.0 on JSR169");
-                continue;
-            }
-            // Derby 10.3.1.4 does not boot on the phoneME advanced platform,
-            // (see DERBY-3176) so don't run upgrade tests in this combination.
-            if ( System.getProperty("java.vm.name").equals("CVM")
-                  && System.getProperty("java.vm.version").startsWith("phoneme")
-                  && old.VERSIONS[i][0]==10 && old.VERSIONS[i][1]==3 
-                  && old.VERSIONS[i][2]==1 && old.VERSIONS[i][3]==4 ) {
-                traceit("Skipping 10.3.1.4 on CVM/phoneme");
-                continue;
-            }
-            suite.addTest(UpgradeRun.suite(old.VERSIONS[i]));
+        old = OldVersions.getSupportedVersions();
+        
+        for (int i = 0; i < old.length; i++) {
+            suite.addTest(UpgradeRun.suite(old[i]));
         }
 
         return suite;
     }
     
 
-    private static class OldVersions{
-
-        private static int[][] VERSIONS =
-          {
-            {10, 0, 2, 1}, // 10.0.2.1 (incubator release)
-            {10, 1, 1, 0}, // 10.1.1.0 (Aug 3, 2005 / SVN 208786)
-            {10, 1, 2, 1}, // 10.1.2.1 (Nov 18, 2005 / SVN 330608)
-            {10, 1, 3, 1}, // 10.1.3.1 (Jun 30, 2006 / SVN 417277)
-            {10, 2, 1, 6}, // 10.2.1.6 (Oct 02, 2006 / SVN 452058)
-            {10, 2, 2, 0}, // 10.2.2.0 (Dec 12, 2006 / SVN 485682)
-            {10, 3, 1, 4}, // 10.3.1.4 (Aug 1, 2007 / SVN 561794)
-            {10, 3, 3, 0}, // 10.3.3.0 (May 12, 2008 / SVN 652961)
-            {10, 4, 1, 3}, // 10.4.1.3 (April 24, 2008 / SVN 648739)
-            {10, 4, 2, 0}, // 10.4.2.0 (September 05, 2008 / SVN 693552)
-          };
-        private OldVersions(String oldVersionsPath)
-        {
-            BufferedReader br = null;
-            try{
-                FileReader fr = new FileReader(oldVersionsPath);
-                br = new BufferedReader(fr);
-            }
-            catch (java.io.FileNotFoundException fNFE)
-            {
-                alarm("File '" + oldVersionsPath 
-                        + "' was not found, using default old versions for upgrade tests.");
-                return;
-            }
-            traceit("Run upgrade tests on versions defined in '" + oldVersionsPath + "'");
-            getVersions(br, oldVersionsPath);
-        }
-
-        private void getVersions(BufferedReader br, String oldVersionsPath) 
-        {
-            VERSIONS = new int[256][4];
-
-            int versions = 0;
-
-            String line = null;
-            int lineNum = 0;
-            try {
-                while ((line = br.readLine()) != null) {
-                    lineNum++;
-                    /* Ignore lines not matching the regexp: "^[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]"
-                     * NB. java.util.regex.Matcher and java.util.regex.Pattern can not be
-                     * used on small devices(JSR219).
-                     */
-                    try {
-                        String[] parts = split4(line,'.');
-                        // String[] parts = line.split("\\."); // JSR219 does NOT have String.split()!
-                        if (parts.length >= 3) {
-
-                            int[] vstr = new int[4];
-                            for (int i = 0; i < 4; i++) // Using first 4 values
-                            {
-                                String str = parts[i];
-                                if (i == 3) { // Clean... remove trailing non-digits
-                                    str = clean(str,"0123456789");
-                                }
-                                vstr[i] = Integer.parseInt(str);
-                            }
-                            VERSIONS[versions++] = vstr;
-                        } else {
-                            alarm("Illegal version format on: " + line);
-                        }
-                    } catch (NumberFormatException nfe) {
-                        alarm("NumberFormatException on line " + lineNum + ": " + line +
": " + " " + nfe.getMessage());
-                    } catch (ArrayIndexOutOfBoundsException aie) {
-                        alarm("ArrayIndexOutOfBoundsException on line " + lineNum + ": "
+ line + ": " + " " + aie.getMessage());
-                    }
-                }
-            } catch (IOException ioe) {
-                alarm("Error reading from file: " + oldVersionsPath + ioe.getMessage());
-            }
-            
-            int[][] finalVERSIONS = new int[versions][4];
-            for (int v = 0; v < versions; v++) {
-                finalVERSIONS[v] = VERSIONS[v];
-            }
-            VERSIONS = finalVERSIONS;
-
-        }
-
-        private static void show() {
-            traceit("Upgrade test versions listed:");
-            for (int o = 0; o < VERSIONS.length; o++) {
-                String ver = "";
-                for (int i = 0; i < VERSIONS[o].length; i++) {
-                    if (i == 0) {
-                        ver = "" + VERSIONS[o][i];
-                    } else {
-                        ver = ver + "." + VERSIONS[o][i];
-                    }
-                }
-                traceit(ver);
-            }
-        }
-        private static String[] split4(String l, char c)
-        {
-            String[] res = new String[4];
-            try{
-            int p0 = l.indexOf(c);
-            if (p0<0) return res;
-            
-            res[0] = l.substring(0, p0);
-            int p1 = l.indexOf(c,p0+1);
-            if (p1<0) return res;
-            
-            res[1] = l.substring(p0+1, p1);
-            int p2 = l.indexOf(c,p1+1); 
-            if (p2<0) return res;
-            
-            res[2] = l.substring(p1+1, p2);
-            int p3 = l.indexOf(c,p2+1); 
-            if (p3<0) p3=l.length();
-            
-            res[3] = l.substring(p2+1, p3);
-            
-            } catch(StringIndexOutOfBoundsException sie){
-                println("split4 StringIndexOutOfBoundsException: "+sie.getMessage());
-                sie.printStackTrace();
-            }
-            return res;
-        }
-        private static String clean(String l, String allowed)
-        {
-            for (int i=0;i<l.length();i++)
-            {
-                if (!matches(l.charAt(i),allowed))
-                {
-                    return l.substring(0,i);
-                }
-            }
-            return l;
-        }
-        private static boolean matches(char c, String allowed)
-        {
-            for (int j=0;j<allowed.length();j++)
-            {
-                if (allowed.charAt(j) == c) return true;
-            }
-            return false;
-        }
-        
-    }
 }



Mime
View raw message