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 dj...@apache.org on 2007/03/16 05:36:33 UTC
svn commit: r518863 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/upgradeTests/ junit/
Author: djd
Date: Thu Mar 15 21:36:25 2007
New Revision: 518863
URL: http://svn.apache.org/viewvc?view=rev&rev=518863
Log:
DERBY-2217 Add the test of trying to encrypt an upgrade non-encrypted database from the old
upgrade test to the new upgrade Junit based test.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
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/junit/JDBCDataSource.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java?view=diff&rev=518863&r1=518862&r2=518863
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java Thu Mar 15 21:36:25 2007
@@ -26,10 +26,13 @@
import java.sql.SQLException;
import java.sql.Statement;
+import javax.sql.DataSource;
+
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.JDBCDataSource;
/**
* Upgrade test cases for changes made in 10.2.
@@ -330,6 +333,62 @@
rs.close();
s.close();
+ break;
+ }
+ }
+
+ /**
+ * Run the change encryption test against a
+ * non-encrypted database.
+ *
+ * @throws SQLException
+ */
+ public void testChangeEncryptionFromNone() throws SQLException
+ {
+ changeEncryption("NO_ENCRYPT_10_2");
+ }
+
+
+ /**
+ * Test that changing the encryption is only allowed if
+ * the database has been hard-upgraded. This test can
+ * work against an existing encrypted or un-encrypted database.
+ * This test assumes it has its own single use database, which
+ * will not be booted by the general upgrade test setup.
+ * @throws SQLException
+ */
+ private void changeEncryption(String logicalDBName) throws SQLException
+ {
+ DataSource ds = JDBCDataSource.getDataSourceLogical(logicalDBName);
+
+ switch (getPhase())
+ {
+ case PH_CREATE:
+ // create the database if it was not already created.
+ JDBCDataSource.setBeanProperty(ds, "createDatabase", "create");
+ ds.getConnection().close();
+ break;
+ case PH_SOFT_UPGRADE:
+ JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+ "dataEncryption=true;bootPassword=xyz1234abc");
+
+ try {
+ ds.getConnection();
+ fail("open re-encrypted connection in soft upgrade");
+ } catch (SQLException e) {
+ assertSQLState("XJ040", e);
+ e = e.getNextException();
+ assertNotNull(e);
+ assertSQLState("XCL47", e);
+ }
+ break;
+
+
+ case PH_POST_SOFT_UPGRADE:
+ case PH_HARD_UPGRADE:
+ // Should be able to successfully connect to it
+ // using the old setup.
+ ds.getConnection().close();
break;
}
}
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?view=diff&rev=518863&r1=518862&r2=518863
==============================================================================
--- 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 Thu Mar 15 21:36:25 2007
@@ -29,6 +29,7 @@
import junit.framework.Test;
import org.apache.derbyTesting.junit.JDBCDataSource;
+import org.apache.derbyTesting.junit.TestConfiguration;
/**
* Decorator that sets the phase of the upgrade process
@@ -89,20 +90,13 @@
break;
}
- try {
- ds.getConnection().close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- do {
- e.printStackTrace();
- e = e.getNextException();
- } while (e != null);
- //throw e;
- }
+ // Ensure the database exists or upgrade it.
+ ds.getConnection().close();
+
}
/**
- * Shutdown the database and reset the class loader.
+ * Shutdown the database(s) and reset the class loader.
* @throws InterruptedException
*/
protected void tearDown() throws InterruptedException
@@ -110,6 +104,25 @@
if (phase != UpgradeChange.PH_POST_HARD_UPGRADE) {
DataSource ds = JDBCDataSource.getDataSource();
JDBCDataSource.shutdownDatabase(ds);
+
+ for (int i = 0; i < UpgradeRun.ADDITIONAL_DBS.length; i++)
+ {
+ ds = JDBCDataSource.getDataSourceLogical(
+ UpgradeRun.ADDITIONAL_DBS[i]);
+
+ boolean shutdown = true;
+ try {
+ ds.getConnection().close();
+ } catch (SQLException e) {
+ // if the database was never created
+ // don't bother shutting it down.
+ if ("XJ004".equals(e.getSQLState()))
+ shutdown = false;
+ }
+
+ if (shutdown)
+ 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?view=diff&rev=518863&r1=518862&r2=518863
==============================================================================
--- 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 Thu Mar 15 21:36:25 2007
@@ -55,6 +55,18 @@
//"derbytools.jar"
};
+
+ /**
+ * Set of additional databases for tests that
+ * require a one-off database. The additional
+ * database decorator wraps all the tests and phases.
+ * They are only created if a test opens a
+ * connection against them.
+ */
+ static final String[] ADDITIONAL_DBS = {
+ "NO_ENCRYPT_10_2"
+ };
+
private static String getTextVersion(int[] iv)
{
String version = iv[0] + "." + iv[1] +
@@ -115,6 +127,12 @@
}
TestSetup setup = TestConfiguration.singleUseDatabaseDecorator(suite);
+
+ for (int i = 0; i < ADDITIONAL_DBS.length; i++)
+ {
+ setup = TestConfiguration.additionalDatabaseDecorator(setup,
+ ADDITIONAL_DBS[i]);
+ }
Properties preReleaseUpgrade = new Properties();
preReleaseUpgrade.setProperty(
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=518863&r1=518862&r2=518863
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Thu Mar 15 21:36:25 2007
@@ -59,6 +59,26 @@
}
/**
+ * Return a DataSource corresponding to one
+ * of the logical databases in the current configuration.
+ */
+ public static javax.sql.DataSource
+ getDataSourceLogical(String logicalDatabasename)
+ {
+ // default DataSource
+ javax.sql.DataSource ds = getDataSource();
+
+ TestConfiguration current = TestConfiguration.getCurrent();
+ String physicalName =
+ current.getPhysicalDatabaseName(logicalDatabasename);
+
+ // Override the database name
+ setBeanProperty(ds, "databaseName", physicalName);
+
+ return ds;
+ }
+
+ /**
* Create a new DataSource object setup from the passed in TestConfiguration.
* The getConnection() method will return a connection identical to
* TestConfiguration.openDefaultConnection().
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=518863&r1=518862&r2=518863
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Thu Mar 15 21:36:25 2007
@@ -914,7 +914,7 @@
*/
Connection openConnection(String logicalDatabaseName)
throws SQLException {
- String databaseName = (String) logicalDbMapping.get(logicalDatabaseName);
+ String databaseName = getPhysicalDatabaseName(logicalDatabaseName);
if (usedDbNames.contains(databaseName))
return connector.openConnection(databaseName);
else