From bae1559748866c228115ded5dcd750f891bef0dc Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Mon, 25 Feb 2008 20:14:52 +0000 Subject: [PATCH] Refactor how session factory Configuration is built up git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14361 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../jbc2/functional/CacheTestCaseBase.java | 47 ++++++++----------- .../functional/OptimisticJBossCacheTest.java | 24 +++++----- .../functional/PessimisticJBossCacheTest.java | 24 +++++----- 3 files changed, 44 insertions(+), 51 deletions(-) diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java index 566fa87cf4..50b6a60ddf 100755 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java @@ -29,6 +29,9 @@ import org.hibernate.cfg.Environment; import org.hibernate.cfg.Mappings; import org.hibernate.dialect.Dialect; import org.hibernate.junit.functional.FunctionalTestCase; +import org.hibernate.transaction.CMTTransactionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides common configuration setups for cache testing. @@ -37,6 +40,8 @@ import org.hibernate.junit.functional.FunctionalTestCase; */ public abstract class CacheTestCaseBase extends FunctionalTestCase { + private static final Logger log = LoggerFactory.getLogger( CacheTestCaseBase.class ); + private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; private String preferIPv4Stack; @@ -50,7 +55,7 @@ public abstract class CacheTestCaseBase extends FunctionalTestCase { } public String[] getMappings() { - return new String[] { "cache/jbc2/functional/Item.hbm.xml" }; + return new String[] { "cache/jbc2/functional/Item.hbm.xml", "cache/jbc2/functional/Customer.hbm.xml", "cache/jbc2/functional/Contact.hbm.xml" }; } public void configure(Configuration cfg) { @@ -65,7 +70,8 @@ public abstract class CacheTestCaseBase extends FunctionalTestCase { cfg.setProperty(Environment.USE_QUERY_CACHE, String.valueOf(getUseQueryCache())); cfg.setProperty(Environment.CONNECTION_PROVIDER, org.hibernate.test.tm.ConnectionProviderImpl.class.getName()); cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, org.hibernate.test.tm.TransactionManagerLookupImpl.class.getName()); - + cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() ); + configureCacheFactory(cfg); } @@ -74,38 +80,16 @@ public abstract class CacheTestCaseBase extends FunctionalTestCase { } /** - * The cache provider to be tested. + * Apply any region-factory specific configurations. * - * @return The cache provider. + * @param the Configuration to update. */ - protected void configureCacheFactory(Configuration cfg) { - if (getConfigResourceKey() != null) { - cfg.setProperty(getConfigResourceKey(), getConfigResourceLocation()); - } - } + protected abstract void configureCacheFactory(Configuration cfg); protected abstract Class getCacheRegionFactory(); protected abstract boolean getUseQueryCache(); - /** - * For provider-specific configuration, the name of the property key the - * provider expects. - * - * @return The provider-specific config key. - */ - protected String getConfigResourceKey() { - return Environment.CACHE_REGION_FACTORY; - } - - /** - * For provider-specific configuration, the resource location of that config - * resource. - * - * @return The config resource location. - */ - protected abstract String getConfigResourceLocation(); - @Override public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) { @@ -130,5 +114,14 @@ public abstract class CacheTestCaseBase extends FunctionalTestCase { } + protected void sleep(long ms) { + try { + Thread.sleep(ms); + } + catch (InterruptedException e) { + log.warn("Interrupted during sleep", e); + } + } + } diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java index f9ab088580..37aad999b0 100755 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java @@ -28,19 +28,18 @@ import junit.framework.Test; import org.hibernate.cache.RegionFactory; import org.hibernate.cache.jbc2.JBossCacheRegionFactory; import org.hibernate.cache.jbc2.builder.SharedCacheInstanceManager; +import org.hibernate.cfg.Configuration; import org.hibernate.junit.functional.FunctionalTestClassTestSuite; /** - * FIXME Move to hibernate-testsuite project and rename class x- "Disabled" + * Basic functional test of a optimistic locking entity + query cache. * * @author Brian Stansberry */ public class OptimisticJBossCacheTest extends AbstractQueryCacheFunctionalTestCase { - // note that a lot of the fucntionality here is intended to be used - // in creating specific tests for each CacheProvider that would extend - // from a base test case (this) for common requirement testing... - + private static final String JBC_CONFIG = "org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml"; + public OptimisticJBossCacheTest(String x) { super(x); } @@ -51,14 +50,15 @@ public class OptimisticJBossCacheTest extends AbstractQueryCacheFunctionalTestCa protected Class getCacheRegionFactory() { return JBossCacheRegionFactory.class; - } + } - protected String getConfigResourceKey() { - return SharedCacheInstanceManager.CACHE_RESOURCE_PROP; - } - - protected String getConfigResourceLocation() { - return "org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml"; + /** + * Apply any region-factory specific configurations. + * + * @param the Configuration to update. + */ + protected void configureCacheFactory(Configuration cfg) { + cfg.setProperty(SharedCacheInstanceManager.CACHE_RESOURCE_PROP, JBC_CONFIG); } } diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java index 4b53f65245..35a37b8ef6 100755 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java @@ -28,19 +28,18 @@ import junit.framework.Test; import org.hibernate.cache.RegionFactory; import org.hibernate.cache.jbc2.JBossCacheRegionFactory; import org.hibernate.cache.jbc2.builder.SharedCacheInstanceManager; +import org.hibernate.cfg.Configuration; import org.hibernate.junit.functional.FunctionalTestClassTestSuite; /** - * FIXME Move to hibernate-testsuite project and rename class x- "Disabled" + * Basic functional test of a pessimistic locking entity + query cache. * * @author Brian Stansberry */ public class PessimisticJBossCacheTest extends AbstractQueryCacheFunctionalTestCase { - // note that a lot of the fucntionality here is intended to be used - // in creating specific tests for each CacheProvider that would extend - // from a base test case (this) for common requirement testing... - + private static final String JBC_CONFIG = "org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml"; + public PessimisticJBossCacheTest(String x) { super(x); } @@ -51,14 +50,15 @@ public class PessimisticJBossCacheTest extends AbstractQueryCacheFunctionalTestC protected Class getCacheRegionFactory() { return JBossCacheRegionFactory.class; - } + } - protected String getConfigResourceKey() { - return SharedCacheInstanceManager.CACHE_RESOURCE_PROP; - } - - protected String getConfigResourceLocation() { - return "org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml"; + /** + * Apply any region-factory specific configurations. + * + * @param the Configuration to update. + */ + protected void configureCacheFactory(Configuration cfg) { + cfg.setProperty(SharedCacheInstanceManager.CACHE_RESOURCE_PROP, JBC_CONFIG); } }