HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (migrate HEM tests - first attempt)
This commit is contained in:
parent
2e1d1a6f16
commit
11fc090557
|
@ -10,13 +10,17 @@ import org.junit.rules.MethodRule;
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
import org.junit.runners.model.FrameworkMethod;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ClassLoadingIsolater implements MethodRule {
|
public class ClassLoadingIsolater implements MethodRule {
|
||||||
|
private static final Logger log = Logger.getLogger( ClassLoadingIsolater.class );
|
||||||
|
|
||||||
public static interface IsolatedClassLoaderProvider {
|
public static interface IsolatedClassLoaderProvider {
|
||||||
public ClassLoader buildIsolatedClassLoader();
|
ClassLoader buildIsolatedClassLoader();
|
||||||
public void releaseIsolatedClassLoader(ClassLoader isolatedClassLoader);
|
void releaseIsolatedClassLoader(ClassLoader isolatedClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IsolatedClassLoaderProvider provider;
|
private final IsolatedClassLoaderProvider provider;
|
||||||
|
@ -30,14 +34,20 @@ public class ClassLoadingIsolater implements MethodRule {
|
||||||
return new Statement() {
|
return new Statement() {
|
||||||
@Override
|
@Override
|
||||||
public void evaluate() throws Throwable {
|
public void evaluate() throws Throwable {
|
||||||
final ClassLoader isolatedClassLoader = provider.buildIsolatedClassLoader();
|
|
||||||
final ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader();
|
final ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader();
|
||||||
|
final ClassLoader isolatedClassLoader = provider.buildIsolatedClassLoader();
|
||||||
|
|
||||||
|
log.infof( "Overriding TCCL [%s] -> [%s]", originalTCCL, isolatedClassLoader );
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader( isolatedClassLoader );
|
Thread.currentThread().setContextClassLoader( isolatedClassLoader );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
base.evaluate();
|
base.evaluate();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
assert Thread.currentThread().getContextClassLoader() == isolatedClassLoader;
|
||||||
|
log.infof( "Reverting TCCL [%s] -> [%s]", isolatedClassLoader, originalTCCL );
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader( originalTCCL );
|
Thread.currentThread().setContextClassLoader( originalTCCL );
|
||||||
provider.releaseIsolatedClassLoader( isolatedClassLoader );
|
provider.releaseIsolatedClassLoader( isolatedClassLoader );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue