提交 bc8d4436 authored 作者: Thomas Mueller's avatar Thomas Mueller

Fixing the unit test.

上级 a9293c88
...@@ -28,8 +28,8 @@ import org.h2.util.Utils; ...@@ -28,8 +28,8 @@ import org.h2.util.Utils;
public class Engine implements SessionFactory { public class Engine implements SessionFactory {
private static final Engine INSTANCE = new Engine(); private static final Engine INSTANCE = new Engine();
private static final HashMap<String, Database> DATABASES = New.hashMap();
private final HashMap<String, Database> databases = New.hashMap();
private volatile long wrongPasswordDelay = SysProperties.DELAY_WRONG_PASSWORD_MIN; private volatile long wrongPasswordDelay = SysProperties.DELAY_WRONG_PASSWORD_MIN;
private boolean jmx; private boolean jmx;
...@@ -45,7 +45,7 @@ public class Engine implements SessionFactory { ...@@ -45,7 +45,7 @@ public class Engine implements SessionFactory {
if (openNew || ci.isUnnamedInMemory()) { if (openNew || ci.isUnnamedInMemory()) {
database = null; database = null;
} else { } else {
database = databases.get(name); database = DATABASES.get(name);
} }
User user = null; User user = null;
boolean opened = false; boolean opened = false;
...@@ -64,7 +64,7 @@ public class Engine implements SessionFactory { ...@@ -64,7 +64,7 @@ public class Engine implements SessionFactory {
database.setMasterUser(user); database.setMasterUser(user);
} }
if (!ci.isUnnamedInMemory()) { if (!ci.isUnnamedInMemory()) {
databases.put(name, database); DATABASES.put(name, database);
} }
} }
synchronized (database) { synchronized (database) {
...@@ -237,7 +237,7 @@ public class Engine implements SessionFactory { ...@@ -237,7 +237,7 @@ public class Engine implements SessionFactory {
throw DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1, e, "JMX"); throw DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1, e, "JMX");
} }
} }
databases.remove(name); DATABASES.remove(name);
} }
/** /**
......
...@@ -13,6 +13,7 @@ import java.util.ArrayList; ...@@ -13,6 +13,7 @@ import java.util.ArrayList;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.value.ValueInt;
/** /**
* Tests if Tomcat would clear static fields when re-loading a web application. * Tests if Tomcat would clear static fields when re-loading a web application.
...@@ -28,9 +29,7 @@ public class TestClearReferences extends TestBase { ...@@ -28,9 +29,7 @@ public class TestClearReferences extends TestBase {
"org.h2.util.StringUtils.softCache", "org.h2.util.StringUtils.softCache",
"org.h2.value.Value.softCache", "org.h2.value.Value.softCache",
"org.h2.jdbcx.JdbcDataSourceFactory.cachedTraceSystem", "org.h2.jdbcx.JdbcDataSourceFactory.cachedTraceSystem",
"org.h2.store.fs.FileObjectMemory.cachedCompressedEmptyBlock",
"org.h2.tools.CompressTool.cachedBuffer", "org.h2.tools.CompressTool.cachedBuffer",
"org.h2.util.MemoryUtils.reserveMemory",
"org.h2.util.NetUtils.cachedLocalAddress", "org.h2.util.NetUtils.cachedLocalAddress",
"org.h2.util.MathUtils.cachedSecureRandom", "org.h2.util.MathUtils.cachedSecureRandom",
"org.h2.value.CompareMode.lastUsed", "org.h2.value.CompareMode.lastUsed",
...@@ -48,18 +47,36 @@ public class TestClearReferences extends TestBase { ...@@ -48,18 +47,36 @@ public class TestClearReferences extends TestBase {
TestBase.createCaller().init().test(); TestBase.createCaller().init().test();
} }
public void test() throws Exception { private void clear() throws Exception {
// initialize the known classes
MathUtils.secureRandomLong();
ArrayList<Class <?>> classes = New.arrayList(); ArrayList<Class <?>> classes = New.arrayList();
check(classes, new File("bin/org/h2")); check(classes, new File("bin/org/h2"));
check(classes, new File("temp/org/h2"));
for (Class<?> clazz : classes) { for (Class<?> clazz : classes) {
clearClass(clazz); clearClass(clazz);
} }
}
public void test() throws Exception {
// initialize the known classes
MathUtils.secureRandomLong();
ValueInt.get(1);
Class.forName("org.h2.store.fs.FileObjectMemoryData");
clear();
if (hasError) { if (hasError) {
fail("Tomcat may clear the field above when reloading the web app"); fail("Tomcat may clear the field above when reloading the web app");
} }
for (String s : KNOWN_REFRESHED) {
String className = s.substring(0, s.lastIndexOf('.'));
String fieldName = s.substring(s.lastIndexOf('.') + 1);
Class<?> clazz = Class.forName(className);
try {
clazz.getDeclaredField(fieldName);
} catch (Exception e) {
fail(s);
}
}
} }
private void check(ArrayList<Class <?>> classes, File file) { private void check(ArrayList<Class <?>> classes, File file) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论