HHH-8127 OutOfMemoryError when running tests

This commit is contained in:
Strong Liu 2013-04-26 02:44:18 +08:00
parent ce08bdb7a8
commit fecde04472
10 changed files with 37 additions and 16 deletions

View File

@ -40,9 +40,9 @@ public class ErrorCounter implements ParseErrorHandler {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, ErrorCounter.class.getName()); private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, ErrorCounter.class.getName());
private List errorList = new ArrayList(); private List<String> errorList = new ArrayList<String>();
private List warningList = new ArrayList(); private List<String> warningList = new ArrayList<String>();
private List recognitionExceptions = new ArrayList(); private List<RecognitionException> recognitionExceptions = new ArrayList<RecognitionException>();
public void reportError(RecognitionException e) { public void reportError(RecognitionException e) {
reportError( e.toString() ); reportError( e.toString() );
@ -66,8 +66,8 @@ public class ErrorCounter implements ParseErrorHandler {
private String getErrorString() { private String getErrorString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
for ( Iterator iterator = errorList.iterator(); iterator.hasNext(); ) { for ( Iterator<String> iterator = errorList.iterator(); iterator.hasNext(); ) {
buf.append( ( String ) iterator.next() ); buf.append( iterator.next() );
if ( iterator.hasNext() ) buf.append( "\n" ); if ( iterator.hasNext() ) buf.append( "\n" );
} }
@ -76,7 +76,7 @@ public class ErrorCounter implements ParseErrorHandler {
public void throwQueryException() throws QueryException { public void throwQueryException() throws QueryException {
if ( getErrorCount() > 0 ) { if ( getErrorCount() > 0 ) {
if (recognitionExceptions.size() > 0) throw QuerySyntaxException.convert((RecognitionException)recognitionExceptions.get(0)); if (recognitionExceptions.size() > 0) throw QuerySyntaxException.convert(recognitionExceptions.get(0));
throw new QueryException(getErrorString()); throw new QueryException(getErrorString());
} }
LOG.debug("throwQueryException() : no errors"); LOG.debug("throwQueryException() : no errors");

View File

@ -32,7 +32,7 @@ import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo; import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
@ -88,7 +88,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
} }
); );
Dialect dialect = new H2Dialect(); Dialect dialect = TestingDatabaseInfo.DIALECT;
generator = new SequenceHiLoGenerator(); generator = new SequenceHiLoGenerator();
generator.configure( StandardBasicTypes.LONG, properties, dialect ); generator.configure( StandardBasicTypes.LONG, properties, dialect );

View File

@ -32,7 +32,7 @@ import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo; import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
@ -84,7 +84,7 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
} }
} ); } );
Dialect dialect = new H2Dialect(); Dialect dialect = TestingDatabaseInfo.DIALECT;
generator = new SequenceHiLoGenerator(); generator = new SequenceHiLoGenerator();
generator.configure( StandardBasicTypes.LONG, properties, dialect ); generator.configure( StandardBasicTypes.LONG, properties, dialect );

View File

@ -27,6 +27,7 @@ import org.junit.Test;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -55,7 +56,7 @@ public class ObjectNameTests extends BaseUnitTestCase {
@Test @Test
public void testIdentifierBuilding() { public void testIdentifierBuilding() {
Dialect dialect = new H2Dialect(); Dialect dialect = TestingDatabaseInfo.DIALECT;
ObjectName on = new ObjectName( "schema", "catalog", "name" ); ObjectName on = new ObjectName( "schema", "catalog", "name" );
assertEquals( "schema.catalog.name", on.toText() ); assertEquals( "schema.catalog.name", on.toText() );
on = new ObjectName( "schema", null, "name" ); on = new ObjectName( "schema", null, "name" );

View File

@ -29,6 +29,7 @@ import org.junit.Test;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -133,7 +134,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
@Test @Test
public void testQualifiedName() { public void testQualifiedName() {
Dialect dialect = new H2Dialect(); Dialect dialect = TestingDatabaseInfo.DIALECT;
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) ); Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) ); Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) );
assertEquals( "my_table", table.getTableName().getName() ); assertEquals( "my_table", table.getTableName().getName() );

View File

@ -59,6 +59,12 @@ public class BackquoteTest extends BaseUnitTestCase {
log.debug(writer.toString()); log.debug(writer.toString());
fail(e.getMessage()); fail(e.getMessage());
} }
finally {
if ( sessionFactory != null ) {
sessionFactory.close();
sessionFactory = null;
}
}
} }
/** /**
@ -87,6 +93,11 @@ public class BackquoteTest extends BaseUnitTestCase {
e.printStackTrace(new PrintWriter(writer)); e.printStackTrace(new PrintWriter(writer));
log.debug(writer.toString()); log.debug(writer.toString());
fail(e.getMessage()); fail(e.getMessage());
} } finally {
if(sessionFactory!=null){
sessionFactory.close();
sessionFactory = null;
}
}
} }
} }

View File

@ -5,6 +5,7 @@ import org.jboss.logging.Logger;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
@ -23,12 +24,13 @@ public class NullablePrimaryKeyTest {
public void testGeneratedSql() { public void testGeneratedSql() {
ServiceRegistry serviceRegistry = null; ServiceRegistry serviceRegistry = null;
SessionFactory sf = null;
try { try {
AnnotationConfiguration config = new AnnotationConfiguration(); AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Address.class);
config.addAnnotatedClass(Person.class); config.addAnnotatedClass(Person.class);
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
config.buildSessionFactory( serviceRegistry ); sf = config.buildSessionFactory( serviceRegistry );
String[] schema = config String[] schema = config
.generateSchemaCreationScript(new SQLServerDialect()); .generateSchemaCreationScript(new SQLServerDialect());
for (String s : schema) { for (String s : schema) {
@ -41,9 +43,13 @@ public class NullablePrimaryKeyTest {
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());
} }
finally { finally {
if ( sf != null ) {
sf.close();
}
if ( serviceRegistry != null ) { if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry ); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }
} }

View File

@ -30,8 +30,10 @@ public abstract class AbstractExecutable implements Executable {
} }
finally { finally {
factory.close(); factory.close();
factory = null;
if ( serviceRegistry != null ) { if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry ); ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = null;
} }
} }
} }

View File

@ -77,6 +77,6 @@ public class ConnectionProviderBuilder {
} }
public static Dialect getCorrespondingDialect() { public static Dialect getCorrespondingDialect() {
return new H2Dialect(); return TestingDatabaseInfo.DIALECT;
} }
} }

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate; package org.hibernate.testing.env;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;