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 ka...@apache.org on 2011/07/12 13:36:20 UTC
svn commit: r1145552 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests:
PhaseChanger.java UpgradeRun.java
Author: kahatlen
Date: Tue Jul 12 11:36:19 2011
New Revision: 1145552
URL: http://svn.apache.org/viewvc?rev=1145552&view=rev
Log:
DERBY-5316: Unload old JDBC drivers when done with them in the upgrade tests
Clear a ThreadLocal in TableDescriptor after shutting down 10.5 and
10.6 engines. This works around DERBY-4895 which prevents the engine
classes from being garbage collected in those versions.
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
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=1145552&r1=1145551&r2=1145552&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 Tue Jul 12 11:36:19 2011
@@ -20,6 +20,7 @@ limitations under the License.
*/
package org.apache.derbyTesting.functionTests.tests.upgradeTests;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.SQLException;
@@ -135,6 +136,12 @@ final class PhaseChanger extends BaseTes
deregisterDriver();
}
+ // Workaround for DERBY-4895, which prevented the engine classes from
+ // being garbage collected.
+ if (phase == UpgradeChange.PH_POST_HARD_UPGRADE) {
+ clearDerby4895ThreadLocal();
+ }
+
if (loader != null)
UpgradeClassLoader.setThreadLoader(previousLoader);
loader = null;
@@ -158,4 +165,30 @@ final class PhaseChanger extends BaseTes
Method m = unloader.getMethod("unload", (Class[]) null);
m.invoke(null, (Object[]) null);
}
+
+ /**
+ * Clear a static ThreadLocal field in TableDescriptor so that the engine
+ * classes can be garbage collected when they are no longer used. This is
+ * a workaround for DERBY-4895, which affects Derby 10.5 and 10.6.
+ */
+ private void clearDerby4895ThreadLocal() throws Exception {
+ boolean isAffectedVersion =
+ (UpgradeRun.lessThan(new int[] {10,5,0,0}, version) &&
+ UpgradeRun.lessThan(version, new int[] {10,5,3,2}))
+ ||
+ (UpgradeRun.lessThan(new int[] {10,6,0,0}, version) &&
+ UpgradeRun.lessThan(version, new int[] {10,6,2,3}));
+
+ if (!isAffectedVersion) {
+ // Nothing to work around in this version.
+ return;
+ }
+
+ Class td = Class.forName(
+ "org.apache.derby.iapi.sql.dictionary.TableDescriptor",
+ true, loader);
+ Field f = td.getDeclaredField("referencedColumnMap");
+ f.setAccessible(true);
+ f.set(null, null);
+ }
}
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=1145552&r1=1145551&r2=1145552&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 Tue Jul 12 11:36:19 2011
@@ -245,7 +245,7 @@ class UpgradeRun extends UpgradeClassLoa
* Return true if and only if the left version is less than the
* right version.
*/
- private static boolean lessThan( int[] left, int[] right )
+ static boolean lessThan( int[] left, int[] right )
{
for (int i = 0; i < left.length; i++)
{