public class UpgradeTrajectoryTest extends BaseJDBCTestCase
Test upgrade trajectories. This test compares the metadata in upgraded databases to the metadata in databases created from scratch. Given a collection of releases, this test does the following:
derbyTesting.allTrajectories
is set to true, builds the set of all upgrade trajectories possible on
that collection of releases. An upgrade trajectory is a sorted subset of
those releases. Each subset is sorted in ascending release order. We
exclude the vacuous empty subset and the uninteresting singleton
subsets. A set of N releases gives rise to ((2**N) - N) - 1 hard-upgrade
trajectories.By default we don't consider soft-upgrades. Also by default, we consider trajectories with more than one release from the same branch. You can parameterize or customize some constants (see below) if you want to change these decisions.
By default we consider all trajectories possible on the collection
of releases listed in OldVersions
. If you want to consider
a different collection of releases, you can override the OldVersions
collection by setting the system property "derbyTesting.oldVersionsPath"
. Here, for instance, is the command
line to run this test against a customized list of releases:
java -XX:MaxPermSize=128M -Xmx512m \ -DderbyTesting.oldReleasePath=/Users/me/myDerbyReleaseDirectory \ -DderbyTesting.oldVersionsPath=/Users/me/fileContainingMyListOfTastyReleases \ junit.textui.TestRunner org.apache.derbyTesting.functionTests.tests.upgradeTests.UpgradeTrajectoryTest
For extra verbose output, you can set the "derby.tests.debug" property too:
java -XX:MaxPermSize=128M -Xmx512m \ -DderbyTesting.oldReleasePath=/Users/me/myDerbyReleaseDirectory \ -DderbyTesting.oldVersionsPath=/Users/me/fileContainingMyListOfTastyReleases \ -Dderby.tests.debug=true \ junit.textui.TestRunner org.apache.derbyTesting.functionTests.tests.upgradeTests.UpgradeTrajectoryTest
Here is the command line to run all upgrade trajectories against a customized list of releases:
java -XX:MaxPermSize=128M -Xmx512m \ -DderbyTesting.allTrajectories=true \ -DderbyTesting.oldReleasePath=/Users/me/myDerbyReleaseDirectory \ -DderbyTesting.oldVersionsPath=/Users/me/fileContainingMyListOfTastyReleases \ junit.textui.TestRunner org.apache.derbyTesting.functionTests.tests.upgradeTests.UpgradeTrajectoryTest
If you need to test a particular trajectory, you can hand-edit
makeSampleTrajectories()
and uncomment the call to it.
Modifier and Type | Field and Description |
---|---|
private boolean[] |
_hardUpgradeRequests |
private static java.lang.ThreadLocal<java.lang.ClassLoader> |
_originalClassLoader |
private Version.Trajectory |
_trajectory |
private java.lang.String |
_trajectoryName |
private java.util.HashMap<java.lang.String,java.lang.String> |
_unstableColumnValues |
private static java.lang.String |
ALIAS |
private static java.lang.String |
ALIASID |
static java.lang.String |
ALL_TRAJECTORIES_PROPERTY |
static java.lang.String |
BRANCH_10_0 |
static java.lang.String |
BRANCH_10_1 |
static java.lang.String |
BRANCH_10_2 |
static java.lang.String |
BRANCH_10_3 |
static java.lang.String |
BRANCH_10_4 |
static java.lang.String |
BRANCH_10_5 |
static java.lang.String |
COMPARISON_DATABASE |
private static java.lang.String |
CONGLOMERATENUMBER |
private static java.lang.String |
DERBY_4214_1 |
private static java.lang.String |
DERBY_4214_2 |
private static java.lang.String |
DERBY_4215 |
private static java.lang.String |
DUMMY_NUMBER |
private static java.lang.String |
DUMMY_STRING |
private static java.lang.String |
DUMMY_TIMESTAMP |
private static java.lang.String[] |
INITIAL_TABLES |
private static java.lang.String |
LASTCOMPILED |
private static boolean |
LOQUACIOUS |
private static java.lang.String |
ROUTINEPERMSID |
private static java.lang.String |
SPECIFICNAME |
private static java.lang.String |
STMTID |
private static java.lang.String |
STMTNAME |
private static java.lang.String |
SYSALIASES |
private static java.lang.String |
SYSCONGLOMERATES |
private static java.lang.String |
SYSROUTINEPERMS |
private static java.lang.String |
SYSSTATEMENTS |
private static java.lang.String |
TEXT |
static Version.Trajectory |
TRAJECTORY_10_0_2_1_TO_10_1_3_1 |
private static boolean |
TRJ_IGNORE_SOFT_UPGRADE |
private static boolean |
TRJ_SAME_BRANCH_NEIGHBORS |
static java.lang.String |
UPGRADED_DATABASE |
static Version |
VERSION_10_0_2_1 |
static Version |
VERSION_10_1_3_1 |
static Version |
VERSION_10_2_2_0 |
static Version |
VERSION_10_5_1_1 |
static Version |
VERSION_10_6_0_0 |
static java.lang.String |
VIRGIN_DATABASE |
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
UpgradeTrajectoryTest(Version.Trajectory trajectory,
boolean[] hardUpgradeRequests) |
Modifier and Type | Method and Description |
---|---|
private static void |
addHardUpgradeOnlyTrajectory(BaseTestSuite suite,
Version.Trajectory trajectory)
Add only the test case which hard-upgrades along all edges of the Trajectory.
|
private static void |
addSubset(Version[] supportedVersions,
java.util.ArrayList<Version.Trajectory> result,
boolean[] include,
boolean removeSameBranchNeighbors)
Add a subset to the evolving list of subsets of supported versions.
|
private static void |
addTrajectories(BaseTestSuite suite)
Add all of the trajectories we intend to test.
|
private static void |
addTrajectory(BaseTestSuite suite,
Version.Trajectory trajectory)
Add a single trajectory to the suite, looping through all combinations of
hard and softupgrade.
|
private static void |
addTrajectory(BaseTestSuite suite,
Version.Trajectory trajectory,
boolean[] hardUpgradeRequests)
Add a single trajectory to the suite, with upgrade instructions.
|
private static void |
addTrajectory(BaseTestSuite suite,
Version.Trajectory trajectory,
boolean[] hardUpgradeRequests,
int idx) |
private javax.sql.DataSource |
bootDatabase(java.lang.String logicalDatabaseName)
Boot a database.
|
private static Version.Trajectory[] |
buildMinimalSet(Version[] supportedVersions)
Builds the minimal set of trajectories for the supported versions.
|
private static Version.Trajectory[] |
buildPowerSet(Version[] supportedVersions)
Build the power set of all supported versions.
|
private static void |
buildPowerSetMinion(Version[] supportedVersions,
java.util.ArrayList<Version.Trajectory> result,
boolean[] include,
int idx,
boolean removeSameBranchNeighbors)
Recursive workhorse to build the power set of supported versions.
|
protected java.sql.PreparedStatement |
chattyPrepare(java.sql.Connection conn,
java.lang.String text)
Prepare a statement and report its sql text.
|
private static boolean[] |
clone(boolean[] input) |
private void |
compareDatabases(Version version,
java.lang.String leftDatabaseName,
java.lang.String rightDatabaseName)
Compare the metadata in two databases.
|
private void |
compareQueries(java.sql.Connection leftConn,
java.sql.Connection rightConn,
int colCount,
java.lang.String query)
Debug method to compare the results of a query on two databases.
|
private void |
compareResults(java.sql.Connection leftConn,
java.sql.Connection rightConn,
java.sql.Connection comparisonConn,
java.lang.String leftSchema,
java.lang.String rightSchema,
java.lang.String tableName,
java.lang.String query)
Compare the results of a query in two databases.
|
private boolean |
contains(java.lang.String left,
java.lang.String right) |
private void |
createDatabase(Version version,
java.lang.String logicalDatabaseName)
Create a database using the indicated version of Derby.
|
private java.lang.String |
filterKnownProblems(java.lang.String tableName,
java.lang.String actual)
Return empty string if passed in result is a known problem.
|
private java.lang.String |
getColumnValue(java.lang.String columnName,
java.lang.String[] columnNames,
java.lang.String[] row)
Return the value for the indicated columns.
|
private java.lang.String |
getDataVersion(java.sql.Connection conn)
Get the version of the data in the database.
|
private static Version[] |
getSupportedVersions()
Get the supported versions.
|
protected void |
goodStatement(java.sql.Connection conn,
java.lang.String ddl)
Run good DDL.
|
private boolean |
isColumn(java.lang.String expectedTableName,
java.lang.String expectedColumnName,
java.lang.String actualTableName,
java.lang.String actualColumnName)
Return true if we are dealing with the indicated column.
|
private boolean |
isUUID(java.lang.String raw)
Return true if the string looks like a UUID.
|
private void |
leftJoin(java.sql.Connection conn,
java.util.ArrayList columnNames,
java.lang.String tableName,
java.lang.String leftTableName,
java.lang.String rightTableName)
Left join two tables and verify that the result is empty.
|
private java.util.ArrayList<java.lang.String> |
listSystemTables(java.sql.Connection conn)
Get the names of all the system tables in the database except for the
list of initial tables.
|
private javax.sql.DataSource |
makeDataSource(java.lang.String logicalDatabaseName)
Make a DataSource given a logical database name.
|
private static Version.Trajectory[] |
makeSampleTrajectories()
Sample trajectory for debugging this program.
|
private static Version.Trajectory[] |
makeTrajectories()
Make all known upgrade trajectories.
|
private void |
normalizeRow(java.lang.String tableName,
java.lang.String[] columnNames,
java.lang.String[] row)
Replace values which are known to be unstable.
|
private void |
printQueryResults(java.sql.Connection conn,
java.lang.String query)
Debug method to print out a result set.
|
private java.lang.String |
printResultSet(java.sql.ResultSet rs)
Stringify a result set.
|
private void |
restoreOriginalClassLoader() |
private void |
saveOriginalClassLoader() |
private static boolean |
shouldBuildAllTrajectories()
Return true if we should build all trajectories.
|
private void |
shutdownDatabase(javax.sql.DataSource ds)
Shutdown a database.
|
private static Version.Trajectory[] |
squeezeArray(java.util.ArrayList<Version.Trajectory> trajectoryList)
Turn a list of trajectories into an array.
|
private java.lang.String |
stringifyUpgradeRequests() |
private int |
stuffTable(java.lang.String tableName,
java.sql.ResultSet select,
java.sql.PreparedStatement insert)
Copy metadata from a source table into a target table.
|
private boolean |
suffersDERBY_4215(java.lang.String tableName)
Return true if the conditions of DERBY-4215 exist.
|
private boolean |
suffersDERBY_4216(java.lang.String tableName)
Return true if the conditions of DERBY-4216 exist.
|
static junit.framework.Test |
suite()
Return the suite of tests.
|
void |
testTrajectory()
Test a single trajectory.
|
private java.lang.String |
trimDriverVersion(java.lang.String driverVersion)
Strip the trailing subversion stamp from a Derby version number.
|
private javax.sql.DataSource |
upgradeDatabase(java.lang.String logicalDatabaseName,
boolean hardUpgrade)
Hard-upgrade a database.
|
private void |
upgradeDatabase(Version softwareVersion,
Version dataVersion,
boolean hardUpgrade,
java.lang.String logicalDatabaseName)
Upgrade a database to the indicated version of Derby.
|
private void |
vetDBVersion(Version softwareVersion,
Version dataVersion,
java.sql.Connection conn)
Verify that the database has the expected version.
|
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, toString
public static final java.lang.String ALL_TRAJECTORIES_PROPERTY
public static Version VERSION_10_0_2_1
public static Version VERSION_10_1_3_1
public static Version VERSION_10_2_2_0
public static Version VERSION_10_5_1_1
public static Version VERSION_10_6_0_0
public static Version.Trajectory TRAJECTORY_10_0_2_1_TO_10_1_3_1
public static java.lang.String BRANCH_10_0
public static java.lang.String BRANCH_10_1
public static java.lang.String BRANCH_10_2
public static java.lang.String BRANCH_10_3
public static java.lang.String BRANCH_10_4
public static java.lang.String BRANCH_10_5
public static final java.lang.String UPGRADED_DATABASE
public static final java.lang.String VIRGIN_DATABASE
public static final java.lang.String COMPARISON_DATABASE
private static final java.lang.String DUMMY_NUMBER
private static final java.lang.String DUMMY_STRING
private static final java.lang.String DUMMY_TIMESTAMP
private static final java.lang.String DERBY_4214_1
private static final java.lang.String DERBY_4214_2
private static final java.lang.String DERBY_4215
private static final boolean TRJ_IGNORE_SOFT_UPGRADE
private static final boolean TRJ_SAME_BRANCH_NEIGHBORS
private static final java.lang.String SYSALIASES
private static final java.lang.String SYSCONGLOMERATES
private static final java.lang.String SYSSTATEMENTS
private static final java.lang.String SYSROUTINEPERMS
private static final java.lang.String CONGLOMERATENUMBER
private static final java.lang.String ALIAS
private static final java.lang.String ALIASID
private static final java.lang.String SPECIFICNAME
private static final java.lang.String STMTID
private static final java.lang.String STMTNAME
private static final java.lang.String TEXT
private static final java.lang.String ROUTINEPERMSID
private static final java.lang.String LASTCOMPILED
private static final boolean LOQUACIOUS
private Version.Trajectory _trajectory
private java.lang.String _trajectoryName
private boolean[] _hardUpgradeRequests
private java.util.HashMap<java.lang.String,java.lang.String> _unstableColumnValues
private static java.lang.ThreadLocal<java.lang.ClassLoader> _originalClassLoader
private static java.lang.String[] INITIAL_TABLES
public UpgradeTrajectoryTest(Version.Trajectory trajectory, boolean[] hardUpgradeRequests)
public static junit.framework.Test suite()
private static void addTrajectories(BaseTestSuite suite)
Add all of the trajectories we intend to test.
private static Version.Trajectory[] makeTrajectories()
Make all known upgrade trajectories. This amounts to every non-vacuous subset of the known versions.
private static boolean shouldBuildAllTrajectories()
Return true if we should build all trajectories.
private static Version.Trajectory[] makeSampleTrajectories()
Sample trajectory for debugging this program.
private static Version[] getSupportedVersions()
Get the supported versions.
private static void addHardUpgradeOnlyTrajectory(BaseTestSuite suite, Version.Trajectory trajectory)
Add only the test case which hard-upgrades along all edges of the Trajectory.
private static void addTrajectory(BaseTestSuite suite, Version.Trajectory trajectory)
Add a single trajectory to the suite, looping through all combinations of hard and softupgrade.
private static void addTrajectory(BaseTestSuite suite, Version.Trajectory trajectory, boolean[] hardUpgradeRequests, int idx)
private static boolean[] clone(boolean[] input)
private static void addTrajectory(BaseTestSuite suite, Version.Trajectory trajectory, boolean[] hardUpgradeRequests)
Add a single trajectory to the suite, with upgrade instructions.
public void testTrajectory() throws java.lang.Exception
Test a single trajectory.
java.lang.Exception
private void compareDatabases(Version version, java.lang.String leftDatabaseName, java.lang.String rightDatabaseName) throws java.lang.Exception
Compare the metadata in two databases.
java.lang.Exception
private java.util.ArrayList<java.lang.String> listSystemTables(java.sql.Connection conn) throws java.lang.Exception
Get the names of all the system tables in the database except for the list of initial tables.
java.lang.Exception
private void compareResults(java.sql.Connection leftConn, java.sql.Connection rightConn, java.sql.Connection comparisonConn, java.lang.String leftSchema, java.lang.String rightSchema, java.lang.String tableName, java.lang.String query) throws java.lang.Exception
Compare the results of a query in two databases.
java.lang.Exception
private int stuffTable(java.lang.String tableName, java.sql.ResultSet select, java.sql.PreparedStatement insert) throws java.lang.Exception
Copy metadata from a source table into a target table.
java.lang.Exception
private void leftJoin(java.sql.Connection conn, java.util.ArrayList columnNames, java.lang.String tableName, java.lang.String leftTableName, java.lang.String rightTableName) throws java.lang.Exception
Left join two tables and verify that the result is empty.
java.lang.Exception
private void createDatabase(Version version, java.lang.String logicalDatabaseName) throws java.lang.Exception
Create a database using the indicated version of Derby.
java.lang.Exception
private void upgradeDatabase(Version softwareVersion, Version dataVersion, boolean hardUpgrade, java.lang.String logicalDatabaseName) throws java.lang.Exception
Upgrade a database to the indicated version of Derby.
java.lang.Exception
private javax.sql.DataSource bootDatabase(java.lang.String logicalDatabaseName) throws java.lang.Exception
Boot a database.
java.lang.Exception
private javax.sql.DataSource upgradeDatabase(java.lang.String logicalDatabaseName, boolean hardUpgrade) throws java.lang.Exception
Hard-upgrade a database.
java.lang.Exception
private javax.sql.DataSource makeDataSource(java.lang.String logicalDatabaseName) throws java.lang.Exception
Make a DataSource given a logical database name.
java.lang.Exception
private void shutdownDatabase(javax.sql.DataSource ds)
Shutdown a database.
private void vetDBVersion(Version softwareVersion, Version dataVersion, java.sql.Connection conn) throws java.lang.Exception
Verify that the database has the expected version.
java.lang.Exception
private java.lang.String getDataVersion(java.sql.Connection conn) throws java.lang.Exception
Get the version of the data in the database.
java.lang.Exception
private java.lang.String trimDriverVersion(java.lang.String driverVersion)
Strip the trailing subversion stamp from a Derby version number.
private void saveOriginalClassLoader()
private void restoreOriginalClassLoader()
private java.lang.String stringifyUpgradeRequests()
protected void goodStatement(java.sql.Connection conn, java.lang.String ddl) throws java.sql.SQLException
goodStatement
in class BaseJDBCTestCase
java.sql.SQLException
protected java.sql.PreparedStatement chattyPrepare(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
chattyPrepare
in class BaseJDBCTestCase
java.sql.SQLException
private java.lang.String printResultSet(java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLException
private void normalizeRow(java.lang.String tableName, java.lang.String[] columnNames, java.lang.String[] row)
Replace values which are known to be unstable.
private boolean isColumn(java.lang.String expectedTableName, java.lang.String expectedColumnName, java.lang.String actualTableName, java.lang.String actualColumnName)
Return true if we are dealing with the indicated column.
private java.lang.String getColumnValue(java.lang.String columnName, java.lang.String[] columnNames, java.lang.String[] row)
Return the value for the indicated columns.
private boolean isUUID(java.lang.String raw)
Return true if the string looks like a UUID.
private void printQueryResults(java.sql.Connection conn, java.lang.String query) throws java.lang.Exception
Debug method to print out a result set.
java.lang.Exception
private void compareQueries(java.sql.Connection leftConn, java.sql.Connection rightConn, int colCount, java.lang.String query) throws java.lang.Exception
Debug method to compare the results of a query on two databases.
java.lang.Exception
private static Version.Trajectory[] buildMinimalSet(Version[] supportedVersions)
Builds the minimal set of trajectories for the supported versions. This is all trajectories which start at some release, then hard upgrade to every subsequent release up to the very last release. For a set of N releases, there are N-1 non-vacuous trajectories of this shape.
private static Version.Trajectory[] buildPowerSet(Version[] supportedVersions)
Build the power set of all supported versions.
private static Version.Trajectory[] squeezeArray(java.util.ArrayList<Version.Trajectory> trajectoryList)
Turn a list of trajectories into an array.
private static void buildPowerSetMinion(Version[] supportedVersions, java.util.ArrayList<Version.Trajectory> result, boolean[] include, int idx, boolean removeSameBranchNeighbors)
Recursive workhorse to build the power set of supported versions. If requested, we also prune out all trajectories which have adjacent versions from the same branch. If we're hard-upgrading, between releases, then these SHOULD be uninteresting combinations.
private static void addSubset(Version[] supportedVersions, java.util.ArrayList<Version.Trajectory> result, boolean[] include, boolean removeSameBranchNeighbors)
Add a subset to the evolving list of subsets of supported versions. Throw out the empty set and singletons. We sort each trajectory so that its versions are in ascending order.
private java.lang.String filterKnownProblems(java.lang.String tableName, java.lang.String actual)
Return empty string if passed in result is a known problem.
private boolean suffersDERBY_4215(java.lang.String tableName)
Return true if the conditions of DERBY-4215 exist.
private boolean suffersDERBY_4216(java.lang.String tableName)
Return true if the conditions of DERBY-4216 exist.
private boolean contains(java.lang.String left, java.lang.String right)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.