Author: bstansberry(a)jboss.com
Date: 2008-02-25 15:14:52 -0500 (Mon, 25 Feb 2008)
New Revision: 14361
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java
Log:
Refactor how session factory Configuration is built up
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java 2008-02-25
20:03:07 UTC (rev 14360)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java 2008-02-25
20:14:52 UTC (rev 14361)
@@ -29,6 +29,9 @@
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 @@
*/
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 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 @@
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 @@
}
/**
- * 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<? extends RegionFactory> 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 @@
}
+ protected void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ }
+ catch (InterruptedException e) {
+ log.warn("Interrupted during sleep", e);
+ }
+ }
+
}
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java 2008-02-25
20:03:07 UTC (rev 14360)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/OptimisticJBossCacheTest.java 2008-02-25
20:14:52 UTC (rev 14361)
@@ -28,19 +28,18 @@
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 @@
protected Class<? extends RegionFactory> getCacheRegionFactory() {
return JBossCacheRegionFactory.class;
- }
+ }
- protected String getConfigResourceKey() {
- return SharedCacheInstanceManager.CACHE_RESOURCE_PROP;
+ /**
+ * Apply any region-factory specific configurations.
+ *
+ * @param the Configuration to update.
+ */
+ protected void configureCacheFactory(Configuration cfg) {
+ cfg.setProperty(SharedCacheInstanceManager.CACHE_RESOURCE_PROP, JBC_CONFIG);
}
- protected String getConfigResourceLocation() {
- return
"org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml";
- }
-
}
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java 2008-02-25
20:03:07 UTC (rev 14360)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticJBossCacheTest.java 2008-02-25
20:14:52 UTC (rev 14361)
@@ -28,19 +28,18 @@
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 @@
protected Class<? extends RegionFactory> getCacheRegionFactory() {
return JBossCacheRegionFactory.class;
- }
+ }
- protected String getConfigResourceKey() {
- return SharedCacheInstanceManager.CACHE_RESOURCE_PROP;
+ /**
+ * Apply any region-factory specific configurations.
+ *
+ * @param the Configuration to update.
+ */
+ protected void configureCacheFactory(Configuration cfg) {
+ cfg.setProperty(SharedCacheInstanceManager.CACHE_RESOURCE_PROP, JBC_CONFIG);
}
- protected String getConfigResourceLocation() {
- return
"org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml";
- }
-
}
Show replies by date