Permalink
Browse files

log possible SF leaks in test suite

  • Loading branch information...
1 parent 757c067 commit c26a3fd7327af28823b6cde1ece4f6af21066721 @sebersole sebersole committed Feb 10, 2014
@@ -165,4 +165,3 @@ task jaxb {
runSourceGenerators.dependsOn jaxb
runSourceGenerators.dependsOn generateGrammarSource
-
@@ -968,13 +968,6 @@ public void sessionFactoryClosed(SessionFactory factory) {
catch (Exception e) {
throw new AssertionFailure("Could not generate UUID");
}
- SessionFactoryRegistry.INSTANCE.addSessionFactory(
- uuid,
- name,
- settings.isSessionFactoryNameAlsoJndiName(),
- this,
- serviceRegistry.getService( JndiService.class )
- );
if ( debugEnabled ) {
LOG.debug("Instantiated session factory");
@@ -1058,6 +1051,14 @@ public void sessionFactoryClosed(SessionFactory factory) {
this.transactionEnvironment = new TransactionEnvironmentImpl( this );
this.observer.sessionFactoryCreated( this );
+
+ SessionFactoryRegistry.INSTANCE.addSessionFactory(
+ uuid,
+ name,
+ settings.isSessionFactoryNameAlsoJndiName(),
+ this,
+ serviceRegistry.getService( JndiService.class )
+ );
}
@SuppressWarnings( {"unchecked"} )
@@ -25,7 +25,6 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
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 (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n
#log4j.appender.stdout-mdc=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout-mdc.Target=System.out
@@ -56,4 +55,16 @@ log4j.logger.org.hibernate.loader.plan2.build.internal.LoadPlanImpl=debug
log4j.logger.org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter=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 @@
import org.hibernate.internal.SessionFactoryRegistry;
+import org.hibernate.testing.PossibleLeaksLogger;
import org.junit.runners.model.Statement;
import org.jboss.logging.Logger;
@@ -33,8 +34,6 @@
* @author Steve Ebersole
*/
public class AfterClassCallbackHandler extends Statement {
- private static final Logger log = Logger.getLogger( AfterClassCallbackHandler.class );
-
private final CustomRunner runner;
private final Statement wrappedStatement;
@@ -48,10 +47,11 @@ public void evaluate() throws Throwable {
wrappedStatement.evaluate();
runner.getTestClassMetadata().performAfterClassCallbacks( runner.getTestInstance() );
if ( SessionFactoryRegistry.INSTANCE.hasRegistrations() ) {
- log.warnf(
- "SessionFactory may be leaked during execution of test : %s",
+ PossibleLeaksLogger.logPossibleLeak(
+ "Possible SessionFactory leak",
runner.getTestClassMetadata().getTestClass().getName()
);
+ SessionFactoryRegistry.INSTANCE.clearRegistrations();
}
}
}
@@ -233,25 +233,6 @@ public int compare(FrameworkMethod o1, FrameworkMethod o2) {
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 determineDialect() {
@@ -377,6 +358,25 @@ private MatcherInstantiationException(Class<? extends Skip.Matcher> matcherClass
}
}
+ @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")
private class FailureExpectedWithNewMetamodelAdapter implements FailureExpected {
private final FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel;

0 comments on commit c26a3fd

Please sign in to comment.