You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2008/12/19 15:03:23 UTC
svn commit: r728024 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/upgradeTests/PhaseChanger.java
functionTests/tests/upgradeTests/UpgradeRun.java
functionTests/tests/upgradeTests/_Suite.java junit/BaseTestCase.java
Author: rhillegas
Date: Fri Dec 19 06:03:22 2008
New Revision: 728024
URL: http://svn.apache.org/viewvc?rev=728024&view=rev
Log:
DERBY-3982: Commit Ole's DERBY-3982_p2_diff.txt patch, which makes it easy to specify patch releases as starting points for the upgrade tests.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java?rev=728024&r1=728023&r2=728024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java Fri Dec 19 06:03:22 2008
@@ -20,6 +20,7 @@
*/
package org.apache.derbyTesting.functionTests.tests.upgradeTests;
+import java.io.PrintStream;
import java.security.AccessController;
import java.sql.SQLException;
@@ -28,6 +29,7 @@
import junit.extensions.TestSetup;
import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseTestCase;
import org.apache.derbyTesting.junit.BaseTestSetup;
import org.apache.derbyTesting.junit.JDBCDataSource;
import org.apache.derbyTesting.junit.TestConfiguration;
@@ -42,6 +44,7 @@
private final int[] version;
private ClassLoader loader;
private ClassLoader previousLoader;
+ private boolean trace = false;
public PhaseChanger(Test test, int phase,
ClassLoader loader, int[] version) {
@@ -62,6 +65,17 @@
UpgradeChange.phase.set(new Integer(phase));
UpgradeChange.oldVersion.set(version);
+ TestConfiguration config = TestConfiguration.getCurrent();
+ trace = config.doTrace();
+ if ( trace )
+ {
+ String versStr = ((int[]) UpgradeChange.oldVersion.get())[0]
+ + "." + ((int[]) UpgradeChange.oldVersion.get())[1]
+ + "." + ((int[]) UpgradeChange.oldVersion.get())[2]
+ + "." + ((int[]) UpgradeChange.oldVersion.get())[3];
+ BaseTestCase.traceit("Test upgrade from: " + versStr + ", phase: "
+ + UpgradeChange.PHASES[phase]);
+ }
if (loader != null) {
previousLoader = Thread.currentThread().getContextClassLoader();
@@ -102,6 +116,7 @@
*/
protected void tearDown() throws InterruptedException
{
+ if ( trace ) BaseTestCase.traceit(" Test upgrade done.");
if (phase != UpgradeChange.PH_POST_HARD_UPGRADE) {
DataSource ds = JDBCDataSource.getDataSource();
JDBCDataSource.shutdownDatabase(ds);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=728024&r1=728023&r2=728024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java Fri Dec 19 06:03:22 2008
@@ -21,6 +21,7 @@
package org.apache.derbyTesting.functionTests.tests.upgradeTests;
import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
@@ -34,6 +35,7 @@
import junit.framework.TestSuite;
import org.apache.derbyTesting.functionTests.tests.jdbcapi.DatabaseMetaDataTest;
+import org.apache.derbyTesting.junit.BaseTestCase;
import org.apache.derbyTesting.junit.SecurityManagerSetup;
import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
@@ -80,10 +82,23 @@
new AdditionalDb("ROLES_10_5", false)
};
+ static final String oldVersionsPath;
static final String jarPath;
static {
- jarPath = (String ) AccessController.doPrivileged
+
+ 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(){
@@ -120,12 +135,14 @@
{
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;
}
-
+
TestSuite suite = new TestSuite(
"Upgrade Tests from " + getTextVersion(version));
+ BaseTestCase.traceit("Prepare to run upgrade tests from " + getTextVersion(version));
for (int phase = 0;
@@ -144,8 +161,8 @@
break;
}
- Test phaseTests = baseSuite(
- "Upgrade Phase: " + UpgradeChange.PHASES[phase],
+ Test phaseTests = baseSuite(getTextVersion(version)
+ + " Upgrade Phase: " + UpgradeChange.PHASES[phase] + " ",
phase, version);
Test phaseSet = new PhaseChanger(phaseTests, phase, loader, version);
@@ -201,7 +218,7 @@
int oldMajor = version[0];
int oldMinor = version[1];
-
+
// No connection is expected in the post hard upgrade
// phase, so don't bother adding test fixtures.
if (phase != UpgradeChange.PH_POST_HARD_UPGRADE)
@@ -318,8 +335,11 @@
// If the jars do not exist then return null
// and the caller will set up to skip this.
- if (!lib.exists())
+ 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 {
@@ -341,9 +361,15 @@
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;
}
+
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java?rev=728024&r1=728023&r2=728024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java Fri Dec 19 06:03:22 2008
@@ -20,8 +20,9 @@
*/
package org.apache.derbyTesting.functionTests.tests.upgradeTests;
-import java.util.Enumeration;
-import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -69,6 +70,13 @@
public class _Suite extends BaseTestCase {
/**
+ * Property that gives the location of a file listing old versions
+ * to be tested.
+ * To be able to override default values hard-coded for OLD_VERSIONS.
+ */
+ static final String OLD_VERSIONS_PATH_PROPERTY =
+ "derbyTesting.oldVersionsPath";
+ /**
* Property that indicates the location of the
* old releases.
*/
@@ -106,19 +114,8 @@
* -DderbyTesting.oldReleasePath=$HOME/derby_upgrade/jars
* when running tests.
*/
- private static final int[][] OLD_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 static OldVersions old;
/**
* Use suite method instead.
@@ -128,30 +125,184 @@
}
public static Test suite() {
+ String id = "Upgrade Suite: "
+ + OLD_RELEASE_PATH_PROPERTY + "=" + UpgradeRun.jarPath
+ + " / " + OLD_VERSIONS_PATH_PROPERTY + "=" + UpgradeRun.oldVersionsPath;
+ TestSuite suite = new TestSuite(id);
- TestSuite suite = new TestSuite("Upgrade Suite: "
- + OLD_RELEASE_PATH_PROPERTY + "=" + UpgradeRun.jarPath);
+ if ( UpgradeRun.oldVersionsPath != null )
+ {
+ old = new OldVersions(UpgradeRun.oldVersionsPath);
+ }
+ OldVersions.show();
- for (int i = 0; i < OLD_VERSIONS.length; i++) {
+ 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))) {
+ (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 ) {
+ && 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]));
+ suite.addTest(UpgradeRun.suite(old.VERSIONS[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;
+ }
+
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=728024&r1=728023&r2=728024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Fri Dec 19 06:03:22 2008
@@ -172,6 +172,16 @@
}
/**
+ * Print trace string.
+ * @param text String to print
+ */
+ public static void traceit(final String text) {
+ if (TestConfiguration.getCurrent().doTrace()) {
+ out.println(text);
+ }
+ }
+
+ /**
* Print debug string.
* @param t Throwable object to print stack trace from
*/