HHH-4569 - Split focus of ConfigurationPerformanceTest
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17964 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
655be65063
commit
d558dac5dc
|
@ -424,70 +424,85 @@ public class Configuration implements Serializable {
|
||||||
* the non-cached file.
|
* the non-cached file.
|
||||||
*/
|
*/
|
||||||
public Configuration addCacheableFile(File xmlFile) throws MappingException {
|
public Configuration addCacheableFile(File xmlFile) throws MappingException {
|
||||||
|
File cachedFile = determineCachedDomFile( xmlFile );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File cachedFile = new File( xmlFile.getAbsolutePath() + ".bin" );
|
return addCacheableFileStrictly( xmlFile );
|
||||||
org.dom4j.Document doc = null;
|
}
|
||||||
|
catch ( SerializationException e ) {
|
||||||
|
log.warn( "Could not deserialize cache file: " + cachedFile.getPath() + " : " + e );
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e ) {
|
||||||
|
log.warn( "I/O reported cached file could not be found : " + cachedFile.getPath() + " : " + e );
|
||||||
|
}
|
||||||
|
|
||||||
final boolean useCachedFile = xmlFile.exists() &&
|
if ( !xmlFile.exists() ) {
|
||||||
cachedFile.exists() &&
|
throw new MappingNotFoundException( "file", xmlFile.toString() );
|
||||||
xmlFile.lastModified() < cachedFile.lastModified();
|
}
|
||||||
|
|
||||||
if ( useCachedFile ) {
|
log.info( "Reading mappings from file: " + xmlFile );
|
||||||
try {
|
List errors = new ArrayList();
|
||||||
log.info( "Reading mappings from cache file: " + cachedFile );
|
try {
|
||||||
doc = ( org.dom4j.Document ) SerializationHelper.deserialize( new FileInputStream( cachedFile ) );
|
org.dom4j.Document doc = xmlHelper.createSAXReader( xmlFile.getAbsolutePath(), errors, entityResolver ).read( xmlFile );
|
||||||
}
|
if ( errors.size() != 0 ) {
|
||||||
catch ( SerializationException e ) {
|
throw new MappingException( "invalid mapping", ( Throwable ) errors.get( 0 ) );
|
||||||
log.warn( "Could not deserialize cache file: " + cachedFile.getPath(), e );
|
|
||||||
}
|
|
||||||
catch ( FileNotFoundException e ) {
|
|
||||||
log.warn( "I/O reported cached file could not be found : " + cachedFile.getPath(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if doc is null, then for whatever reason, the cached file cannot be used...
|
try {
|
||||||
if ( doc == null ) {
|
log.debug( "Writing cache file for: " + xmlFile + " to: " + cachedFile );
|
||||||
if ( !xmlFile.exists() ) {
|
SerializationHelper.serialize( ( Serializable ) doc, new FileOutputStream( cachedFile ) );
|
||||||
throw new MappingNotFoundException( "file", xmlFile.toString() );
|
}
|
||||||
}
|
catch ( SerializationException e ) {
|
||||||
|
log.warn( "Could not write cached file: " + cachedFile, e );
|
||||||
log.info( "Reading mappings from file: " + xmlFile );
|
}
|
||||||
List errors = new ArrayList();
|
catch ( FileNotFoundException e ) {
|
||||||
try {
|
log.warn( "I/O reported error writing cached file : " + cachedFile.getPath(), e );
|
||||||
doc = xmlHelper.createSAXReader( xmlFile.getAbsolutePath(), errors, entityResolver ).read( xmlFile );
|
|
||||||
if ( errors.size() != 0 ) {
|
|
||||||
throw new MappingException( "invalid mapping", ( Throwable ) errors.get( 0 ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( DocumentException e){
|
|
||||||
throw new MappingException( "invalid mapping", e );
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
log.debug( "Writing cache file for: " + xmlFile + " to: " + cachedFile );
|
|
||||||
SerializationHelper.serialize( ( Serializable ) doc, new FileOutputStream( cachedFile ) );
|
|
||||||
}
|
|
||||||
catch ( SerializationException e ) {
|
|
||||||
log.warn( "Could not write cached file: " + cachedFile, e );
|
|
||||||
}
|
|
||||||
catch ( FileNotFoundException e ) {
|
|
||||||
log.warn( "I/O reported error writing cached file : " + cachedFile.getPath(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add( doc );
|
add( doc );
|
||||||
return this;
|
}
|
||||||
|
catch( DocumentException e){
|
||||||
|
throw new MappingException( "invalid mapping", e );
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private File determineCachedDomFile(File xmlFile) {
|
||||||
|
return new File( xmlFile.getAbsolutePath() + ".bin" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>INTENDED FOR TESTSUITE USE ONLY!</b>
|
||||||
|
* <p/>
|
||||||
|
* Much like {@link addCacheableFile(File)} except that here we will fail immediately if
|
||||||
|
* the cache version cannot be found or used for whatever reason
|
||||||
|
*
|
||||||
|
* @param xmlFile The xml file, not the bin!
|
||||||
|
*
|
||||||
|
* @return The dom "deserialized" from the cached file.
|
||||||
|
*
|
||||||
|
* @throws MappingException Indicates a problem in the underlyiong call to {@link #add(org.dom4j.Document)}
|
||||||
|
* @throws SerializationException Indicates a problem deserializing the cached dom tree
|
||||||
|
* @throws FileNotFoundException Indicates that the cached file was not found or was not usable.
|
||||||
|
*/
|
||||||
|
public Configuration addCacheableFileStrictly(File xmlFile)
|
||||||
|
throws MappingException, SerializationException, FileNotFoundException {
|
||||||
|
final File cachedFile = determineCachedDomFile( xmlFile );
|
||||||
|
|
||||||
|
final boolean useCachedFile = xmlFile.exists()
|
||||||
|
&& cachedFile.exists()
|
||||||
|
&& xmlFile.lastModified() < cachedFile.lastModified();
|
||||||
|
|
||||||
|
if ( ! useCachedFile ) {
|
||||||
|
throw new FileNotFoundException( "Cached file could not be found or could not be used" );
|
||||||
}
|
}
|
||||||
catch ( InvalidMappingException e ) {
|
|
||||||
throw e;
|
log.info( "Reading mappings from cache file: " + cachedFile );
|
||||||
}
|
org.dom4j.Document document =
|
||||||
catch ( MappingNotFoundException e ) {
|
( org.dom4j.Document ) SerializationHelper.deserialize( new FileInputStream( cachedFile ) );
|
||||||
throw e;
|
add( document );
|
||||||
}
|
return this;
|
||||||
catch ( Exception e ) {
|
|
||||||
throw new InvalidMappingException( "file", xmlFile.toString(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,20 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
|
||||||
|
*
|
||||||
|
* 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.test.cfg;
|
package org.hibernate.test.cfg;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.junit.UnitTestCase;
|
import org.hibernate.junit.UnitTestCase;
|
||||||
|
import org.hibernate.util.SerializationHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Tests using of cacheable configuration files.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class CacheableFileTest extends UnitTestCase {
|
public class CacheableFileTest extends UnitTestCase {
|
||||||
|
|
||||||
public static final String MAPPING = "org/hibernate/test/cfg/Cacheable.hbm.xml";
|
public static final String MAPPING = "org/hibernate/test/cfg/Cacheable.hbm.xml";
|
||||||
|
|
||||||
private File mappingFile;
|
private File mappingFile;
|
||||||
|
private File mappingBinFile;
|
||||||
|
|
||||||
public CacheableFileTest(String string) {
|
public CacheableFileTest(String string) {
|
||||||
super( string );
|
super( string );
|
||||||
|
@ -24,21 +48,31 @@ public class CacheableFileTest extends UnitTestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mappingFile = new File( getClass().getClassLoader().getResource( MAPPING ).toURI() );
|
mappingFile = new File( getClass().getClassLoader().getResource( MAPPING ).toURI() );
|
||||||
assertTrue( mappingFile.exists() );
|
assertTrue( mappingFile.exists() );
|
||||||
File cached = new File( mappingFile.getParentFile(), mappingFile.getName() + ".bin" );
|
mappingBinFile = new File( mappingFile.getParentFile(), mappingFile.getName() + ".bin" );
|
||||||
if ( cached.exists() ) {
|
if ( mappingBinFile.exists() ) {
|
||||||
cached.delete();
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
mappingBinFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
|
if ( mappingBinFile != null && mappingBinFile.exists() ) {
|
||||||
|
// be nice
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
mappingBinFile.delete();
|
||||||
|
}
|
||||||
|
mappingBinFile = null;
|
||||||
mappingFile = null;
|
mappingFile = null;
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCachedFiles() {
|
public void testCachedFiles() throws Exception {
|
||||||
Configuration cfg = new Configuration();
|
assertFalse( mappingBinFile.exists() );
|
||||||
cfg.addCacheableFile( mappingFile );
|
// This call should create the cached file
|
||||||
Configuration cfg2 = new Configuration();
|
new Configuration().addCacheableFile( mappingFile );
|
||||||
cfg2.addCacheableFile( mappingFile );
|
assertTrue( mappingBinFile.exists() );
|
||||||
|
|
||||||
|
Configuration cfg = new Configuration().addCacheableFileStrictly( mappingFile );
|
||||||
|
SerializationHelper.clone( cfg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
|
||||||
|
* third-party contributors as indicated by either @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.test.cfg;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.hibernate.junit.UnitTestCase;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.util.SerializationHelper;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copied over mostly from ConfigurationPerformanceTest
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
* @author Max Andersen
|
||||||
|
*/
|
||||||
|
public class ConfigurationSerializationTest extends UnitTestCase {
|
||||||
|
public ConfigurationSerializationTest(String string) {
|
||||||
|
super( string );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite( ConfigurationSerializationTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String[] FILES = new String[] {
|
||||||
|
"legacy/ABC.hbm.xml",
|
||||||
|
"legacy/ABCExtends.hbm.xml",
|
||||||
|
"legacy/Baz.hbm.xml",
|
||||||
|
"legacy/Blobber.hbm.xml",
|
||||||
|
"legacy/Broken.hbm.xml",
|
||||||
|
"legacy/Category.hbm.xml",
|
||||||
|
"legacy/Circular.hbm.xml",
|
||||||
|
"legacy/Commento.hbm.xml",
|
||||||
|
"legacy/ComponentNotNullMaster.hbm.xml",
|
||||||
|
"legacy/Componentizable.hbm.xml",
|
||||||
|
"legacy/Container.hbm.xml",
|
||||||
|
"legacy/Custom.hbm.xml",
|
||||||
|
"legacy/CustomSQL.hbm.xml",
|
||||||
|
"legacy/Eye.hbm.xml",
|
||||||
|
"legacy/Fee.hbm.xml",
|
||||||
|
"legacy/Fo.hbm.xml",
|
||||||
|
"legacy/FooBar.hbm.xml",
|
||||||
|
"legacy/Fum.hbm.xml",
|
||||||
|
"legacy/Fumm.hbm.xml",
|
||||||
|
"legacy/Glarch.hbm.xml",
|
||||||
|
"legacy/Holder.hbm.xml",
|
||||||
|
"legacy/IJ2.hbm.xml",
|
||||||
|
"legacy/Immutable.hbm.xml",
|
||||||
|
"legacy/Location.hbm.xml",
|
||||||
|
"legacy/Many.hbm.xml",
|
||||||
|
"legacy/Map.hbm.xml",
|
||||||
|
"legacy/Marelo.hbm.xml",
|
||||||
|
"legacy/MasterDetail.hbm.xml",
|
||||||
|
"legacy/Middle.hbm.xml",
|
||||||
|
"legacy/Multi.hbm.xml",
|
||||||
|
"legacy/MultiExtends.hbm.xml",
|
||||||
|
"legacy/Nameable.hbm.xml",
|
||||||
|
"legacy/One.hbm.xml",
|
||||||
|
"legacy/ParentChild.hbm.xml",
|
||||||
|
"legacy/Qux.hbm.xml",
|
||||||
|
"legacy/Simple.hbm.xml",
|
||||||
|
"legacy/SingleSeveral.hbm.xml",
|
||||||
|
"legacy/Stuff.hbm.xml",
|
||||||
|
"legacy/UpDown.hbm.xml",
|
||||||
|
"legacy/Vetoer.hbm.xml",
|
||||||
|
"legacy/WZ.hbm.xml",
|
||||||
|
};
|
||||||
|
|
||||||
|
public void testConfiguraionSerializability() {
|
||||||
|
Configuration cfg = new Configuration();
|
||||||
|
for ( String file : FILES ) {
|
||||||
|
cfg.addResource( "org/hibernate/test/" + file );
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = SerializationHelper.serialize( cfg );
|
||||||
|
cfg = ( Configuration ) SerializationHelper.deserialize( bytes );
|
||||||
|
|
||||||
|
// try to build SF
|
||||||
|
SessionFactory factory = cfg.buildSessionFactory();
|
||||||
|
factory.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
|
||||||
|
*
|
||||||
|
* 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.test.cfg;
|
package org.hibernate.test.cfg;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -1,29 +1,33 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
* 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
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
* Lesser General Public License, v. 2.1. This program is distributed in the
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
* hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
|
|
||||||
* distribution; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
*
|
||||||
* Red Hat Author(s): Max Andersen, Steve Ebersole
|
* 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.test.cfg;
|
package org.hibernate.test.perf;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
@ -46,12 +50,10 @@ public class ConfigurationPerformanceTest extends UnitTestCase {
|
||||||
|
|
||||||
private final String workPackageName = "org.hibernate.test.cfg.work";
|
private final String workPackageName = "org.hibernate.test.cfg.work";
|
||||||
private File compilationBaseDir;
|
private File compilationBaseDir;
|
||||||
private File mappingBaseDir;
|
|
||||||
private File workPackageDir;
|
private File workPackageDir;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
compilationBaseDir = getTestComplileDirectory();
|
compilationBaseDir = getTestComplileDirectory();
|
||||||
mappingBaseDir = new File( compilationBaseDir, "org/hibernate/test" );
|
|
||||||
workPackageDir = new File( compilationBaseDir, workPackageName.replace( '.', '/' ) );
|
workPackageDir = new File( compilationBaseDir, workPackageName.replace( '.', '/' ) );
|
||||||
if ( workPackageDir.exists() ) {
|
if ( workPackageDir.exists() ) {
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
@ -67,50 +69,6 @@ public class ConfigurationPerformanceTest extends UnitTestCase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] FILES = new String[] {
|
|
||||||
"legacy/ABC.hbm.xml",
|
|
||||||
"legacy/ABCExtends.hbm.xml",
|
|
||||||
"legacy/Baz.hbm.xml",
|
|
||||||
"legacy/Blobber.hbm.xml",
|
|
||||||
"legacy/Broken.hbm.xml",
|
|
||||||
"legacy/Category.hbm.xml",
|
|
||||||
"legacy/Circular.hbm.xml",
|
|
||||||
"legacy/Commento.hbm.xml",
|
|
||||||
"legacy/ComponentNotNullMaster.hbm.xml",
|
|
||||||
"legacy/Componentizable.hbm.xml",
|
|
||||||
"legacy/Container.hbm.xml",
|
|
||||||
"legacy/Custom.hbm.xml",
|
|
||||||
"legacy/CustomSQL.hbm.xml",
|
|
||||||
"legacy/Eye.hbm.xml",
|
|
||||||
"legacy/Fee.hbm.xml",
|
|
||||||
"legacy/Fo.hbm.xml",
|
|
||||||
"legacy/FooBar.hbm.xml",
|
|
||||||
"legacy/Fum.hbm.xml",
|
|
||||||
"legacy/Fumm.hbm.xml",
|
|
||||||
"legacy/Glarch.hbm.xml",
|
|
||||||
"legacy/Holder.hbm.xml",
|
|
||||||
"legacy/IJ2.hbm.xml",
|
|
||||||
"legacy/Immutable.hbm.xml",
|
|
||||||
"legacy/Location.hbm.xml",
|
|
||||||
"legacy/Many.hbm.xml",
|
|
||||||
"legacy/Map.hbm.xml",
|
|
||||||
"legacy/Marelo.hbm.xml",
|
|
||||||
"legacy/MasterDetail.hbm.xml",
|
|
||||||
"legacy/Middle.hbm.xml",
|
|
||||||
"legacy/Multi.hbm.xml",
|
|
||||||
"legacy/MultiExtends.hbm.xml",
|
|
||||||
"legacy/Nameable.hbm.xml",
|
|
||||||
"legacy/One.hbm.xml",
|
|
||||||
"legacy/ParentChild.hbm.xml",
|
|
||||||
"legacy/Qux.hbm.xml",
|
|
||||||
"legacy/Simple.hbm.xml",
|
|
||||||
"legacy/SingleSeveral.hbm.xml",
|
|
||||||
"legacy/Stuff.hbm.xml",
|
|
||||||
"legacy/UpDown.hbm.xml",
|
|
||||||
"legacy/Vetoer.hbm.xml",
|
|
||||||
"legacy/WZ.hbm.xml",
|
|
||||||
};
|
|
||||||
|
|
||||||
public ConfigurationPerformanceTest(String string) {
|
public ConfigurationPerformanceTest(String string) {
|
||||||
super( string );
|
super( string );
|
||||||
}
|
}
|
||||||
|
@ -123,33 +81,6 @@ public class ConfigurationPerformanceTest extends UnitTestCase {
|
||||||
TestRunner.run( suite() );
|
TestRunner.run( suite() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadingAndSerializationOfConfiguration() throws Throwable {
|
|
||||||
final File cachedCfgFile = new File( workPackageDir, "hibernate.cfg.bin" );
|
|
||||||
try {
|
|
||||||
System.err.println( "#### Preparing serialized configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
|
|
||||||
prepareSerializedConfiguration( mappingBaseDir, FILES, cachedCfgFile );
|
|
||||||
System.err.println( "#### Preparing serialized configuration complete ~~~~~~~~~~~~~~~~~~~~~~~~" );
|
|
||||||
|
|
||||||
// now make sure we can reload the serialized configuration...
|
|
||||||
System.err.println( "#### Reading serialized configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
|
|
||||||
readSerializedConfiguration( cachedCfgFile );
|
|
||||||
System.err.println( "#### Reading serialized configuration complete ~~~~~~~~~~~~~~~~~~~~~~~~~~" );
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
System.err.println( "###CLEANING UP###" );
|
|
||||||
if ( ! cachedCfgFile.delete() ) {
|
|
||||||
System.err.println( "Unable to cleanup file " + cachedCfgFile.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
//noinspection ForLoopReplaceableByForEach
|
|
||||||
for ( int i = 0; i < FILES.length; i++ ) {
|
|
||||||
File file = new File( mappingBaseDir, FILES[i] + ".bin" );
|
|
||||||
if ( ! file.delete() ) {
|
|
||||||
System.err.println( "Unable to cleanup file " + file.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSessionFactoryCreationTime() throws Throwable {
|
public void testSessionFactoryCreationTime() throws Throwable {
|
||||||
generateTestFiles();
|
generateTestFiles();
|
||||||
if ( !workPackageDir.exists() ) {
|
if ( !workPackageDir.exists() ) {
|
||||||
|
@ -198,20 +129,6 @@ public class ConfigurationPerformanceTest extends UnitTestCase {
|
||||||
System.err.println( "Subsequent SessionFactory load time : " + subsequent );
|
System.err.println( "Subsequent SessionFactory load time : " + subsequent );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareSerializedConfiguration(
|
|
||||||
File mappingFileBase,
|
|
||||||
String[] files,
|
|
||||||
File cachedCfgFile) throws IOException {
|
|
||||||
Configuration cfg = buildConfigurationFromCacheableFiles( mappingFileBase, files );
|
|
||||||
|
|
||||||
ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream( cachedCfgFile ) );
|
|
||||||
os.writeObject( cfg ); // need to serialize Configuration *before* building sf since it would require non-mappings and cfg types to be serializable
|
|
||||||
os.flush();
|
|
||||||
os.close();
|
|
||||||
|
|
||||||
timeBuildingSessionFactory( cfg );
|
|
||||||
}
|
|
||||||
|
|
||||||
private Configuration buildConfigurationFromCacheableFiles(File mappingFileBase, String[] files) {
|
private Configuration buildConfigurationFromCacheableFiles(File mappingFileBase, String[] files) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
|
@ -232,27 +149,6 @@ public class ConfigurationPerformanceTest extends UnitTestCase {
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timeBuildingSessionFactory(Configuration configuration) {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
System.err.println( "Start build of session factory" );
|
|
||||||
SessionFactory factory = configuration.buildSessionFactory();
|
|
||||||
System.err.println( "Built session factory :" + ( System.currentTimeMillis() - start ) / 1000.0 + " sec." );
|
|
||||||
factory.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readSerializedConfiguration(File cachedCfgFile) throws ClassNotFoundException, IOException {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
ObjectInputStream is = new ObjectInputStream( new FileInputStream( cachedCfgFile ) );
|
|
||||||
Configuration cfg = ( Configuration ) is.readObject();
|
|
||||||
is.close();
|
|
||||||
System.err.println(
|
|
||||||
"Loaded serializable configuration :" +
|
|
||||||
( System.currentTimeMillis() - start ) / 1000.0 + " sec."
|
|
||||||
);
|
|
||||||
|
|
||||||
timeBuildingSessionFactory( cfg );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generateTestFiles() throws Throwable {
|
public void generateTestFiles() throws Throwable {
|
||||||
String filesToCompile = "";
|
String filesToCompile = "";
|
||||||
for ( int count = 0; count < 100; count++ ) {
|
for ( int count = 0; count < 100; count++ ) {
|
Loading…
Reference in New Issue