log possible SF leaks in test suite
This commit is contained in:
parent
757c067165
commit
c26a3fd732
|
@ -165,4 +165,3 @@ task jaxb {
|
||||||
|
|
||||||
runSourceGenerators.dependsOn jaxb
|
runSourceGenerators.dependsOn jaxb
|
||||||
runSourceGenerators.dependsOn generateGrammarSource
|
runSourceGenerators.dependsOn generateGrammarSource
|
||||||
|
|
||||||
|
|
|
@ -968,13 +968,6 @@ public final class SessionFactoryImpl
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new AssertionFailure("Could not generate UUID");
|
throw new AssertionFailure("Could not generate UUID");
|
||||||
}
|
}
|
||||||
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
|
||||||
uuid,
|
|
||||||
name,
|
|
||||||
settings.isSessionFactoryNameAlsoJndiName(),
|
|
||||||
this,
|
|
||||||
serviceRegistry.getService( JndiService.class )
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( debugEnabled ) {
|
if ( debugEnabled ) {
|
||||||
LOG.debug("Instantiated session factory");
|
LOG.debug("Instantiated session factory");
|
||||||
|
@ -1058,6 +1051,14 @@ public final class SessionFactoryImpl
|
||||||
|
|
||||||
this.transactionEnvironment = new TransactionEnvironmentImpl( this );
|
this.transactionEnvironment = new TransactionEnvironmentImpl( this );
|
||||||
this.observer.sessionFactoryCreated( this );
|
this.observer.sessionFactoryCreated( this );
|
||||||
|
|
||||||
|
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||||
|
uuid,
|
||||||
|
name,
|
||||||
|
settings.isSessionFactoryNameAlsoJndiName(),
|
||||||
|
this,
|
||||||
|
serviceRegistry.getService( JndiService.class )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"} )
|
@SuppressWarnings( {"unchecked"} )
|
||||||
|
|
|
@ -25,7 +25,6 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.stdout.Target=System.out
|
log4j.appender.stdout.Target=System.out
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||||
#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n
|
|
||||||
|
|
||||||
#log4j.appender.stdout-mdc=org.apache.log4j.ConsoleAppender
|
#log4j.appender.stdout-mdc=org.apache.log4j.ConsoleAppender
|
||||||
#log4j.appender.stdout-mdc.Target=System.out
|
#log4j.appender.stdout-mdc.Target=System.out
|
||||||
|
@ -57,3 +56,15 @@ log4j.logger.org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter=debug
|
||||||
log4j.logger.org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails=debug
|
log4j.logger.org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails=debug
|
||||||
|
|
||||||
log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=info
|
log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=info
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Used to direct certain log events (that indicate possible leaks from the test suite) to a file
|
||||||
|
|
||||||
|
log4j.appender.leak=org.apache.log4j.FileAppender
|
||||||
|
log4j.appender.leak.File=target/logs/test-leaks.txt
|
||||||
|
log4j.appender.leak.Append=false
|
||||||
|
log4j.appender.leak.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.leak.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||||
|
|
||||||
|
log4j.logger.org.hibernate.testing.PossibleLeaksLogger=warn,leak
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.testing;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Centralized logger (easier config) for logging possible test leaks
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class PossibleLeaksLogger {
|
||||||
|
private static final Logger log = Logger.getLogger( PossibleLeaksLogger.class );
|
||||||
|
|
||||||
|
public static void logPossibleLeak(String message, String test) {
|
||||||
|
log.warn( "POSSIBLE LEAK [" + test + "] : " + message );
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ package org.hibernate.testing.junit4;
|
||||||
|
|
||||||
import org.hibernate.internal.SessionFactoryRegistry;
|
import org.hibernate.internal.SessionFactoryRegistry;
|
||||||
|
|
||||||
|
import org.hibernate.testing.PossibleLeaksLogger;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
@ -33,8 +34,6 @@ import org.jboss.logging.Logger;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class AfterClassCallbackHandler extends Statement {
|
public class AfterClassCallbackHandler extends Statement {
|
||||||
private static final Logger log = Logger.getLogger( AfterClassCallbackHandler.class );
|
|
||||||
|
|
||||||
private final CustomRunner runner;
|
private final CustomRunner runner;
|
||||||
private final Statement wrappedStatement;
|
private final Statement wrappedStatement;
|
||||||
|
|
||||||
|
@ -48,10 +47,11 @@ public class AfterClassCallbackHandler extends Statement {
|
||||||
wrappedStatement.evaluate();
|
wrappedStatement.evaluate();
|
||||||
runner.getTestClassMetadata().performAfterClassCallbacks( runner.getTestInstance() );
|
runner.getTestClassMetadata().performAfterClassCallbacks( runner.getTestInstance() );
|
||||||
if ( SessionFactoryRegistry.INSTANCE.hasRegistrations() ) {
|
if ( SessionFactoryRegistry.INSTANCE.hasRegistrations() ) {
|
||||||
log.warnf(
|
PossibleLeaksLogger.logPossibleLeak(
|
||||||
"SessionFactory may be leaked during execution of test : %s",
|
"Possible SessionFactory leak",
|
||||||
runner.getTestClassMetadata().getTestClass().getName()
|
runner.getTestClassMetadata().getTestClass().getName()
|
||||||
);
|
);
|
||||||
|
SessionFactoryRegistry.INSTANCE.clearRegistrations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,25 +233,6 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( {"ClassExplicitlyAnnotation"})
|
|
||||||
public static class IgnoreImpl implements Ignore {
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
public IgnoreImpl(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String value() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Annotation> annotationType() {
|
|
||||||
return Ignore.class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dialect dialect = determineDialect();
|
private static Dialect dialect = determineDialect();
|
||||||
|
|
||||||
private static Dialect determineDialect() {
|
private static Dialect determineDialect() {
|
||||||
|
@ -377,6 +358,25 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"ClassExplicitlyAnnotation"})
|
||||||
|
public static class IgnoreImpl implements Ignore {
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
public IgnoreImpl(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String value() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> annotationType() {
|
||||||
|
return Ignore.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ClassExplicitlyAnnotation")
|
@SuppressWarnings("ClassExplicitlyAnnotation")
|
||||||
private class FailureExpectedWithNewMetamodelAdapter implements FailureExpected {
|
private class FailureExpectedWithNewMetamodelAdapter implements FailureExpected {
|
||||||
private final FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel;
|
private final FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel;
|
||||||
|
|
Loading…
Reference in New Issue