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 List errorList = new ArrayList();
private List warningList = new ArrayList();
private List recognitionExceptions = new ArrayList();
private List<String> errorList = new ArrayList<String>();
private List<String> warningList = new ArrayList<String>();
private List<RecognitionException> recognitionExceptions = new ArrayList<RecognitionException>();
public void reportError(RecognitionException e) {
reportError( e.toString() );
@ -66,8 +66,8 @@ public class ErrorCounter implements ParseErrorHandler {
private String getErrorString() {
StringBuilder buf = new StringBuilder();
for ( Iterator iterator = errorList.iterator(); iterator.hasNext(); ) {
buf.append( ( String ) iterator.next() );
for ( Iterator<String> iterator = errorList.iterator(); iterator.hasNext(); ) {
buf.append( iterator.next() );
if ( iterator.hasNext() ) buf.append( "\n" );
}
@ -76,7 +76,7 @@ public class ErrorCounter implements ParseErrorHandler {
public void throwQueryException() throws QueryException {
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());
}
LOG.debug("throwQueryException() : no errors");

View File

@ -32,7 +32,7 @@ import java.sql.SQLException;
import java.util.Properties;
import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
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.configure( StandardBasicTypes.LONG, properties, dialect );

View File

@ -32,7 +32,7 @@ import java.sql.SQLException;
import java.util.Properties;
import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
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.configure( StandardBasicTypes.LONG, properties, dialect );

View File

@ -27,6 +27,7 @@ import org.junit.Test;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
@ -55,7 +56,7 @@ public class ObjectNameTests extends BaseUnitTestCase {
@Test
public void testIdentifierBuilding() {
Dialect dialect = new H2Dialect();
Dialect dialect = TestingDatabaseInfo.DIALECT;
ObjectName on = new ObjectName( "schema", "catalog", "name" );
assertEquals( "schema.catalog.name", on.toText() );
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.H2Dialect;
import org.hibernate.testing.env.TestingDatabaseInfo;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
@ -133,7 +134,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
@Test
public void testQualifiedName() {
Dialect dialect = new H2Dialect();
Dialect dialect = TestingDatabaseInfo.DIALECT;
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) );
assertEquals( "my_table", table.getTableName().getName() );

View File

@ -59,6 +59,12 @@ public class BackquoteTest extends BaseUnitTestCase {
log.debug(writer.toString());
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));
log.debug(writer.toString());
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.Test;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServerDialect;
@ -23,12 +24,13 @@ public class NullablePrimaryKeyTest {
public void testGeneratedSql() {
ServiceRegistry serviceRegistry = null;
SessionFactory sf = null;
try {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Address.class);
config.addAnnotatedClass(Person.class);
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
config.buildSessionFactory( serviceRegistry );
sf = config.buildSessionFactory( serviceRegistry );
String[] schema = config
.generateSchemaCreationScript(new SQLServerDialect());
for (String s : schema) {
@ -41,9 +43,13 @@ public class NullablePrimaryKeyTest {
Assert.fail(e.getMessage());
}
finally {
if ( sf != null ) {
sf.close();
}
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
}
}

View File

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

View File

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

View File

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